]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - jssource/src_files/include/SubPanel/SubPanelTiles.js
Release 6.5.15
[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-2013 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
97         return_url = "index.php?module="+get_module_name()+"&action=SubPanelViewer&subpanel="+sp+"&record="+get_record_id()+"&sugar_body_only=1&inline=1";
98
99         remove_url = "index.php?module="+ get_module_name()
100                         + "&action=DeleteRelationship"
101                         + "&record="+ get_record_id()
102                         + "&linked_field="+ lf  //$linked_field"
103                         + "&linked_id="+ li //$record"
104                         + "&return_url=" + escape(escape(return_url))
105                         + "&refresh_page=" + rp;//$refresh_page"
106         showSubPanel(sp,remove_url,true);
107 }
108
109 function sp_rem_conf(){
110         return confirm(SUGAR.language.get('app_strings', 'NTC_REMOVE_CONFIRMATION'))
111 }
112
113 function sub_p_del(sp,submod,subrec, rp){
114         return_url = "index.php?module="+get_module_name()+"&action=SubPanelViewer&subpanel="+sp+"&record="+get_record_id()+"&sugar_body_only=1&inline=1";
115
116         remove_url = "index.php?module="+ submod
117                         + "&action=delete"
118                         + "&record="+ subrec
119                         + "&return_url=" + escape(return_url)
120                         + "&refresh_page=" + rp;//$refresh_page"
121         showSubPanel(sp,remove_url,true);
122 }
123
124 function sp_del_conf(){
125         return confirm(SUGAR.language.get('app_strings', 'NTC_DELETE_CONFIRMATION'))
126 }
127
128 function get_record_id()
129 {
130         return window.document.forms['DetailView'].elements['record'].value;
131 }
132 function get_layout_def_key()
133 {
134         if(typeof(window.document.forms['DetailView'].elements['layout_def_key']) == 'undefined')return '';
135         return window.document.forms['DetailView'].elements['layout_def_key'].value;
136 }
137
138 function save_finished(args)
139 {
140         var child_field = request_map[args.request_id];
141         delete (child_field_loaded[child_field] );
142         showSubPanel(child_field);
143 }
144
145 function set_return_and_save_background(popup_reply_data)
146 {
147         var form_name = popup_reply_data.form_name;
148         var name_to_value_array = popup_reply_data.name_to_value_array;
149         var passthru_data = popup_reply_data.passthru_data;
150         var select_entire_list = typeof( popup_reply_data.select_entire_list ) == 'undefined' ? 0 : popup_reply_data.select_entire_list;
151         var current_query_by_page = popup_reply_data.current_query_by_page;
152         // construct the POST request
153         var query_array =  new Array();
154         if (name_to_value_array != 'undefined') {
155                 for (var the_key in name_to_value_array)
156                 {
157                         if(the_key == 'toJSON')
158                         {
159                                 /* just ignore */
160                         }
161                         else
162                         {
163                                 query_array.push(the_key+"="+name_to_value_array[the_key]);
164                         }
165                 }
166         }
167         //construct the muulti select list
168         var selection_list = popup_reply_data.selection_list;
169         if (selection_list != 'undefined') {
170                 for (var the_key in selection_list)
171                 {
172                         query_array.push('subpanel_id[]='+selection_list[the_key])
173                 }
174         }
175         var module = get_module_name();
176         var id = get_record_id();
177
178         query_array.push('value=DetailView');
179         query_array.push('module='+module);
180         query_array.push('http_method=get');
181         query_array.push('return_module='+module);
182         query_array.push('return_id='+id);
183         query_array.push('record='+id);
184         query_array.push('isDuplicate=false');
185         query_array.push('action=Save2');
186         query_array.push('inline=1');
187         query_array.push('select_entire_list='+select_entire_list);
188         if(select_entire_list == 1){
189                 query_array.push('current_query_by_page='+current_query_by_page);
190         }
191         var refresh_page = escape(passthru_data['refresh_page']);
192         for (prop in passthru_data) {
193                 if (prop=='link_field_name') {
194                         query_array.push('subpanel_field_name='+escape(passthru_data[prop]));
195                 } else {
196                         if (prop=='module_name') {
197                                 query_array.push('subpanel_module_name='+escape(passthru_data[prop]));
198                         } else if(prop == 'prospect_ids'){
199                                 for(var i=0;i<passthru_data[prop].length;i++){
200                                         query_array.push(prop + '[]=' + escape(passthru_data[prop][i]));
201                                 }
202                         } else {
203                                 query_array.push(prop+'='+escape(passthru_data[prop]));
204                         }
205                 }
206         }
207
208         var query_string = query_array.join('&');
209         request_map[request_id] = passthru_data['child_field'];
210
211         var returnstuff = http_fetch_sync('index.php',query_string);
212         request_id++;
213
214         // Bug 52843
215         // If returnstuff.responseText is empty, don't process, because it will blank the innerHTML
216         if (typeof returnstuff != 'undefined' && typeof returnstuff.responseText != 'undefined' && returnstuff.responseText.length != 0) {
217                 got_data(returnstuff, true);
218         }
219         
220         if(refresh_page == 1){
221                 document.location.reload(true);
222         }
223 }
224
225 function got_data(args, inline)
226 {
227
228         var list_subpanel = document.getElementById('list_subpanel_'+request_map[args.request_id].toLowerCase());
229         //this function assumes that we are always working with a subpanel..
230         //add a null check to prevent failures when we are not.
231         if (list_subpanel != null) {
232                 var subpanel = document.getElementById('subpanel_'+request_map[args.request_id].toLowerCase());
233                 var child_field = request_map[args.request_id].toLowerCase();
234                 if(inline){
235
236                         child_field_loaded[child_field] = 2;
237                         list_subpanel.innerHTML='';
238                         list_subpanel.innerHTML=args.responseText;                      
239
240                 } else {
241                         child_field_loaded[child_field] = 1;
242                         subpanel.innerHTML='';
243                         subpanel.innerHTML=args.responseText;
244
245                         /* walk into the DOM and insert the list_subpanel_* div */
246                         var inlineTable = subpanel.getElementsByTagName('table');
247                         inlineTable = inlineTable[1];
248                         inlineTable = subpanel.removeChild(inlineTable);
249                         var listDiv = document.createElement('div');
250                         listDiv.id = 'list_subpanel_'+request_map[args.request_id].toLowerCase();
251                         subpanel.appendChild(listDiv);
252                         listDiv.appendChild(inlineTable);
253                 }
254         SUGAR.util.evalScript(args.responseText);
255                 subpanel.style.display = '';
256                 set_div_cookie(subpanel.cookie_name, '');
257
258                 if (current_child_field != '' && child_field != current_child_field)
259                 {
260                         // commented out for now.  this was originally used by tab UI of subpanels
261                         //hideSubPanel(current_child_field);
262                 }
263                 current_child_field = child_field;
264                 //reinit action menus
265                 $("ul.clickMenu").each(function(index, node){
266                         $(node).sugarActionMenu();
267                 });
268         }
269 }
270
271 function showSubPanel(child_field,url,force_load,layout_def_key)
272 {
273         var inline = 1;
274         if ( typeof(force_load) == 'undefined' || force_load == null)
275         {
276                 force_load = false;
277         }
278
279         if (force_load || typeof( child_field_loaded[child_field] ) == 'undefined')
280         {
281                 request_map[request_id] = child_field;
282                 if ( typeof (url) == 'undefined' || url == null)
283                 {
284                         var module = get_module_name();
285                         var id = get_record_id();
286             if ( typeof(layout_def_key) == 'undefined' || layout_def_key == null ) {
287                 layout_def_key = get_layout_def_key();
288             }
289
290                         url = 'index.php?sugar_body_only=1&module='+module+'&subpanel='+child_field+'&action=SubPanelViewer&inline=' + inline + '&record='+id + '&layout_def_key='+ layout_def_key;
291                 }
292
293                 if ( url.indexOf('http://') != 0  && url.indexOf('https://') != 0)
294                 {
295                         url = ''+url ;
296                 }
297
298                 current_subpanel_url = url;
299                 // http_fetch_async(url,got_data,request_id++);
300                 var returnstuff = http_fetch_sync(url+ '&inline=' + inline + '&ajaxSubpanel=true');
301                 request_id++;
302                 got_data(returnstuff, inline);
303         }
304         else
305         {
306                 var subpanel = document.getElementById('subpanel_'+child_field);
307                 subpanel.style.display = '';
308
309                 set_div_cookie(subpanel.cookie_name, '');
310
311                 if (current_child_field != '' && child_field != current_child_field)
312                 {
313                         hideSubPanel(current_child_field);
314                 }
315
316                 current_child_field = child_field;
317         }
318         if(typeof(url) != 'undefined' && url != null && url.indexOf('refresh_page=1') > 0){
319                 document.location.reload();
320         }
321
322 }
323
324 function markSubPanelLoaded(child_field){
325         child_field_loaded[child_field] = 2;
326 }
327 function hideSubPanel(child_field)
328 {
329         var subpanel = document.getElementById('subpanel_'+child_field);
330         subpanel.style.display = 'none';
331         set_div_cookie(subpanel.cookie_name, 'none');
332 }
333 var sub_cookie_name = get_module_name() + '_divs';
334 var temp = Get_Cookie(sub_cookie_name);
335 var div_cookies = new Array();
336
337 if(temp && typeof(temp) != 'undefined'){
338         div_cookies = get_sub_cookies(temp);
339 }
340 function set_div_cookie(name, display){
341         div_cookies[name] = display;
342         Set_Cookie(sub_cookie_name, subs_to_cookie(div_cookies), 3000, false, false,false);
343 }
344
345
346 function local_open_popup(name, width, height,arg1, arg2, arg3, params)
347 {
348         return open_popup(name, width, height,arg1,arg2,arg3, params);
349 }
350
351 SUGAR.subpanelUtils = function() {
352         var originalLayout = null,
353         subpanelContents = {},
354         subpanelLocked = {},
355
356         // Keeps track of the current subpanel id
357         currentPanelDiv;
358
359         return {
360                 // get the current subpanel layout
361                 getLayout: function(asString, ignoreHidden) {
362                     subpanels = document.getElementById('subpanel_list');
363                     subpanelIds = new Array();
364                     for(wp = 0; wp < subpanels.childNodes.length; wp++) {
365                       if(typeof subpanels.childNodes[wp].id != 'undefined' && subpanels.childNodes[wp].id.match(/whole_subpanel_[\w-]*/) && (typeof ignoreHidden == 'undefined' || subpanels.childNodes[wp].style.display != 'none')) {
366                                 subpanelIds.push(subpanels.childNodes[wp].id.replace(/whole_subpanel_/,''));
367                       }
368                     }
369                         if(asString) return subpanelIds.join(',');
370                         else return subpanelIds;
371                 },
372
373                 // called when subpanel is picked up
374                 onDrag: function(e, id) {
375                         originalLayout = SUGAR.subpanelUtils.getLayout(true, true);
376                 },
377
378                 // called when subpanel is dropped
379                 onDrop: function(e, id) {
380                         newLayout = SUGAR.subpanelUtils.getLayout(true, true);
381                         if(originalLayout != newLayout) { // only save if the layout has changed
382                                 SUGAR.subpanelUtils.saveLayout(newLayout);
383                         }
384                 },
385
386                 // save the layout of the subpanels
387                 saveLayout: function(order) {
388                         ajaxStatus.showStatus(SUGAR.language.get('app_strings', 'LBL_SAVING_LAYOUT'));
389
390                         if(typeof SUGAR.subpanelUtils.currentSubpanelGroup != 'undefined') {
391                                 var orderList = SUGAR.subpanelUtils.getLayout(false, true);
392                                 var currentGroup = SUGAR.subpanelUtils.currentSubpanelGroup;
393                         }
394                         var success = function(data) {
395                                 ajaxStatus.showStatus(SUGAR.language.get('app_strings', 'LBL_SAVED_LAYOUT'));
396                                 window.setTimeout('ajaxStatus.hideStatus()', 2000);
397                                 if(typeof SUGAR.subpanelUtils.currentSubpanelGroup != 'undefined') {
398                                         SUGAR.subpanelUtils.reorderSubpanelSubtabs(currentGroup, orderList);
399                                 }
400                         }
401
402                         url = 'index.php?module=Home&action=SaveSubpanelLayout&layout=' + order + '&layoutModule=' + currentModule;
403                         if(typeof SUGAR.subpanelUtils.currentSubpanelGroup != 'undefined') {
404                                 url = url + '&layoutGroup=' + encodeURI(SUGAR.subpanelUtils.currentSubpanelGroup);
405                         }
406                         var cObj = YAHOO.util.Connect.asyncRequest('GET', url, {success: success, failure: success});
407                 },
408
409         /**
410          * Call when an inline create is saved.
411          * Note: We require the subpanel name to refresh the subpanel contents and
412          * to close the subpanel after the save. However, the code the generates the
413          * button doesn't have access to the subpanel name, only the module name.
414          * Hence this rather long-winded mechanism.
415          * @param theForm
416          * @param buttonName id of the originating 'save' button - we determine the
417          *          associated subpanel name by climbing the DOM from this point
418          */
419                 inlineSave: function(theForm, buttonName) {
420                         ajaxStatus.showStatus(SUGAR.language.get('app_strings', 'LBL_SAVING'));
421                         var success = function(data) {
422                 var module = get_module_name();
423                 var id = get_record_id();
424                 var layout_def_key = get_layout_def_key();
425                 try {
426                     eval('result = ' + data.responseText);
427                 } catch (err) {
428                 }
429                 if (typeof(result) != 'undefined' && result != null && result['status'] == 'dupe') {
430                     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');
431                     return;
432                 } else {
433                     SUGAR.subpanelUtils.cancelCreate(buttonName);
434                     // parse edit form name in order to get the name of
435                     // module which saved item belongs to
436                     var parts = theForm.split('_');
437                     var savedModule = '';
438                     var subPanels = [];
439                     for (var i = parts.length - 1; i >= 0; i --) {
440                         if (parts[i] == '') {
441                             continue;
442                         }
443                         if (savedModule != '') {
444                             savedModule = '_' + savedModule;
445                         }
446                         savedModule = parts[i] + savedModule;
447                         if (window.ModuleSubPanels && window.ModuleSubPanels[savedModule]) {
448                             subPanels = subPanels.concat(window.ModuleSubPanels[savedModule]);
449                         }
450                     }
451                     for (var i = 0; i < subPanels.length; i++) {
452                         showSubPanel(subPanels[i], null, true);
453                     }
454                     ajaxStatus.showStatus(SUGAR.language.get('app_strings', 'LBL_SAVED'));
455                     window.setTimeout('ajaxStatus.hideStatus()', 1000);
456                 }
457                         }
458
459             YAHOO.util.Connect.setForm(theForm, true, true);
460                         var cObj = YAHOO.util.Connect.asyncRequest('POST', 'index.php', {success: success, failure: success, upload:success});
461                         return false;
462                 },
463
464         /**
465          * Retrieves the subpanel form.
466          * Note: We only allow one subpanel form to be open at any given time
467          * because some of the form widgets interfere with each other.
468          * @param theForm
469          * @param theDiv
470          * @param loadingStr
471          */
472                 sendAndRetrieve: function(theForm, theDiv, loadingStr) {
473             // look whether a quick create form is currently opened
474             var quickCreateDiv = YAHOO.util.Selector.query("div.quickcreate", null, true);
475             if (quickCreateDiv)
476             {
477                 var form = YAHOO.util.Selector.query("form", quickCreateDiv, true);
478                 if (form)
479                 {
480                     // discover cancelCreate function parameters needed
481                     var moduleName = YAHOO.util.Selector.query('input[name=module]', form, true).value;
482                     var buttonName = moduleName + "_subpanel_cancel_button";
483                     var cancelled  = false;
484
485                     // try to cancel form submission
486                     SUGAR.subpanelUtils.cancelCreate(buttonName, function()
487                     {
488                         cancelled = true;
489                     });
490
491                     // if submission cancellation was cancelled, do nothing
492                     if (cancelled)
493                     {
494                         return false;
495                     }
496                 }
497             }
498
499                         function success(data) {
500                                 var theDivObj = document.getElementById(theDiv),
501                     divName = theDiv + '_newDiv',
502                     form_el;
503                 SUGAR.subpanelUtils.dataToDOMAvail = false;
504
505                 // Show buttons before we remove subpanel
506                 if (typeof currentPanelDiv != 'undefined' && currentPanelDiv != null) {            
507                     var button_elements = YAHOO.util.Selector.query('td.buttons', currentPanelDiv, false);
508                     YAHOO.util.Dom.setStyle(button_elements, 'display', ''); 
509                 }
510                
511                 // Check if preview subpanel form exists, remove if it does.
512                 SUGAR.subpanelUtils.removeSubPanel();
513
514                                 subpanelContents[theDiv] = {};
515                                 subpanelContents[theDiv]['list'] = theDivObj;
516                                 subpanelContents[theDiv]['newDiv'] = document.createElement('div');
517                                 subpanelContents[theDiv]['newDiv'].innerHTML = '<script type="text/javascript">SUGAR.subpanelUtils.dataToDOMAvail=true;</script>' + data.responseText;
518                                 subpanelContents[theDiv]['newDiv'].id = divName;
519                                 subpanelContents[theDiv]['newDiv'].className = 'quickcreate';
520
521                                 // Grab the buttons from the subpanel and hide them
522                                 var button_elements = YAHOO.util.Selector.query('td.buttons', theDiv, false);
523                                 YAHOO.util.Dom.setStyle(button_elements, 'display', 'none');
524                                 button_elements = YAHOO.util.Selector.query('ul.SugarActionMenu', theDiv, false);
525                                 YAHOO.util.Dom.setStyle(button_elements, 'display', 'none');
526
527                 // Add the form object to the DOM
528                                 theDivObj.parentNode.insertBefore(subpanelContents[theDiv]['newDiv'], theDivObj);
529                 currentPanelDiv = divName;
530
531                 if (!SUGAR.subpanelUtils.dataToDOMAvail) {
532                                         SUGAR.util.evalScript(data.responseText);
533                                 }
534
535                                 form_el = YAHOO.util.Selector.query('form', divName, true);
536                 YAHOO.util.Dom.setStyle(form_el, 'padding-bottom', '10px');
537                 
538                 subpanelLocked[theDiv] = false;
539                 setTimeout("enableQS(false)",500);
540                                 ajaxStatus.hideStatus();
541                         }
542
543                         if (subpanelLocked[theDiv] === true) {
544                 return false;
545             }
546             
547                         subpanelLocked[theDiv] = true;
548
549                         loadingStr = loadingStr || SUGAR.language.get('app_strings', 'LBL_LOADING');
550                         ajaxStatus.showStatus(loadingStr);
551                         YAHOO.util.Connect.setForm(theForm);
552                         YAHOO.util.Connect.asyncRequest('POST', 'index.php', {success: success, failure: success});
553
554                         return false;
555                 },
556
557         // as long as formerly the function used to be always returning false,
558         // there was no possibility to determine, was the creation cancelled or not.
559         // we couldn't modify function return value in case of user cancels the
560         // cancellation as long as it (false) is used in multiple places to
561         // prevent DOM event propagation. thus, cancelCallback optional
562         // parameter is added to be able to track this case
563                 cancelCreate: function(buttonName, cancelCallback) {
564                         var element = document.getElementById(buttonName),
565                 theForm = element.form,
566                 confirmMsg = onUnloadEditView(theForm);
567
568                         do {
569                                 element = element.parentNode;
570                         } while ( element.className != 'quickcreate' && element.parentNode ) ;
571
572                         var theDiv = element.id.substr(0,element.id.length-7);
573
574                         if (typeof(subpanelContents[theDiv]) == 'undefined')
575                 return false;
576
577             if ( confirmMsg != null ) {
578                 if ( !confirm(confirmMsg) ) {
579                     if ("function" === typeof cancelCallback)
580                     {
581                         cancelCallback();
582                     }
583                     return false;
584                 } else {
585                     disableOnUnloadEditView(theForm);
586                 }
587             }
588
589             SUGAR.subpanelUtils.removeSubPanel();
590             var button_elements = YAHOO.util.Selector.query('td.buttons', theDiv, false);
591             YAHOO.util.Dom.setStyle(button_elements, 'display', '');
592             button_elements = YAHOO.util.Selector.query('ul.SugarActionMenu', theDiv, false);
593             YAHOO.util.Dom.setStyle(button_elements, 'display', '');
594             
595                         return false;
596                 },
597
598                 loadSubpanelGroupFromMore: function(group){
599                         SUGAR.subpanelUtils.updateSubpanelMoreTab(group);
600                         SUGAR.subpanelUtils.loadSubpanelGroup(group);
601                 },
602
603                 updateSubpanelMoreTab: function(group){
604                         // Update Tab
605                         var moreTab = document.getElementById(SUGAR.subpanelUtils.subpanelMoreTab + '_sp_tab');
606                         moreTab.id = group + '_sp_tab';
607                         moreTab.getElementsByTagName('a')[0].innerHTML = group;
608                         moreTab.getElementsByTagName('a')[0].href = "javascript:SUGAR.subpanelUtils.loadSubpanelGroup('"+group+"');";
609
610                         // Update Menu
611                         var menuLink = document.getElementById(group+'_sp_mm');
612                         menuLink.id = SUGAR.subpanelUtils.subpanelMoreTab+'_sp_mm';
613                         menuLink.href = "javascript:SUGAR.subpanelUtils.loadSubpanelGroupFromMore('"+SUGAR.subpanelUtils.subpanelMoreTab+"');";
614                         menuLink.innerHTML = SUGAR.subpanelUtils.subpanelMoreTab;
615
616                         SUGAR.subpanelUtils.subpanelMoreTab = group;
617                 },
618
619         /**
620          * Removes the current subpanel if it exists.
621          */
622         removeSubPanel: function() {
623             var currentPanelEl = null;
624             if (typeof currentPanelDiv != 'undefined' && currentPanelDiv != null) {
625                 currentPanelEl = document.getElementById(currentPanelDiv);
626             }
627
628             if (currentPanelEl != null) {
629                 currentPanelEl.parentNode.removeChild(currentPanelEl);
630                 SUGAR.ajaxUI.cleanGlobals();
631                 currentPanelDiv = null;
632             }
633         },
634
635                 /* loadSubpanels:
636                 /* construct set of needed subpanels */
637                 /* if we have not yet loaded this subpanel group, */
638                 /*     set loadedGroups[group] */
639                 /*     for each subpanel in subpanelGroups[group] */
640                 /*         if document.getElementById('whole_subpanel_'+subpanel) doesn't exist */
641                 /*         then add subpanel to set of needed subpanels */
642                 /*     if we need to load any subpanels, send a request for them */
643                 /*            with updateSubpanels as the callback. */
644                 /* otherwise call updateSubpanels */
645                 /* call setGroupCookie */
646
647                 loadSubpanelGroup: function(group){
648                         if(group == SUGAR.subpanelUtils.currentSubpanelGroup) return;
649
650                         if(SUGAR.subpanelUtils.loadedGroups[group]){
651                                 SUGAR.subpanelUtils.updateSubpanel(group);
652                         }else{
653
654                                 SUGAR.subpanelUtils.loadedGroups.push(group);
655                                 var needed = [];
656                                 for(group_sp in SUGAR.subpanelUtils.subpanelGroups[group]){
657                                         if(typeof(SUGAR.subpanelUtils.subpanelGroups[group][group_sp]) == 'string' && !document.getElementById('whole_subpanel_'+SUGAR.subpanelUtils.subpanelGroups[group][group_sp])){
658                                                 needed.push(SUGAR.subpanelUtils.subpanelGroups[group][group_sp]);
659                                         }
660                                 }
661                                 var success = function(){
662                                         SUGAR.subpanelUtils.updateSubpanelEventHandlers(needed);
663                                         SUGAR.subpanelUtils.updateSubpanels(group);
664                                 };
665                                 /* needed to retrieve each of the specified subpanels and install them ...*/
666                                 /* load them in bulk, insert via innerHTML, then sort nodes later. */
667                                 if(needed.length){
668
669                                         ajaxStatus.showStatus(SUGAR.language.get('app_strings', 'LBL_LOADING'));
670                                         SUGAR.util.retrieveAndFill(SUGAR.subpanelUtils.requestUrl + needed.join(','),'subpanel_list', null, success, null, true);
671                                 }else{
672                                         SUGAR.subpanelUtils.updateSubpanels(group);
673                                 }
674                         }
675                         SUGAR.subpanelUtils.setGroupCookie(group);
676                 },
677
678                 /* updateSubpanels:
679                 /* for each child node of subpanel_list */
680                 /*     let subpanel name be id.match(/whole_subpanel_(\w*)/) */
681                 /*     if the subpanel name is in the list of subpanels for the current group, show it */
682                 /*     otherwise hide it */
683                 /* swap nodes to suit user's order */
684                 /* call updateSubpanelTabs */
685
686                 updateSubpanels: function(group){
687                         var sp_list = document.getElementById('subpanel_list');
688                         for(sp in sp_list.childNodes){
689                                 if(sp_list.childNodes[sp].id){
690                                         sp_list.childNodes[sp].style.display = 'none';
691                                 }
692                         }
693
694                         for(group_sp in SUGAR.subpanelUtils.subpanelGroups[group]){
695                 if ( typeof(SUGAR.subpanelUtils.subpanelGroups[group][group_sp]) != 'string' )
696                 {
697                     continue;
698                 }
699                                 var cur = document.getElementById('whole_subpanel_'+SUGAR.subpanelUtils.subpanelGroups[group][group_sp]);
700                             
701                 if(cur == null)
702                 {
703                     continue;
704                 }
705
706                 cur.style.display = 'block';
707
708                         }
709
710                         SUGAR.subpanelUtils.updateSubpanelTabs(group);
711                 },
712
713                 updateSubpanelTabs: function(group){
714                         if(SUGAR.subpanelUtils.showLinks){
715                                 SUGAR.subpanelUtils.updateSubpanelSubtabs(group);
716                                 document.getElementById('subpanelSubTabs').innerHTML = SUGAR.subpanelUtils.subpanelSubTabs[group];
717                         }
718
719                         oldTab = document.getElementById(SUGAR.subpanelUtils.currentSubpanelGroup+'_sp_tab');
720                         if(oldTab){
721                                 oldTab.className = '';
722                                 oldTab.getElementsByTagName('a')[0].className = '';
723                         }
724
725                         mainTab = document.getElementById(group+'_sp_tab');
726                         mainTab.className = 'active';
727                         mainTab.getElementsByTagName('a')[0].className = 'current';
728
729                         SUGAR.subpanelUtils.currentSubpanelGroup = group;
730                         ajaxStatus.hideStatus();
731                 },
732
733                 updateSubpanelEventHandlers: function(){
734                         if(SubpanelInitTabNames){
735                                 SubpanelInitTabNames(SUGAR.subpanelUtils.getLayout(false));
736                         }
737                 },
738
739                 reorderSubpanelSubtabs: function(group, order){
740                         SUGAR.subpanelUtils.subpanelGroups[group] = order;
741                         if(SUGAR.subpanelUtils.showLinks==1){
742                                 SUGAR.subpanelUtils.updateSubpanelSubtabs(group);
743                                 if(SUGAR.subpanelUtils.currentSubpanelGroup == group){
744                                         document.getElementById('subpanelSubTabs').innerHTML = SUGAR.subpanelUtils.subpanelSubTabs[group];
745                                 }
746                         }
747                 },
748
749                 // Re-renders the contents of subpanelSubTabs[group].
750                 // Does not immediately affect what's on the screen.
751                 updateSubpanelSubtabs: function(group){
752                         var notFirst = 0;
753                         var preMore = SUGAR.subpanelUtils.subpanelGroups[group].slice(0, SUGAR.subpanelUtils.subpanelMaxSubtabs);
754
755                         SUGAR.subpanelUtils.subpanelSubTabs[group] = '<table border="0" cellpadding="0" cellspacing="0" height="20" width="100%" class="subTabs"><tr>';
756
757                         for(var sp_key = 0; sp_key < preMore.length; sp_key++){
758                                 if(notFirst != 0){
759                                         SUGAR.subpanelUtils.subpanelSubTabs[group] += '<td width="1"> | </td>';
760                                 }else{
761                                         notFirst = 1;
762                                 }
763                                 SUGAR.subpanelUtils.subpanelSubTabs[group] += '<td nowrap="nowrap"><a href="#'+preMore[sp_key]+'" class="subTabLink">'+SUGAR.subpanelUtils.subpanelTitles[preMore[sp_key]]+'</a></td>';
764                         }
765                         if(document.getElementById('MoreSub'+group+'PanelMenu')){
766                                 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>';
767                         }
768                         SUGAR.subpanelUtils.subpanelSubTabs[group] += '<td width="100%">&nbsp;</td></tr></table>';
769
770                         // Update the more menu for the current group
771                         var postMore = SUGAR.subpanelUtils.subpanelGroups[group].slice(SUGAR.subpanelUtils.subpanelMaxSubtabs);
772                         var subpanelMenu = document.getElementById('MoreSub'+group+'PanelMenu');
773
774                         if(postMore && subpanelMenu){
775                                 subpanelMenu.innerHTML = '';
776                                 for(var sp_key = 0; sp_key < postMore.length; sp_key++){
777                                         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>';
778                                 }
779                                 subpanelMenu += '</div>';
780                         }
781                 },
782
783                 setGroupCookie: function(group){
784                         Set_Cookie(SUGAR.subpanelUtils.tabCookieName, group, 3000, false, false,false);
785                 }
786         };
787 }();
788
789 SUGAR.subpanelUtils.menu = function(){
790         return {
791                 tbspButtonMouseOver : function(id,top,left,leftOffset){ //*//
792                         closeMenusDelay = eraseTimeout(closeMenusDelay);
793                         if (openMenusDelay == null){
794                                 openMenusDelay = window.setTimeout("SUGAR.subpanelUtils.menu.spShowMenu('"+id+"','"+top+"','"+left+"','"+leftOffset+"')", delayTime);
795                         }
796                 },
797                 spShowMenu : function(id,top,left,leftOffset){ //*//
798                         openMenusDelay = eraseTimeout(openMenusDelay);
799                         var menuName = id.replace(/Handle/i,'Menu');
800                         var menu = getLayer(menuName);
801                         //if (menu) menu.className = 'tbButtonMouseOverUp';
802                         if (currentMenu){
803                                 closeAllMenus();
804                         }
805                         SUGAR.subpanelUtils.menu.spPopupMenu(id, menu, top,left,leftOffset);
806                 },
807                 spPopupMenu : function(handleID, menu, top, left, leftOffset){ //*//
808                         var bw = checkBrowserWidth();
809                         var menuName = handleID.replace(/Handle/i,'Menu');
810                         var menuWidth = 120;
811                         var imgWidth = document.getElementById(handleID).width;
812                         if (menu){
813                                 var menuHandle = getLayer(handleID);
814                                 var p=menuHandle;
815                                 if (left == "") {
816                                         var left = 0;
817                                         while(p&&p.tagName.toUpperCase()!='BODY'){
818                                                 left+=p.offsetLeft;
819                                                 p=p.offsetParent;
820                                         }
821                                         left+=parseInt(leftOffset);
822                                 }
823                                 if (top == "") {
824                                         var top = 0;
825                                         p=menuHandle;
826                                         top+=p.offsetHeight;
827                                         while(p&&p.tagName.toUpperCase()!='BODY'){
828                                                 top+=p.offsetTop;
829                                                 p=p.offsetParent;
830                                         }
831                                 }
832                                 if (left+menuWidth>bw) {
833                                         left = left-menuWidth+imgWidth;
834                                 }
835                                 setMenuVisible(menu, left, top, false);
836                         }
837                 }
838         };
839 }();