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