]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - jssource/src_files/include/SubPanel/SubPanelTiles.js
Release 6.3.0
[Github/sugarcrm.git] / jssource / src_files / include / SubPanel / SubPanelTiles.js
1 /*********************************************************************************
2  * SugarCRM Community Edition is a customer relationship management program developed by
3  * SugarCRM, Inc. Copyright (C) 2004-2011 SugarCRM Inc.
4  * 
5  * This program is free software; you can redistribute it and/or modify it under
6  * the terms of the GNU Affero General Public License version 3 as published by the
7  * Free Software Foundation with the addition of the following permission added
8  * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
9  * IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
10  * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
11  * 
12  * This program is distributed in the hope that it will be useful, but WITHOUT
13  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14  * FOR A PARTICULAR PURPOSE.  See the GNU Affero General Public License for more
15  * details.
16  * 
17  * You should have received a copy of the GNU Affero General Public License along with
18  * this program; if not, see http://www.gnu.org/licenses or write to the Free
19  * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
20  * 02110-1301 USA.
21  * 
22  * You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
23  * SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
24  * 
25  * The interactive user interfaces in modified source and object code versions
26  * of this program must display Appropriate Legal Notices, as required under
27  * Section 5 of the GNU Affero General Public License version 3.
28  * 
29  * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
30  * these Appropriate Legal Notices must retain the display of the "Powered by
31  * SugarCRM" logo. If the display of the logo is not reasonably feasible for
32  * technical reasons, the Appropriate Legal Notices must display the words
33  * "Powered by SugarCRM".
34  ********************************************************************************/
35
36
37
38
39 var request_id = 0;
40 var current_child_field = '';
41 var current_subpanel_url = '';
42 var child_field_loaded = new Object();
43 var request_map = new Object();
44
45 function get_module_name()
46 {
47         if(typeof(window.document.forms['DetailView']) == 'undefined') {
48                 return '';
49         } else {
50
51                 //check to see if subpanel_parent_module input exists.  If so override module name
52                 //this is used in the case when the subpanel contents are of the same module as the current module
53                 //and the record in $_REQUEST is of the parent object.  By specifying the subpanel_parent_module,
54                 //you allow normal processing to continue.  For an example, see trackdetailview.html/php in campaigns module
55                 if(typeof(window.document.forms['DetailView'].elements['subpanel_parent_module']) != 'undefined' &&
56                 window.document.forms['DetailView'].elements['subpanel_parent_module'].value != ''){
57                         return window.document.forms['DetailView'].elements['subpanel_parent_module'].value;
58                 }
59                 return window.document.forms['DetailView'].elements['module'].value;
60         }
61 }
62 /*this function will take in three parameters, m,i,a and recreate navigation
63 * m = module
64 * i = record id
65 * a = action (detail/edit)
66 * t = element to be modified
67 * r = relationship to update after edit.
68 * This is done to minimize page size
69 * */
70 function subp_nav(m,i,a,t,r){
71         if(t.href.search(/#/) < 0){
72                 //no need to process if url has already been converted
73                 return;
74         }
75         if(a=='d'){
76                 a='DetailView';
77         }else{
78                 a='EditView';
79         }
80         url = "index.php?module="+m+"&action="+a+"&record="+i+"&parent_module="+get_module_name()+"&parent_id="+get_record_id()+"&return_module="+get_module_name()+"&return_id="+get_record_id()+"&return_action=DetailView";
81         if  (r)
82         {
83                 url += "&return_relationship=" + r;
84         }
85         t.href = url;
86 }
87
88
89 /*this function will take in three parameters, m,i,a and recreate navigation
90 * m = module
91 * i = record id
92 * a = action (detail/edit)
93 * This is done to minimize page size
94 * */
95 function sub_p_rem(sp,lf,li,rp){
96         return_url = "index.php?module="+get_module_name()+"&action=SubPanelViewer&subpanel="+sp+"&record="+get_record_id()+"&sugar_body_only=1&inline=1";
97
98         remove_url = "index.php?module="+ get_module_name()
99                         + "&action=DeleteRelationship"
100                         + "&record="+ get_record_id()
101                         + "&linked_field="+ lf  //$linked_field"
102                         + "&linked_id="+ li //$record"
103                         + "&return_url=" + escape(escape(return_url))
104                         + "&refresh_page=" + rp;//$refresh_page"
105         showSubPanel(sp,remove_url,true);
106 }
107
108 function sp_rem_conf(){
109         return confirm(SUGAR.language.get('app_strings', 'NTC_REMOVE_CONFIRMATION'))
110 }
111
112 function sub_p_del(sp,submod,subrec, rp){
113         return_url = "index.php?module="+get_module_name()+"&action=SubPanelViewer&subpanel="+sp+"&record="+get_record_id()+"&sugar_body_only=1&inline=1";
114
115         remove_url = "index.php?module="+ submod
116                         + "&action=delete"
117                         + "&record="+ subrec
118                         + "&return_url=" + escape(escape(return_url))
119                         + "&refresh_page=" + rp;//$refresh_page"
120         showSubPanel(sp,remove_url,true);
121 }
122
123 function sp_del_conf(){
124         return confirm(SUGAR.language.get('app_strings', 'NTC_DELETE_CONFIRMATION'))
125 }
126
127 function get_record_id()
128 {
129         return window.document.forms['DetailView'].elements['record'].value;
130 }
131 function get_layout_def_key()
132 {
133         if(typeof(window.document.forms['DetailView'].elements['layout_def_key']) == 'undefined')return '';
134         return window.document.forms['DetailView'].elements['layout_def_key'].value;
135 }
136
137 function save_finished(args)
138 {
139         var child_field = request_map[args.request_id];
140         delete (child_field_loaded[child_field] );
141         showSubPanel(child_field);
142 }
143
144 function set_return_and_save_background(popup_reply_data)
145 {
146         var form_name = popup_reply_data.form_name;
147         var name_to_value_array = popup_reply_data.name_to_value_array;
148         var passthru_data = popup_reply_data.passthru_data;
149         var select_entire_list = typeof( popup_reply_data.select_entire_list ) == 'undefined' ? 0 : popup_reply_data.select_entire_list;
150         var current_query_by_page = popup_reply_data.current_query_by_page;
151         // construct the POST request
152         var query_array =  new Array();
153         if (name_to_value_array != 'undefined') {
154                 for (var the_key in name_to_value_array)
155                 {
156                         if(the_key == 'toJSON')
157                         {
158                                 /* just ignore */
159                         }
160                         else
161                         {
162                                 query_array.push(the_key+"="+name_to_value_array[the_key]);
163                         }
164                 }
165         }
166         //construct the muulti select list
167         var selection_list = popup_reply_data.selection_list;
168         if (selection_list != 'undefined') {
169                 for (var the_key in selection_list)
170                 {
171                         query_array.push('subpanel_id[]='+selection_list[the_key])
172                 }
173         }
174         var module = get_module_name();
175         var id = get_record_id();
176
177         query_array.push('value=DetailView');
178         query_array.push('module='+module);
179         query_array.push('http_method=get');
180         query_array.push('return_module='+module);
181         query_array.push('return_id='+id);
182         query_array.push('record='+id);
183         query_array.push('isDuplicate=false');
184         query_array.push('action=Save2');
185         query_array.push('inline=1');
186         query_array.push('select_entire_list='+select_entire_list);
187         if(select_entire_list == 1){
188                 query_array.push('current_query_by_page='+current_query_by_page);
189         }
190         var refresh_page = escape(passthru_data['refresh_page']);
191         for (prop in passthru_data) {
192                 if (prop=='link_field_name') {
193                         query_array.push('subpanel_field_name='+escape(passthru_data[prop]));
194                 } else {
195                         if (prop=='module_name') {
196                                 query_array.push('subpanel_module_name='+escape(passthru_data[prop]));
197                         } else {
198                                 query_array.push(prop+'='+escape(passthru_data[prop]));
199                         }
200                 }
201         }
202
203         var query_string = query_array.join('&');
204         request_map[request_id] = passthru_data['child_field'];
205
206         var returnstuff = http_fetch_sync('index.php',query_string);
207         request_id++;
208         got_data(returnstuff, true);
209         if(refresh_page == 1){
210                 document.location.reload(true);
211         }
212 }
213
214 function got_data(args, inline)
215 {
216
217         var list_subpanel = document.getElementById('list_subpanel_'+request_map[args.request_id].toLowerCase());
218         //this function assumes that we are always working with a subpanel..
219         //add a null check to prevent failures when we are not.
220         if (list_subpanel != null) {
221                 var subpanel = document.getElementById('subpanel_'+request_map[args.request_id].toLowerCase());
222                 var child_field = request_map[args.request_id].toLowerCase();
223                 if(inline){
224
225                         //CCL - 21752
226                         //if this is an inline operation, get the original buttons in the td element
227                         //so that we may replace them later
228                         buttonHTML = '';
229                         trEls = list_subpanel.getElementsByTagName('tr');
230                         if(trEls && trEls.length > 0) {
231                                 for(x in trEls) {
232                                         if(trEls[x] && trEls[x].className == 'pagination') {
233                                            tableEls = trEls[x].getElementsByTagName('table');
234                                            tdEls = tableEls[0].getElementsByTagName('td');
235                                            span = tdEls[0].getElementsByTagName('span');
236                                            if(span) {
237                                               buttonHTML = span[0].innerHTML;
238                                            }
239                                            break;
240                                         }
241                                 }
242                         }
243
244                         child_field_loaded[child_field] = 2;
245                         list_subpanel.innerHTML='';
246                         list_subpanel.innerHTML=args.responseText;
247
248                         //now if the trPagination element is set then let's replace the new tr element with this
249                         if(buttonHTML != '') {
250                                 list_subpanel = document.getElementById('list_subpanel_'+request_map[args.request_id].toLowerCase());
251                                 trEls = list_subpanel.getElementsByTagName('tr');
252                                 for(x in trEls) {
253                                         if(trEls[x] && trEls[x].className == 'pagination') {
254                                            tableEls = trEls[x].getElementsByTagName('table');
255                                            tdEls = tableEls[0].getElementsByTagName('td');
256                                            span = tdEls[0].getElementsByTagName('span');
257                                            span[0].innerHTML = buttonHTML;
258                                            break;
259                                         }
260                                 }
261                         }
262
263                 } else {
264                         child_field_loaded[child_field] = 1;
265                         subpanel.innerHTML='';
266                         subpanel.innerHTML=args.responseText;
267
268                         /* walk into the DOM and insert the list_subpanel_* div */
269                         var inlineTable = subpanel.getElementsByTagName('table');
270                         inlineTable = inlineTable[1];
271                         inlineTable = subpanel.removeChild(inlineTable);
272                         var listDiv = document.createElement('div');
273                         listDiv.id = 'list_subpanel_'+request_map[args.request_id].toLowerCase();
274                         subpanel.appendChild(listDiv);
275                         listDiv.appendChild(inlineTable);
276                 }
277                 subpanel.style.display = '';
278                 set_div_cookie(subpanel.cookie_name, '');
279
280                 if (current_child_field != '' && child_field != current_child_field)
281                 {
282                         // commented out for now.  this was originally used by tab UI of subpanels
283                         //hideSubPanel(current_child_field);
284                 }
285                 current_child_field = child_field;
286         }
287 }
288
289 function showSubPanel(child_field,url,force_load,layout_def_key)
290 {
291         var inline = 1;
292         if ( typeof(force_load) == 'undefined' || force_load == null)
293         {
294                 force_load = false;
295         }
296
297         if (force_load || typeof( child_field_loaded[child_field] ) == 'undefined')
298         {
299                 request_map[request_id] = child_field;
300                 if ( typeof (url) == 'undefined' || url == null)
301                 {
302                         var module = get_module_name();
303                         var id = get_record_id();
304             if ( typeof(layout_def_key) == 'undefined' || layout_def_key == null ) {
305                 layout_def_key = get_layout_def_key();
306             }
307
308                         url = 'index.php?sugar_body_only=1&module='+module+'&subpanel='+child_field+'&action=SubPanelViewer&inline=' + inline + '&record='+id + '&layout_def_key='+ layout_def_key;
309                 }
310
311                 if ( url.indexOf('http://') != 0  && url.indexOf('https://') != 0)
312                 {
313                         url = ''+url ;
314                 }
315
316                 current_subpanel_url = url;
317                 // http_fetch_async(url,got_data,request_id++);
318                 var returnstuff = http_fetch_sync(url+ '&inline=' + inline + '&ajaxSubpanel=true');
319                 request_id++;
320                 got_data(returnstuff, inline);
321         }
322         else
323         {
324                 var subpanel = document.getElementById('subpanel_'+child_field);
325                 subpanel.style.display = '';
326
327                 set_div_cookie(subpanel.cookie_name, '');
328
329                 if (current_child_field != '' && child_field != current_child_field)
330                 {
331                         hideSubPanel(current_child_field);
332                 }
333
334                 current_child_field = child_field;
335         }
336         if(typeof(url) != 'undefined' && url != null && url.indexOf('refresh_page=1') > 0){
337                 document.location.reload();
338         }
339
340 }
341
342 function markSubPanelLoaded(child_field){
343         child_field_loaded[child_field] = 2;
344 }
345 function hideSubPanel(child_field)
346 {
347         var subpanel = document.getElementById('subpanel_'+child_field);
348         subpanel.style.display = 'none';
349         set_div_cookie(subpanel.cookie_name, 'none');
350 }
351 var sub_cookie_name = get_module_name() + '_divs';
352 var temp = Get_Cookie(sub_cookie_name);
353 var div_cookies = new Array();
354
355 if(temp && typeof(temp) != 'undefined'){
356         div_cookies = get_sub_cookies(temp);
357 }
358 function set_div_cookie(name, display){
359         div_cookies[name] = display;
360         Set_Cookie(sub_cookie_name, subs_to_cookie(div_cookies), 3000, false, false,false);
361 }
362
363
364 function local_open_popup(name, width, height,arg1, arg2, arg3, params)
365 {
366         return open_popup(name, width, height,arg1,arg2,arg3, params);
367 }
368
369 SUGAR.subpanelUtils = function() {
370         var originalLayout = null,
371         subpanelContents = {},
372         subpanelLocked = {},
373
374         // Keeps track of the current subpanel id
375         currentPanelDiv;
376
377         return {
378                 // get the current subpanel layout
379                 getLayout: function(asString, ignoreHidden) {
380                     subpanels = document.getElementById('subpanel_list');
381                     subpanelIds = new Array();
382                     for(wp = 0; wp < subpanels.childNodes.length; wp++) {
383                       if(typeof subpanels.childNodes[wp].id != 'undefined' && subpanels.childNodes[wp].id.match(/whole_subpanel_[\w-]*/) && (typeof ignoreHidden == 'undefined' || subpanels.childNodes[wp].style.display != 'none')) {
384                                 subpanelIds.push(subpanels.childNodes[wp].id.replace(/whole_subpanel_/,''));
385                       }
386                     }
387                         if(asString) return subpanelIds.join(',');
388                         else return subpanelIds;
389                 },
390
391                 // called when subpanel is picked up
392                 onDrag: function(e, id) {
393                         originalLayout = SUGAR.subpanelUtils.getLayout(true, true);
394                 },
395
396                 // called when subpanel is dropped
397                 onDrop: function(e, id) {
398                         newLayout = SUGAR.subpanelUtils.getLayout(true, true);
399                         if(originalLayout != newLayout) { // only save if the layout has changed
400                                 SUGAR.subpanelUtils.saveLayout(newLayout);
401                         }
402                 },
403
404                 // save the layout of the subpanels
405                 saveLayout: function(order) {
406                         ajaxStatus.showStatus(SUGAR.language.get('app_strings', 'LBL_SAVING_LAYOUT'));
407
408                         if(typeof SUGAR.subpanelUtils.currentSubpanelGroup != 'undefined') {
409                                 var orderList = SUGAR.subpanelUtils.getLayout(false, true);
410                                 var currentGroup = SUGAR.subpanelUtils.currentSubpanelGroup;
411                         }
412                         var success = function(data) {
413                                 ajaxStatus.showStatus(SUGAR.language.get('app_strings', 'LBL_SAVED_LAYOUT'));
414                                 window.setTimeout('ajaxStatus.hideStatus()', 2000);
415                                 if(typeof SUGAR.subpanelUtils.currentSubpanelGroup != 'undefined') {
416                                         SUGAR.subpanelUtils.reorderSubpanelSubtabs(currentGroup, orderList);
417                                 }
418                         }
419
420                         url = 'index.php?module=Home&action=SaveSubpanelLayout&layout=' + order + '&layoutModule=' + currentModule;
421                         if(typeof SUGAR.subpanelUtils.currentSubpanelGroup != 'undefined') {
422                                 url = url + '&layoutGroup=' + encodeURI(SUGAR.subpanelUtils.currentSubpanelGroup);
423                         }
424                         var cObj = YAHOO.util.Connect.asyncRequest('GET', url, {success: success, failure: success});
425                 },
426
427         /**
428          * Call when an inline create is saved.
429          * Note: We require the subpanel name to refresh the subpanel contents and
430          * to close the subpanel after the save. However, the code the generates the
431          * button doesn't have access to the subpanel name, only the module name.
432          * Hence this rather long-winded mechanism.
433          * @param theForm
434          * @param buttonName id of the originating 'save' button - we determine the
435          *          associated subpanel name by climbing the DOM from this point
436          */
437                 inlineSave: function(theForm, buttonName) {
438                         ajaxStatus.showStatus(SUGAR.language.get('app_strings', 'LBL_SAVING'));
439                         var success = function(data) {
440                                 var element = document.getElementById(buttonName);
441                                 do {
442                                         element = element.parentNode;
443                                 } while ( element.className != 'quickcreate' && element.parentNode ) ;
444
445                                 if (element.className == 'quickcreate') {
446                                         var subpanel = element.id.slice(9,-7) ; // retrieve the subpanel name from the div id - the name is encoded as 'subpanel_<subpanelname>_newdiv'
447
448                                         var module = get_module_name();
449                                         var id = get_record_id();
450                                         var layout_def_key = get_layout_def_key();
451                                         try {
452                                                 eval('result = ' + data.responseText);
453                                         } catch (err) {
454
455                                         }
456
457                                         if (typeof(result) != 'undefined' && result != null && result['status'] == 'dupe') {
458                                                 document.location.href = "index.php?" + result['get'].replace(/&amp;/gi,'&').replace(/&lt;/gi,'<').replace(/&gt;/gi,'>').replace(/&#039;/gi,'\'').replace(/&quot;/gi,'"').replace(/\r\n/gi,'\n');
459                                                 return;
460                                         } else {
461                                                 SUGAR.subpanelUtils.cancelCreate(buttonName);
462                                                 showSubPanel(subpanel, null, true);
463                                                 ajaxStatus.showStatus(SUGAR.language.get('app_strings', 'LBL_SAVED'));
464                                                 window.setTimeout('ajaxStatus.hideStatus()', 1000);
465                             if(reloadpage) window.location.reload(false);
466                                         }
467                                 }
468                         }
469             // reload page if we are setting status to Held
470             var reloadpage = false;
471             if ((buttonName == 'Meetings_subpanel_save_button' || buttonName == 'Calls_subpanel_save_button' )
472                  && typeof(theForm) !='undefined' && typeof(document.getElementById(theForm)) != 'undefined'
473                  && typeof(document.getElementById(theForm).status) != 'undefined'
474                  && document.getElementById(theForm).status[document.getElementById(theForm).status.selectedIndex].value == 'Held') {
475                 reloadpage = true;
476             }
477             YAHOO.util.Connect.setForm(theForm, true, true);
478                         var cObj = YAHOO.util.Connect.asyncRequest('POST', 'index.php', {success: success, failure: success, upload:success});
479                         return false;
480                 },
481
482         /**
483          * Retrieves the subpanel form.
484          * Note: We only allow one subpanel form to be open at any given time
485          * because some of the form widgets interfere with each other.
486          * @param theForm
487          * @param theDiv
488          * @param loadingStr
489          */
490                 sendAndRetrieve: function(theForm, theDiv, loadingStr) {
491                         function success(data) {
492                                 var theDivObj = document.getElementById(theDiv),
493                     divName = theDiv + '_newDiv',
494                     form_el;
495                 SUGAR.subpanelUtils.dataToDOMAvail = false;
496
497                 // Check if preview subpanel form exists, remove if it does.
498                 SUGAR.subpanelUtils.removeSubPanel();
499
500                                 subpanelContents[theDiv] = {};
501                                 subpanelContents[theDiv]['list'] = theDivObj;
502                                 subpanelContents[theDiv]['newDiv'] = document.createElement('div');
503                                 subpanelContents[theDiv]['newDiv'].innerHTML = '<script type="text/javascript">SUGAR.subpanelUtils.dataToDOMAvail=true;</script>' + data.responseText;
504                                 subpanelContents[theDiv]['newDiv'].id = divName;
505                                 subpanelContents[theDiv]['newDiv'].className = 'quickcreate';
506
507                                 // Grab the buttons from the subpanel and hide them
508                                 var button_elements = YAHOO.util.Selector.query('td.buttons', theDiv, false);
509                                 YAHOO.util.Dom.setStyle(button_elements, 'display', 'none');
510
511                 // Add the form object to the DOM
512                                 theDivObj.parentNode.insertBefore(subpanelContents[theDiv]['newDiv'], theDivObj);
513                 currentPanelDiv = divName;
514
515                 if (!SUGAR.subpanelUtils.dataToDOMAvail) {
516                                         SUGAR.util.evalScript(data.responseText);
517                                 }
518
519                                 form_el = YAHOO.util.Selector.query('form', divName, true);
520                 YAHOO.util.Dom.setStyle(form_el, 'padding-bottom', '10px');
521                 
522                 subpanelLocked[theDiv] = false;
523                 setTimeout("enableQS(false)",500);
524                                 ajaxStatus.hideStatus();
525                         }
526
527                         if (subpanelLocked[theDiv] === true) {
528                 return false;
529             }
530             
531                         subpanelLocked[theDiv] = true;
532
533                         loadingStr = loadingStr || SUGAR.language.get('app_strings', 'LBL_LOADING');
534                         ajaxStatus.showStatus(loadingStr);
535                         YAHOO.util.Connect.setForm(theForm);
536                         YAHOO.util.Connect.asyncRequest('POST', 'index.php', {success: success, failure: success});
537
538                         return false;
539                 },
540
541                 cancelCreate: function(buttonName) {
542                         var element = document.getElementById(buttonName),
543                 theForm = element.form,
544                 confirmMsg = onUnloadEditView(theForm);
545
546                         do {
547                                 element = element.parentNode;
548                         } while ( element.className != 'quickcreate' && element.parentNode ) ;
549
550                         var theDiv = element.id.substr(0,element.id.length-7);
551
552                         if (typeof(subpanelContents[theDiv]) == 'undefined')
553                 return false;
554
555             if ( confirmMsg != null ) {
556                 if ( !confirm(confirmMsg) ) {
557                     return false;
558                 } else {
559                     disableOnUnloadEditView(theForm);
560                 }
561             }
562
563             SUGAR.subpanelUtils.removeSubPanel();
564             var button_elements = YAHOO.util.Selector.query('td.buttons', theDiv, false);
565             YAHOO.util.Dom.setStyle(button_elements, 'display', '');
566             
567                         return false;
568                 },
569
570                 loadSubpanelGroupFromMore: function(group){
571                         SUGAR.subpanelUtils.updateSubpanelMoreTab(group);
572                         SUGAR.subpanelUtils.loadSubpanelGroup(group);
573                 },
574
575                 updateSubpanelMoreTab: function(group){
576                         // Update Tab
577                         var moreTab = document.getElementById(SUGAR.subpanelUtils.subpanelMoreTab + '_sp_tab');
578                         moreTab.id = group + '_sp_tab';
579                         moreTab.getElementsByTagName('a')[0].innerHTML = group;
580                         moreTab.getElementsByTagName('a')[0].href = "javascript:SUGAR.subpanelUtils.loadSubpanelGroup('"+group+"');";
581
582                         // Update Menu
583                         var menuLink = document.getElementById(group+'_sp_mm');
584                         menuLink.id = SUGAR.subpanelUtils.subpanelMoreTab+'_sp_mm';
585                         menuLink.href = "javascript:SUGAR.subpanelUtils.loadSubpanelGroupFromMore('"+SUGAR.subpanelUtils.subpanelMoreTab+"');";
586                         menuLink.innerHTML = SUGAR.subpanelUtils.subpanelMoreTab;
587
588                         SUGAR.subpanelUtils.subpanelMoreTab = group;
589                 },
590
591         /**
592          * Removes the current subpanel if it exists.
593          */
594         removeSubPanel: function() {
595             var currentPanelEl = document.getElementById(currentPanelDiv);
596
597             if (currentPanelEl != null) {
598                 currentPanelEl.parentNode.removeChild(currentPanelEl);
599                 SUGAR.ajaxUI.cleanGlobals();
600                 currentPanelDiv = null;
601             }
602         },
603
604                 /* loadSubpanels:
605                 /* construct set of needed subpanels */
606                 /* if we have not yet loaded this subpanel group, */
607                 /*     set loadedGroups[group] */
608                 /*     for each subpanel in subpanelGroups[group] */
609                 /*         if document.getElementById('whole_subpanel_'+subpanel) doesn't exist */
610                 /*         then add subpanel to set of needed subpanels */
611                 /*     if we need to load any subpanels, send a request for them */
612                 /*            with updateSubpanels as the callback. */
613                 /* otherwise call updateSubpanels */
614                 /* call setGroupCookie */
615
616                 loadSubpanelGroup: function(group){
617                         if(group == SUGAR.subpanelUtils.currentSubpanelGroup) return;
618                         if(SUGAR.subpanelUtils.loadedGroups[group]){
619                                 SUGAR.subpanelUtils.updateSubpanel(group);
620                         }else{
621                                 SUGAR.subpanelUtils.loadedGroups.push(group);
622                                 var needed = Array();
623                                 for(group_sp in SUGAR.subpanelUtils.subpanelGroups[group]){
624                                         if(typeof(SUGAR.subpanelUtils.subpanelGroups[group][group_sp]) == 'string' && !document.getElementById('whole_subpanel_'+SUGAR.subpanelUtils.subpanelGroups[group][group_sp])){
625                                                 needed.push(SUGAR.subpanelUtils.subpanelGroups[group][group_sp]);
626                                         }
627                                 }
628                                 var success = function(){
629                                         SUGAR.subpanelUtils.updateSubpanelEventHandlers(needed);
630                                         SUGAR.subpanelUtils.updateSubpanels(group);
631                                 };
632                                 /* needed to retrieve each of the specified subpanels and install them ...*/
633                                 /* load them in bulk, insert via innerHTML, then sort nodes later. */
634                                 if(needed.length){
635                                         ajaxStatus.showStatus(SUGAR.language.get('app_strings', 'LBL_LOADING'));
636                                         SUGAR.util.retrieveAndFill(SUGAR.subpanelUtils.requestUrl + needed.join(','),'subpanel_list', null, success, null, true);
637                                 }else{
638                                         SUGAR.subpanelUtils.updateSubpanels(group);
639                                 }
640                         }
641                         SUGAR.subpanelUtils.setGroupCookie(group);
642                 },
643
644                 /* updateSubpanels:
645                 /* for each child node of subpanel_list */
646                 /*     let subpanel name be id.match(/whole_subpanel_(\w*)/) */
647                 /*     if the subpanel name is in the list of subpanels for the current group, show it */
648                 /*     otherwise hide it */
649                 /* swap nodes to suit user's order */
650                 /* call updateSubpanelTabs */
651
652                 updateSubpanels: function(group){
653                         var sp_list = document.getElementById('subpanel_list');
654                         for(sp in sp_list.childNodes){
655                                 if(sp_list.childNodes[sp].id){
656                                         sp_list.childNodes[sp].style.display = 'none';
657                                 }
658                         }
659                         for(group_sp in SUGAR.subpanelUtils.subpanelGroups[group]){
660                 if ( typeof(SUGAR.subpanelUtils.subpanelGroups[group][group_sp]) != 'string' ) continue;
661                                 var cur = document.getElementById('whole_subpanel_'+SUGAR.subpanelUtils.subpanelGroups[group][group_sp]);
662                                 cur.style.display = 'block';
663                                 /* use YDD swapNodes this and first, second, etc. */
664                                 try{
665                                         YAHOO.util.DDM.swapNode(cur, sp_list.getElementsByTagName('LI')[group_sp]);
666                                 }catch(e){
667
668                                 }
669                         }
670                         SUGAR.subpanelUtils.updateSubpanelTabs(group);
671                 },
672
673                 updateSubpanelTabs: function(group){
674                         if(SUGAR.subpanelUtils.showLinks){
675                                 SUGAR.subpanelUtils.updateSubpanelSubtabs(group);
676                                 document.getElementById('subpanelSubTabs').innerHTML = SUGAR.subpanelUtils.subpanelSubTabs[group];
677                         }
678
679                         oldTab = document.getElementById(SUGAR.subpanelUtils.currentSubpanelGroup+'_sp_tab');
680                         if(oldTab){
681                                 oldTab.className = '';
682                                 oldTab.getElementsByTagName('a')[0].className = '';
683                         }
684
685                         mainTab = document.getElementById(group+'_sp_tab');
686                         mainTab.className = 'active';
687                         mainTab.getElementsByTagName('a')[0].className = 'current';
688
689                         SUGAR.subpanelUtils.currentSubpanelGroup = group;
690                         ajaxStatus.hideStatus();
691                 },
692
693                 updateSubpanelEventHandlers: function(){
694                         if(SubpanelInitTabNames){
695                                 SubpanelInitTabNames(SUGAR.subpanelUtils.getLayout(false));
696                         }
697                 },
698
699                 reorderSubpanelSubtabs: function(group, order){
700                         SUGAR.subpanelUtils.subpanelGroups[group] = order;
701                         if(SUGAR.subpanelUtils.showLinks==1){
702                                 SUGAR.subpanelUtils.updateSubpanelSubtabs(group);
703                                 if(SUGAR.subpanelUtils.currentSubpanelGroup == group){
704                                         document.getElementById('subpanelSubTabs').innerHTML = SUGAR.subpanelUtils.subpanelSubTabs[group];
705                                 }
706                         }
707                 },
708
709                 // Re-renders the contents of subpanelSubTabs[group].
710                 // Does not immediately affect what's on the screen.
711                 updateSubpanelSubtabs: function(group){
712                         var notFirst = 0;
713                         var preMore = SUGAR.subpanelUtils.subpanelGroups[group].slice(0, SUGAR.subpanelUtils.subpanelMaxSubtabs);
714
715                         SUGAR.subpanelUtils.subpanelSubTabs[group] = '<table border="0" cellpadding="0" cellspacing="0" height="20" width="100%" class="subTabs"><tr>';
716
717                         for(var sp_key = 0; sp_key < preMore.length; sp_key++){
718                                 if(notFirst != 0){
719                                         SUGAR.subpanelUtils.subpanelSubTabs[group] += '<td width="1"> | </td>';
720                                 }else{
721                                         notFirst = 1;
722                                 }
723                                 SUGAR.subpanelUtils.subpanelSubTabs[group] += '<td nowrap="nowrap"><a href="#'+preMore[sp_key]+'" class="subTabLink">'+SUGAR.subpanelUtils.subpanelTitles[preMore[sp_key]]+'</a></td>';
724                         }
725                         if(document.getElementById('MoreSub'+group+'PanelMenu')){
726                                 SUGAR.subpanelUtils.subpanelSubTabs[group] += '<td nowrap="nowrap"> | &nbsp;<span class="subTabMore" id="MoreSub'+group+'PanelHandle" style="margin-left:2px; cursor: pointer; cursor: hand;" align="absmiddle" onmouseover="SUGAR.subpanelUtils.menu.tbspButtonMouseOver(this.id,\'\',\'\',0);">&gt;&gt;</span></td>';
727                         }
728                         SUGAR.subpanelUtils.subpanelSubTabs[group] += '<td width="100%">&nbsp;</td></tr></table>';
729
730                         // Update the more menu for the current group
731                         var postMore = SUGAR.subpanelUtils.subpanelGroups[group].slice(SUGAR.subpanelUtils.subpanelMaxSubtabs);
732                         var subpanelMenu = document.getElementById('MoreSub'+group+'PanelMenu');
733
734                         if(postMore && subpanelMenu){
735                                 subpanelMenu.innerHTML = '';
736                                 for(var sp_key = 0; sp_key < postMore.length; sp_key++){
737                                         subpanelMenu.innerHTML += '<a href="#'+postMore[sp_key]+'" class="menuItem" parentid="MoreSub'+group+'PanelMenu" onmouseover="hiliteItem(this,\'yes\'); closeSubMenus(this);" onmouseout="unhiliteItem(this);">'+SUGAR.subpanelUtils.subpanelTitles[postMore[sp_key]]+'</a>';
738                                 }
739                                 subpanelMenu += '</div>';
740                         }
741                 },
742
743                 setGroupCookie: function(group){
744                         Set_Cookie(SUGAR.subpanelUtils.tabCookieName, group, 3000, false, false,false);
745                 }
746         };
747 }();
748
749 SUGAR.subpanelUtils.menu = function(){
750         return {
751                 tbspButtonMouseOver : function(id,top,left,leftOffset){ //*//
752                         closeMenusDelay = eraseTimeout(closeMenusDelay);
753                         if (openMenusDelay == null){
754                                 openMenusDelay = window.setTimeout("SUGAR.subpanelUtils.menu.spShowMenu('"+id+"','"+top+"','"+left+"','"+leftOffset+"')", delayTime);
755                         }
756                 },
757                 spShowMenu : function(id,top,left,leftOffset){ //*//
758                         openMenusDelay = eraseTimeout(openMenusDelay);
759                         var menuName = id.replace(/Handle/i,'Menu');
760                         var menu = getLayer(menuName);
761                         //if (menu) menu.className = 'tbButtonMouseOverUp';
762                         if (currentMenu){
763                                 closeAllMenus();
764                         }
765                         SUGAR.subpanelUtils.menu.spPopupMenu(id, menu, top,left,leftOffset);
766                 },
767                 spPopupMenu : function(handleID, menu, top, left, leftOffset){ //*//
768                         var bw = checkBrowserWidth();
769                         var menuName = handleID.replace(/Handle/i,'Menu');
770                         var menuWidth = 120;
771                         var imgWidth = document.getElementById(handleID).width;
772                         if (menu){
773                                 var menuHandle = getLayer(handleID);
774                                 var p=menuHandle;
775                                 if (left == "") {
776                                         var left = 0;
777                                         while(p&&p.tagName.toUpperCase()!='BODY'){
778                                                 left+=p.offsetLeft;
779                                                 p=p.offsetParent;
780                                         }
781                                         left+=parseInt(leftOffset);
782                                 }
783                                 if (top == "") {
784                                         var top = 0;
785                                         p=menuHandle;
786                                         top+=p.offsetHeight;
787                                         while(p&&p.tagName.toUpperCase()!='BODY'){
788                                                 top+=p.offsetTop;
789                                                 p=p.offsetParent;
790                                         }
791                                 }
792                                 if (left+menuWidth>bw) {
793                                         left = left-menuWidth+imgWidth;
794                                 }
795                                 setMenuVisible(menu, left, top, false);
796                         }
797                 }
798         };
799 }();