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