1 /*********************************************************************************
2 * SugarCRM Community Edition is a customer relationship management program developed by
3 * SugarCRM, Inc. Copyright (C) 2004-2012 SugarCRM Inc.
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.
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
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
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.
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.
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 ********************************************************************************/
40 var current_child_field = '';
41 var current_subpanel_url = '';
42 var child_field_loaded = new Object();
43 var request_map = new Object();
45 function get_module_name()
47 if(typeof(window.document.forms['DetailView']) == 'undefined') {
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;
59 return window.document.forms['DetailView'].elements['module'].value;
62 /*this function will take in three parameters, m,i,a and recreate navigation
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
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
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";
83 url += "&return_relationship=" + r;
89 /*this function will take in three parameters, m,i,a and recreate navigation
92 * a = action (detail/edit)
93 * This is done to minimize page size
95 function sub_p_rem(sp,lf,li,rp){
97 return_url = "index.php?module="+get_module_name()+"&action=SubPanelViewer&subpanel="+sp+"&record="+get_record_id()+"&sugar_body_only=1&inline=1";
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);
109 function sp_rem_conf(){
110 return confirm(SUGAR.language.get('app_strings', 'NTC_REMOVE_CONFIRMATION'))
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";
116 remove_url = "index.php?module="+ submod
119 + "&return_url=" + escape(escape(return_url))
120 + "&refresh_page=" + rp;//$refresh_page"
121 showSubPanel(sp,remove_url,true);
124 function sp_del_conf(){
125 return confirm(SUGAR.language.get('app_strings', 'NTC_DELETE_CONFIRMATION'))
128 function get_record_id()
130 return window.document.forms['DetailView'].elements['record'].value;
132 function get_layout_def_key()
134 if(typeof(window.document.forms['DetailView'].elements['layout_def_key']) == 'undefined')return '';
135 return window.document.forms['DetailView'].elements['layout_def_key'].value;
138 function save_finished(args)
140 var child_field = request_map[args.request_id];
141 delete (child_field_loaded[child_field] );
142 showSubPanel(child_field);
145 function set_return_and_save_background(popup_reply_data)
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)
157 if(the_key == 'toJSON')
163 query_array.push(the_key+"="+name_to_value_array[the_key]);
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)
172 query_array.push('subpanel_id[]='+selection_list[the_key])
175 var module = get_module_name();
176 var id = get_record_id();
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);
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]));
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]));
203 query_array.push(prop+'='+escape(passthru_data[prop]));
208 var query_string = query_array.join('&');
209 request_map[request_id] = passthru_data['child_field'];
211 var returnstuff = http_fetch_sync('index.php',query_string);
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);
220 if(refresh_page == 1){
221 document.location.reload(true);
225 function got_data(args, inline)
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();
236 child_field_loaded[child_field] = 2;
237 list_subpanel.innerHTML='';
238 list_subpanel.innerHTML=args.responseText;
241 child_field_loaded[child_field] = 1;
242 subpanel.innerHTML='';
243 subpanel.innerHTML=args.responseText;
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);
254 subpanel.style.display = '';
255 set_div_cookie(subpanel.cookie_name, '');
257 if (current_child_field != '' && child_field != current_child_field)
259 // commented out for now. this was originally used by tab UI of subpanels
260 //hideSubPanel(current_child_field);
262 current_child_field = child_field;
263 //reinit action menus
264 $("ul.clickMenu").each(function(index, node){
265 $(node).sugarActionMenu();
270 function showSubPanel(child_field,url,force_load,layout_def_key)
273 if ( typeof(force_load) == 'undefined' || force_load == null)
278 if (force_load || typeof( child_field_loaded[child_field] ) == 'undefined')
280 request_map[request_id] = child_field;
281 if ( typeof (url) == 'undefined' || url == null)
283 var module = get_module_name();
284 var id = get_record_id();
285 if ( typeof(layout_def_key) == 'undefined' || layout_def_key == null ) {
286 layout_def_key = get_layout_def_key();
289 url = 'index.php?sugar_body_only=1&module='+module+'&subpanel='+child_field+'&action=SubPanelViewer&inline=' + inline + '&record='+id + '&layout_def_key='+ layout_def_key;
292 if ( url.indexOf('http://') != 0 && url.indexOf('https://') != 0)
297 current_subpanel_url = url;
298 // http_fetch_async(url,got_data,request_id++);
299 var returnstuff = http_fetch_sync(url+ '&inline=' + inline + '&ajaxSubpanel=true');
301 got_data(returnstuff, inline);
305 var subpanel = document.getElementById('subpanel_'+child_field);
306 subpanel.style.display = '';
308 set_div_cookie(subpanel.cookie_name, '');
310 if (current_child_field != '' && child_field != current_child_field)
312 hideSubPanel(current_child_field);
315 current_child_field = child_field;
317 if(typeof(url) != 'undefined' && url != null && url.indexOf('refresh_page=1') > 0){
318 document.location.reload();
323 function markSubPanelLoaded(child_field){
324 child_field_loaded[child_field] = 2;
326 function hideSubPanel(child_field)
328 var subpanel = document.getElementById('subpanel_'+child_field);
329 subpanel.style.display = 'none';
330 set_div_cookie(subpanel.cookie_name, 'none');
332 var sub_cookie_name = get_module_name() + '_divs';
333 var temp = Get_Cookie(sub_cookie_name);
334 var div_cookies = new Array();
336 if(temp && typeof(temp) != 'undefined'){
337 div_cookies = get_sub_cookies(temp);
339 function set_div_cookie(name, display){
340 div_cookies[name] = display;
341 Set_Cookie(sub_cookie_name, subs_to_cookie(div_cookies), 3000, false, false,false);
345 function local_open_popup(name, width, height,arg1, arg2, arg3, params)
347 return open_popup(name, width, height,arg1,arg2,arg3, params);
350 SUGAR.subpanelUtils = function() {
351 var originalLayout = null,
352 subpanelContents = {},
355 // Keeps track of the current subpanel id
359 // get the current subpanel layout
360 getLayout: function(asString, ignoreHidden) {
361 subpanels = document.getElementById('subpanel_list');
362 subpanelIds = new Array();
363 for(wp = 0; wp < subpanels.childNodes.length; wp++) {
364 if(typeof subpanels.childNodes[wp].id != 'undefined' && subpanels.childNodes[wp].id.match(/whole_subpanel_[\w-]*/) && (typeof ignoreHidden == 'undefined' || subpanels.childNodes[wp].style.display != 'none')) {
365 subpanelIds.push(subpanels.childNodes[wp].id.replace(/whole_subpanel_/,''));
368 if(asString) return subpanelIds.join(',');
369 else return subpanelIds;
372 // called when subpanel is picked up
373 onDrag: function(e, id) {
374 originalLayout = SUGAR.subpanelUtils.getLayout(true, true);
377 // called when subpanel is dropped
378 onDrop: function(e, id) {
379 newLayout = SUGAR.subpanelUtils.getLayout(true, true);
380 if(originalLayout != newLayout) { // only save if the layout has changed
381 SUGAR.subpanelUtils.saveLayout(newLayout);
385 // save the layout of the subpanels
386 saveLayout: function(order) {
387 ajaxStatus.showStatus(SUGAR.language.get('app_strings', 'LBL_SAVING_LAYOUT'));
389 if(typeof SUGAR.subpanelUtils.currentSubpanelGroup != 'undefined') {
390 var orderList = SUGAR.subpanelUtils.getLayout(false, true);
391 var currentGroup = SUGAR.subpanelUtils.currentSubpanelGroup;
393 var success = function(data) {
394 ajaxStatus.showStatus(SUGAR.language.get('app_strings', 'LBL_SAVED_LAYOUT'));
395 window.setTimeout('ajaxStatus.hideStatus()', 2000);
396 if(typeof SUGAR.subpanelUtils.currentSubpanelGroup != 'undefined') {
397 SUGAR.subpanelUtils.reorderSubpanelSubtabs(currentGroup, orderList);
401 url = 'index.php?module=Home&action=SaveSubpanelLayout&layout=' + order + '&layoutModule=' + currentModule;
402 if(typeof SUGAR.subpanelUtils.currentSubpanelGroup != 'undefined') {
403 url = url + '&layoutGroup=' + encodeURI(SUGAR.subpanelUtils.currentSubpanelGroup);
405 var cObj = YAHOO.util.Connect.asyncRequest('GET', url, {success: success, failure: success});
409 * Call when an inline create is saved.
410 * Note: We require the subpanel name to refresh the subpanel contents and
411 * to close the subpanel after the save. However, the code the generates the
412 * button doesn't have access to the subpanel name, only the module name.
413 * Hence this rather long-winded mechanism.
415 * @param buttonName id of the originating 'save' button - we determine the
416 * associated subpanel name by climbing the DOM from this point
418 inlineSave: function(theForm, buttonName) {
419 ajaxStatus.showStatus(SUGAR.language.get('app_strings', 'LBL_SAVING'));
420 var success = function(data) {
421 var element = document.getElementById(buttonName);
423 element = element.parentNode;
424 } while ( element.className != 'quickcreate' && element.parentNode ) ;
426 if (element.className == 'quickcreate') {
427 var subpanel = element.id.slice(9,-7) ; // retrieve the subpanel name from the div id - the name is encoded as 'subpanel_<subpanelname>_newdiv'
429 var module = get_module_name();
430 var id = get_record_id();
431 var layout_def_key = get_layout_def_key();
433 eval('result = ' + data.responseText);
438 if (typeof(result) != 'undefined' && result != null && result['status'] == 'dupe') {
439 document.location.href = "index.php?" + result['get'].replace(/&/gi,'&').replace(/</gi,'<').replace(/>/gi,'>').replace(/'/gi,'\'').replace(/"/gi,'"').replace(/\r\n/gi,'\n');
442 SUGAR.subpanelUtils.cancelCreate(buttonName);
443 showSubPanel(subpanel, null, true);
444 ajaxStatus.showStatus(SUGAR.language.get('app_strings', 'LBL_SAVED'));
445 window.setTimeout('ajaxStatus.hideStatus()', 1000);
446 if(reloadpage) window.location.reload(false);
450 // reload page if we are setting status to Held
451 var reloadpage = false;
452 // Bug #51388 - Captivea (qch)
453 reloadpage = reloadpage || ((buttonName == 'Meetings_subpanel_save_button' || buttonName == 'Calls_subpanel_save_button' )
454 && typeof(theForm) !='undefined' && typeof(document.getElementById(theForm)) != 'undefined'
455 && typeof(document.getElementById(theForm).status) != 'undefined'
456 && document.getElementById(theForm).status[document.getElementById(theForm).status.selectedIndex].value == 'Held');
457 reloadpage = reloadpage || (buttonName == 'Tasks_subpanel_save_button'
458 && typeof(theForm) !='undefined' && typeof(document.getElementById(theForm)) != 'undefined'
459 && typeof(document.getElementById(theForm).status) != 'undefined'
460 && document.getElementById(theForm).status[document.getElementById(theForm).status.selectedIndex].value == 'Completed');
462 YAHOO.util.Connect.setForm(theForm, true, true);
463 var cObj = YAHOO.util.Connect.asyncRequest('POST', 'index.php', {success: success, failure: success, upload:success});
468 * Retrieves the subpanel form.
469 * Note: We only allow one subpanel form to be open at any given time
470 * because some of the form widgets interfere with each other.
475 sendAndRetrieve: function(theForm, theDiv, loadingStr) {
476 // look whether a quick create form is currently opened
477 var quickCreateDiv = YAHOO.util.Selector.query("div.quickcreate", null, true);
480 var form = YAHOO.util.Selector.query("form", quickCreateDiv, true);
483 // discover cancelCreate function parameters needed
484 var moduleName = form.id.replace(/.*?_([^_]+)$/, "$1");
485 var buttonName = moduleName + "_subpanel_cancel_button";
486 var cancelled = false;
488 // try to cancel form submission
489 SUGAR.subpanelUtils.cancelCreate(buttonName, function()
494 // if submission cancellation was cancelled, do nothing
502 function success(data) {
503 var theDivObj = document.getElementById(theDiv),
504 divName = theDiv + '_newDiv',
506 SUGAR.subpanelUtils.dataToDOMAvail = false;
508 // Show buttons before we remove subpanel
509 if (typeof currentPanelDiv != 'undefined' && currentPanelDiv != null) {
510 var button_elements = YAHOO.util.Selector.query('td.buttons', currentPanelDiv, false);
511 YAHOO.util.Dom.setStyle(button_elements, 'display', '');
514 // Check if preview subpanel form exists, remove if it does.
515 SUGAR.subpanelUtils.removeSubPanel();
517 subpanelContents[theDiv] = {};
518 subpanelContents[theDiv]['list'] = theDivObj;
519 subpanelContents[theDiv]['newDiv'] = document.createElement('div');
520 subpanelContents[theDiv]['newDiv'].innerHTML = '<script type="text/javascript">SUGAR.subpanelUtils.dataToDOMAvail=true;</script>' + data.responseText;
521 subpanelContents[theDiv]['newDiv'].id = divName;
522 subpanelContents[theDiv]['newDiv'].className = 'quickcreate';
524 // Grab the buttons from the subpanel and hide them
525 var button_elements = YAHOO.util.Selector.query('td.buttons', theDiv, false);
526 YAHOO.util.Dom.setStyle(button_elements, 'display', 'none');
527 button_elements = YAHOO.util.Selector.query('ul.SugarActionMenu', theDiv, false);
528 YAHOO.util.Dom.setStyle(button_elements, 'display', 'none');
530 // Add the form object to the DOM
531 theDivObj.parentNode.insertBefore(subpanelContents[theDiv]['newDiv'], theDivObj);
532 currentPanelDiv = divName;
534 if (!SUGAR.subpanelUtils.dataToDOMAvail) {
535 SUGAR.util.evalScript(data.responseText);
538 form_el = YAHOO.util.Selector.query('form', divName, true);
539 YAHOO.util.Dom.setStyle(form_el, 'padding-bottom', '10px');
541 subpanelLocked[theDiv] = false;
542 setTimeout("enableQS(false)",500);
543 ajaxStatus.hideStatus();
546 if (subpanelLocked[theDiv] === true) {
550 subpanelLocked[theDiv] = true;
552 loadingStr = loadingStr || SUGAR.language.get('app_strings', 'LBL_LOADING');
553 ajaxStatus.showStatus(loadingStr);
554 YAHOO.util.Connect.setForm(theForm);
555 YAHOO.util.Connect.asyncRequest('POST', 'index.php', {success: success, failure: success});
560 // as long as formerly the function used to be always returning false,
561 // there was no possibility to determine, was the creation cancelled or not.
562 // we couldn't modify function return value in case of user cancels the
563 // cancellation as long as it (false) is used in multiple places to
564 // prevent DOM event propagation. thus, cancelCallback optional
565 // parameter is added to be able to track this case
566 cancelCreate: function(buttonName, cancelCallback) {
567 var element = document.getElementById(buttonName),
568 theForm = element.form,
569 confirmMsg = onUnloadEditView(theForm);
572 element = element.parentNode;
573 } while ( element.className != 'quickcreate' && element.parentNode ) ;
575 var theDiv = element.id.substr(0,element.id.length-7);
577 if (typeof(subpanelContents[theDiv]) == 'undefined')
580 if ( confirmMsg != null ) {
581 if ( !confirm(confirmMsg) ) {
582 if ("function" === typeof cancelCallback)
588 disableOnUnloadEditView(theForm);
592 SUGAR.subpanelUtils.removeSubPanel();
593 var button_elements = YAHOO.util.Selector.query('td.buttons', theDiv, false);
594 YAHOO.util.Dom.setStyle(button_elements, 'display', '');
595 button_elements = YAHOO.util.Selector.query('ul.SugarActionMenu', theDiv, false);
596 YAHOO.util.Dom.setStyle(button_elements, 'display', '');
601 loadSubpanelGroupFromMore: function(group){
602 SUGAR.subpanelUtils.updateSubpanelMoreTab(group);
603 SUGAR.subpanelUtils.loadSubpanelGroup(group);
606 updateSubpanelMoreTab: function(group){
608 var moreTab = document.getElementById(SUGAR.subpanelUtils.subpanelMoreTab + '_sp_tab');
609 moreTab.id = group + '_sp_tab';
610 moreTab.getElementsByTagName('a')[0].innerHTML = group;
611 moreTab.getElementsByTagName('a')[0].href = "javascript:SUGAR.subpanelUtils.loadSubpanelGroup('"+group+"');";
614 var menuLink = document.getElementById(group+'_sp_mm');
615 menuLink.id = SUGAR.subpanelUtils.subpanelMoreTab+'_sp_mm';
616 menuLink.href = "javascript:SUGAR.subpanelUtils.loadSubpanelGroupFromMore('"+SUGAR.subpanelUtils.subpanelMoreTab+"');";
617 menuLink.innerHTML = SUGAR.subpanelUtils.subpanelMoreTab;
619 SUGAR.subpanelUtils.subpanelMoreTab = group;
623 * Removes the current subpanel if it exists.
625 removeSubPanel: function() {
626 var currentPanelEl = null;
627 if (typeof currentPanelDiv != 'undefined' && currentPanelDiv != null) {
628 currentPanelEl = document.getElementById(currentPanelDiv);
631 if (currentPanelEl != null) {
632 currentPanelEl.parentNode.removeChild(currentPanelEl);
633 SUGAR.ajaxUI.cleanGlobals();
634 currentPanelDiv = null;
639 /* construct set of needed subpanels */
640 /* if we have not yet loaded this subpanel group, */
641 /* set loadedGroups[group] */
642 /* for each subpanel in subpanelGroups[group] */
643 /* if document.getElementById('whole_subpanel_'+subpanel) doesn't exist */
644 /* then add subpanel to set of needed subpanels */
645 /* if we need to load any subpanels, send a request for them */
646 /* with updateSubpanels as the callback. */
647 /* otherwise call updateSubpanels */
648 /* call setGroupCookie */
650 loadSubpanelGroup: function(group){
651 if(group == SUGAR.subpanelUtils.currentSubpanelGroup) return;
653 if(SUGAR.subpanelUtils.loadedGroups[group]){
654 SUGAR.subpanelUtils.updateSubpanel(group);
657 SUGAR.subpanelUtils.loadedGroups.push(group);
659 for(group_sp in SUGAR.subpanelUtils.subpanelGroups[group]){
660 if(typeof(SUGAR.subpanelUtils.subpanelGroups[group][group_sp]) == 'string' && !document.getElementById('whole_subpanel_'+SUGAR.subpanelUtils.subpanelGroups[group][group_sp])){
661 needed.push(SUGAR.subpanelUtils.subpanelGroups[group][group_sp]);
664 var success = function(){
665 SUGAR.subpanelUtils.updateSubpanelEventHandlers(needed);
666 SUGAR.subpanelUtils.updateSubpanels(group);
668 /* needed to retrieve each of the specified subpanels and install them ...*/
669 /* load them in bulk, insert via innerHTML, then sort nodes later. */
672 ajaxStatus.showStatus(SUGAR.language.get('app_strings', 'LBL_LOADING'));
673 SUGAR.util.retrieveAndFill(SUGAR.subpanelUtils.requestUrl + needed.join(','),'subpanel_list', null, success, null, true);
675 SUGAR.subpanelUtils.updateSubpanels(group);
678 SUGAR.subpanelUtils.setGroupCookie(group);
682 /* for each child node of subpanel_list */
683 /* let subpanel name be id.match(/whole_subpanel_(\w*)/) */
684 /* if the subpanel name is in the list of subpanels for the current group, show it */
685 /* otherwise hide it */
686 /* swap nodes to suit user's order */
687 /* call updateSubpanelTabs */
689 updateSubpanels: function(group){
690 var sp_list = document.getElementById('subpanel_list');
691 for(sp in sp_list.childNodes){
692 if(sp_list.childNodes[sp].id){
693 sp_list.childNodes[sp].style.display = 'none';
697 for(group_sp in SUGAR.subpanelUtils.subpanelGroups[group]){
698 if ( typeof(SUGAR.subpanelUtils.subpanelGroups[group][group_sp]) != 'string' )
702 var cur = document.getElementById('whole_subpanel_'+SUGAR.subpanelUtils.subpanelGroups[group][group_sp]);
709 cur.style.display = 'block';
713 SUGAR.subpanelUtils.updateSubpanelTabs(group);
716 updateSubpanelTabs: function(group){
717 if(SUGAR.subpanelUtils.showLinks){
718 SUGAR.subpanelUtils.updateSubpanelSubtabs(group);
719 document.getElementById('subpanelSubTabs').innerHTML = SUGAR.subpanelUtils.subpanelSubTabs[group];
722 oldTab = document.getElementById(SUGAR.subpanelUtils.currentSubpanelGroup+'_sp_tab');
724 oldTab.className = '';
725 oldTab.getElementsByTagName('a')[0].className = '';
728 mainTab = document.getElementById(group+'_sp_tab');
729 mainTab.className = 'active';
730 mainTab.getElementsByTagName('a')[0].className = 'current';
732 SUGAR.subpanelUtils.currentSubpanelGroup = group;
733 ajaxStatus.hideStatus();
736 updateSubpanelEventHandlers: function(){
737 if(SubpanelInitTabNames){
738 SubpanelInitTabNames(SUGAR.subpanelUtils.getLayout(false));
742 reorderSubpanelSubtabs: function(group, order){
743 SUGAR.subpanelUtils.subpanelGroups[group] = order;
744 if(SUGAR.subpanelUtils.showLinks==1){
745 SUGAR.subpanelUtils.updateSubpanelSubtabs(group);
746 if(SUGAR.subpanelUtils.currentSubpanelGroup == group){
747 document.getElementById('subpanelSubTabs').innerHTML = SUGAR.subpanelUtils.subpanelSubTabs[group];
752 // Re-renders the contents of subpanelSubTabs[group].
753 // Does not immediately affect what's on the screen.
754 updateSubpanelSubtabs: function(group){
756 var preMore = SUGAR.subpanelUtils.subpanelGroups[group].slice(0, SUGAR.subpanelUtils.subpanelMaxSubtabs);
758 SUGAR.subpanelUtils.subpanelSubTabs[group] = '<table border="0" cellpadding="0" cellspacing="0" height="20" width="100%" class="subTabs"><tr>';
760 for(var sp_key = 0; sp_key < preMore.length; sp_key++){
762 SUGAR.subpanelUtils.subpanelSubTabs[group] += '<td width="1"> | </td>';
766 SUGAR.subpanelUtils.subpanelSubTabs[group] += '<td nowrap="nowrap"><a href="#'+preMore[sp_key]+'" class="subTabLink">'+SUGAR.subpanelUtils.subpanelTitles[preMore[sp_key]]+'</a></td>';
768 if(document.getElementById('MoreSub'+group+'PanelMenu')){
769 SUGAR.subpanelUtils.subpanelSubTabs[group] += '<td nowrap="nowrap"> | <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);">>></span></td>';
771 SUGAR.subpanelUtils.subpanelSubTabs[group] += '<td width="100%"> </td></tr></table>';
773 // Update the more menu for the current group
774 var postMore = SUGAR.subpanelUtils.subpanelGroups[group].slice(SUGAR.subpanelUtils.subpanelMaxSubtabs);
775 var subpanelMenu = document.getElementById('MoreSub'+group+'PanelMenu');
777 if(postMore && subpanelMenu){
778 subpanelMenu.innerHTML = '';
779 for(var sp_key = 0; sp_key < postMore.length; sp_key++){
780 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>';
782 subpanelMenu += '</div>';
786 setGroupCookie: function(group){
787 Set_Cookie(SUGAR.subpanelUtils.tabCookieName, group, 3000, false, false,false);
792 SUGAR.subpanelUtils.menu = function(){
794 tbspButtonMouseOver : function(id,top,left,leftOffset){ //*//
795 closeMenusDelay = eraseTimeout(closeMenusDelay);
796 if (openMenusDelay == null){
797 openMenusDelay = window.setTimeout("SUGAR.subpanelUtils.menu.spShowMenu('"+id+"','"+top+"','"+left+"','"+leftOffset+"')", delayTime);
800 spShowMenu : function(id,top,left,leftOffset){ //*//
801 openMenusDelay = eraseTimeout(openMenusDelay);
802 var menuName = id.replace(/Handle/i,'Menu');
803 var menu = getLayer(menuName);
804 //if (menu) menu.className = 'tbButtonMouseOverUp';
808 SUGAR.subpanelUtils.menu.spPopupMenu(id, menu, top,left,leftOffset);
810 spPopupMenu : function(handleID, menu, top, left, leftOffset){ //*//
811 var bw = checkBrowserWidth();
812 var menuName = handleID.replace(/Handle/i,'Menu');
814 var imgWidth = document.getElementById(handleID).width;
816 var menuHandle = getLayer(handleID);
820 while(p&&p.tagName.toUpperCase()!='BODY'){
824 left+=parseInt(leftOffset);
830 while(p&&p.tagName.toUpperCase()!='BODY'){
835 if (left+menuWidth>bw) {
836 left = left-menuWidth+imgWidth;
838 setMenuVisible(menu, left, top, false);