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