]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - jssource/src_files/include/MySugar/javascript/MySugar.js
Release 6.1.4
[Github/sugarcrm.git] / jssource / src_files / include / MySugar / javascript / MySugar.js
1 /*********************************************************************************
2  * SugarCRM is a customer relationship management program developed by
3  * SugarCRM, Inc. Copyright (C) 2004-2011 SugarCRM Inc.
4  * 
5  * This program is free software; you can redistribute it and/or modify it under
6  * the terms of the GNU Affero General Public License version 3 as published by the
7  * Free Software Foundation with the addition of the following permission added
8  * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
9  * IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
10  * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
11  * 
12  * This program is distributed in the hope that it will be useful, but WITHOUT
13  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14  * FOR A PARTICULAR PURPOSE.  See the GNU Affero General Public License for more
15  * details.
16  * 
17  * You should have received a copy of the GNU Affero General Public License along with
18  * this program; if not, see http://www.gnu.org/licenses or write to the Free
19  * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
20  * 02110-1301 USA.
21  * 
22  * You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
23  * SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
24  * 
25  * The interactive user interfaces in modified source and object code versions
26  * of this program must display Appropriate Legal Notices, as required under
27  * Section 5 of the GNU Affero General Public License version 3.
28  * 
29  * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
30  * these Appropriate Legal Notices must retain the display of the "Powered by
31  * SugarCRM" logo. If the display of the logo is not reasonably feasible for
32  * technical reasons, the Appropriate Legal Notices must display the words
33  * "Powered by SugarCRM".
34  ********************************************************************************/
35
36
37
38 SUGAR.mySugar = function() {
39         var originalLayout = null;
40         var configureDashletId = null;
41         var currentDashlet = null;
42         var leftColumnInnerHTML = null;
43         var leftColObj = null;
44         var maxCount;
45         var warningLang;
46         
47         var activeTab = activePage;
48         var current_user = current_user_id;
49         
50         var module = moduleName;
51         
52         var charts = new Object();
53         
54         if (module == 'Dashboard'){
55                 cookiePageIndex = current_user + "_activeDashboardPage";
56         }
57         else{
58                 cookiePageIndex = current_user + "_activePage";
59         }
60         
61         var homepage_dd;
62         
63
64         return {
65                 
66
67                 
68                 
69
70                 
71                 
72                 clearChartsArray: function(){
73                         charts[activeTab] = new Object();
74                 },
75                 
76                 addToChartsArray: function(name, xmlFile, width, height, styleSheet, colorScheme, langFile){
77
78                         if (charts[activeTab] == null){
79                                 charts[activeTab] = new Object();
80                         }
81                         charts[activeTab][name] = new Object();
82                         charts[activeTab][name]['name'] = name;
83                         charts[activeTab][name]['xmlFile'] = xmlFile;
84                         charts[activeTab][name]['width'] = width;
85                         charts[activeTab][name]['height'] = height;
86                         charts[activeTab][name]['styleSheet'] = styleSheet;
87                         charts[activeTab][name]['colorScheme'] = colorScheme;   
88                         charts[activeTab][name]['langFile'] = langFile;                         
89                 },
90
91                 loadSugarChart: function(name, xmlFile, width, height, styleSheet, colorScheme, langFile){
92                         loadChartSWF(name, xmlFile, width, height, styleSheet, colorScheme, langFile);
93                 },
94                 
95                 loadSugarCharts: function(){
96                         for (id in charts[activeTab]){
97                                 if(id != 'undefined'){
98                                         SUGAR.mySugar.loadSugarChart(charts[activeTab][id]['name'], 
99                                                                                          charts[activeTab][id]['xmlFile'], 
100                                                                                          charts[activeTab][id]['width'], 
101                                                                                          charts[activeTab][id]['height'],
102                                                                                          charts[activeTab][id]['styleSheet'],
103                                                                                          charts[activeTab][id]['colorScheme'],
104                                                                                          charts[activeTab][id]['langFile']);
105                                 }
106                         }
107                 },
108
109         
110         
111                 
112                 
113                                 
114                 
115                 // get the current dashlet layout
116                 getLayout: function(asString) {
117                         columns = new Array();
118                         for(je = 0; je < 3; je++) {
119                             dashlets = document.getElementById('col_'+activeTab+'_'+ je);
120                                             
121                                 if (dashlets != null){
122                                     dashletIds = new Array();
123                                     for(wp = 0; wp < dashlets.childNodes.length; wp++) {
124                                       if(typeof dashlets.childNodes[wp].id != 'undefined' && dashlets.childNodes[wp].id.match(/dashlet_[\w-]*/)) {
125                                                 dashletIds.push(dashlets.childNodes[wp].id.replace(/dashlet_/,''));
126                                       }
127                                     }
128                                         if(asString) 
129                                                 columns[je] = dashletIds.join(',');
130                                         else 
131                                                 columns[je] = dashletIds;
132                                 }
133                         }
134
135                         if(asString) return columns.join('|');
136                         else return columns;
137                 },
138
139                 // called when dashlet is picked up
140                 onDrag: function(e, id) {
141                         originalLayout = SUGAR.mySugar.getLayout(true);         
142                 },
143                 
144                 // called when dashlet is dropped
145                 onDrop: function(e, id) {       
146                         newLayout = SUGAR.mySugar.getLayout(true);
147                         if(originalLayout != newLayout) { // only save if the layout has changed
148                                 SUGAR.mySugar.saveLayout(newLayout);
149                                 SUGAR.mySugar.loadSugarCharts(); // called safely because there is a check to be sure the array exists
150                         }
151                 },
152                 
153                 // save the layout of the dashlet  
154                 saveLayout: function(order) {
155                         ajaxStatus.showStatus(SUGAR.language.get('app_strings', 'LBL_SAVING_LAYOUT'));
156                         var success = function(data) {
157                                 ajaxStatus.showStatus(SUGAR.language.get('app_strings', 'LBL_SAVED_LAYOUT'));
158                                 window.setTimeout('ajaxStatus.hideStatus()', 2000);
159                         }
160                         
161                         url = 'index.php?to_pdf=1&module='+module+'&action=DynamicAction&DynamicAction=saveLayout&layout=' + order + '&selectedPage=' + activeTab;
162                         var cObj = YAHOO.util.Connect.asyncRequest('GET', url, {success: success, failure: success});                                     
163                 },
164
165
166                 uncoverPage: function(id) {
167                         if (!SUGAR.isIE){       
168                                 document.getElementById('dlg_c').style.display = 'none';        
169                         }               
170                         configureDlg.hide();
171             if ( document.getElementById('dashletType') == null ) {
172                 dashletType = '';
173             } else {
174                 dashletType = document.getElementById('dashletType').value;
175             }
176                         SUGAR.mySugar.retrieveDashlet(SUGAR.mySugar.configureDashletId, dashletType);
177                 },
178                 
179                 // call to configure a Dashlet
180                 configureDashlet: function(id) {
181                         ajaxStatus.showStatus(SUGAR.language.get('app_strings', 'LBL_LOADING'));
182                         configureDlg = new YAHOO.widget.SimpleDialog("dlg", 
183                                 { visible:false, 
184                                   width:"510", 
185                                   effect:[{effect:YAHOO.widget.ContainerEffect.SLIDE, duration:0.5},
186                                                   {effect:YAHOO.widget.ContainerEffect.FADE,duration:0.5}], 
187                                   fixedcenter:true, 
188                                   modal:true, 
189                                   draggable:false }
190                         );
191                         
192                         fillInConfigureDiv = function(data){
193                                 ajaxStatus.hideStatus();
194                                 // uncomment the line below to debug w/ FireBug
195                                 // console.log(data.responseText); 
196                                 try {
197                                         eval(data.responseText);
198                                 }
199                                 catch(e) {
200                                         result = new Array();
201                                         result['header'] = 'error';
202                                         result['body'] = 'There was an error handling this request.';
203                                 }
204                                 configureDlg.setHeader(result['header']);
205                                 configureDlg.setBody(result['body']);
206                                 var listeners = new YAHOO.util.KeyListener(document, { keys : 27 }, {fn: function() {this.hide();}, scope: configureDlg, correctScope:true} );
207                                 configureDlg.cfg.queueProperty("keylisteners", listeners);
208
209                                 configureDlg.render(document.body);
210                                 configureDlg.show();
211                                 configureDlg.configFixedCenter(null, false) ;
212                                 SUGAR.util.evalScript(result['body']);
213                         }
214
215                         SUGAR.mySugar.configureDashletId = id; // save the id of the dashlet being configured
216                         var cObj = YAHOO.util.Connect.asyncRequest('GET','index.php?to_pdf=1&module='+module+'&action=DynamicAction&DynamicAction=configureDashlet&id=' + id, 
217                                                                                                           {success: fillInConfigureDiv, failure: fillInConfigureDiv}, null);
218                 },
219                 
220                                 
221                 /** returns dashlets contents
222                  * if url is defined, dashlet will be retrieve with it, otherwise use default url
223                  *
224                  * @param string id id of the dashlet to refresh
225                  * @param string url url to be used
226                  * @param function callback callback function after refresh
227                  * @param bool dynamic does the script load dynamic javascript, set to true if you user needs to refresh the dashlet after load
228                  */
229                 retrieveDashlet: function(id, url, callback, dynamic) {
230                         ajaxStatus.showStatus(SUGAR.language.get('app_strings', 'LBL_LOADING'));
231                                         
232                         if(!url) {
233                                 url = 'index.php?action=DynamicAction&DynamicAction=displayDashlet&session_commit=1&module='+module+'&to_pdf=1&id=' + id;
234                                 is_chart_dashlet = false;
235                         }
236                         else if (url == 'predefined_chart'){
237                                 url = 'index.php?action=DynamicAction&DynamicAction=displayDashlet&session_commit=1&module='+module+'&to_pdf=1&id=' + id;
238                                 scriptUrl = 'index.php?action=DynamicAction&DynamicAction=getPredefinedChartScript&session_commit=1&module='+module+'&to_pdf=1&id=' + id;
239                                 is_chart_dashlet = true;
240                         }
241                         
242                         
243                         if(dynamic) {
244                                 url += '&dynamic=true';
245                         }
246
247                         var fillInDashlet = function(data) {
248
249                                 ajaxStatus.hideStatus();
250                                 if(data) {              
251                                         SUGAR.mySugar.currentDashlet.innerHTML = data.responseText;                             
252                                 }
253
254                                 SUGAR.util.evalScript(data.responseText);
255                                 if(callback) callback();
256                                 
257                                 var processChartScript = function(scriptData){
258                                         SUGAR.util.evalScript(scriptData.responseText);
259
260                                         SUGAR.mySugar.loadSugarChart(charts[activeTab][id]['name'], 
261                                                                                                  charts[activeTab][id]['xmlFile'], 
262                                                                                                  charts[activeTab][id]['width'], 
263                                                                                                  charts[activeTab][id]['height'],
264                                                                                                  charts[activeTab][id]['styleSheet'],
265                                                                                                  charts[activeTab][id]['colorScheme'],
266                                                                                                  charts[activeTab][id]['langFile']);
267                                 }
268                                 if(typeof(is_chart_dashlet)=='undefined'){
269                                         is_chart_dashlet = false;
270                                 }
271                                 if (is_chart_dashlet){                          
272                                         var chartScriptObj = YAHOO.util.Connect.asyncRequest('GET', scriptUrl,
273                                                                                                           {success: processChartScript, failure: processChartScript}, null);
274                                 }
275                         }
276                         
277                         SUGAR.mySugar.currentDashlet = document.getElementById('dashlet_entire_' + id);
278                         var cObj = YAHOO.util.Connect.asyncRequest('GET', url,
279                                                                                                   {success: fillInDashlet, failure: fillInDashlet}, null);
280                         return false;
281                 },
282                 
283                 // for the display columns widget
284                 setChooser: function() {                
285                         var displayColumnsDef = new Array();
286                         var hideTabsDef = new Array();
287
288                     var left_td = document.getElementById('display_tabs_td');   
289                     var right_td = document.getElementById('hide_tabs_td');                     
290         
291                     var displayTabs = left_td.getElementsByTagName('select')[0];
292                     var hideTabs = right_td.getElementsByTagName('select')[0];
293                         
294                         for(i = 0; i < displayTabs.options.length; i++) {
295                                 displayColumnsDef.push(displayTabs.options[i].value);
296                         }
297                         
298                         if(typeof hideTabs != 'undefined') {
299                                 for(i = 0; i < hideTabs.options.length; i++) {
300                                  hideTabsDef.push(hideTabs.options[i].value);
301                                 }
302                         }
303                         
304                         document.getElementById('displayColumnsDef').value = displayColumnsDef.join('|');
305                         document.getElementById('hideTabsDef').value = hideTabsDef.join('|');
306                 },
307                 
308                 deleteDashlet: function(id) {
309                         if(confirm(SUGAR.language.get('app_strings', 'LBL_REMOVE_DASHLET_CONFIRM'))) {
310                                 ajaxStatus.showStatus(SUGAR.language.get('app_strings', 'LBL_REMOVING_DASHLET'));
311                                 
312                                 del = function() {
313                                         var success = function(data) {
314                                                 dashlet = document.getElementById('dashlet_' + id);
315                                                 dashlet.parentNode.removeChild(dashlet);
316                                                 ajaxStatus.showStatus(SUGAR.language.get('app_strings', 'LBL_REMOVED_DASHLET'));
317                                                 window.setTimeout('ajaxStatus.hideStatus()', 2000);
318                                         }
319                                 
320                                         
321                                         var cObj = YAHOO.util.Connect.asyncRequest('GET','index.php?to_pdf=1&module='+module+'&action=DynamicAction&DynamicAction=deleteDashlet&activePage=' + activeTab + '&id=' + id, 
322                                                                                                                           {success: success, failure: success}, null);
323                                 }
324                                 
325                                 var anim = new YAHOO.util.Anim('dashlet_entire_' + id, { height: {to: 1} }, .5 );                                       
326                                 anim.onComplete.subscribe(del);                                 
327                                 document.getElementById('dashlet_entire_' + id).style.overflow = 'hidden';
328                                 anim.animate();
329                                 
330                                 return false;
331                         }
332                         return false;
333                 },
334                 
335                 
336                 addDashlet: function(id, type, type_module) {
337                         ajaxStatus.hideStatus();
338                         columns = SUGAR.mySugar.getLayout();
339                                                 
340                         var num_dashlets = columns[0].length;
341                         if (typeof columns[1] == undefined){
342                                 num_dashlets = num_dashlets + columns[1].length;
343                         }
344                         
345                         if((num_dashlets) >= SUGAR.mySugar.maxCount) {
346                                 alert(SUGAR.language.get('app_strings', 'LBL_MAX_DASHLETS_REACHED'));
347                                 return;
348                         }                       
349 /*                      if((columns[0].length + columns[1].length) >= SUGAR.mySugar.maxCount) {
350                                 alert(SUGAR.language.get('Home', 'LBL_MAX_DASHLETS_REACHED'));
351                                 return;
352                         }*/
353                         ajaxStatus.showStatus(SUGAR.language.get('app_strings', 'LBL_ADDING_DASHLET'));
354                         var success = function(data) {
355
356                         //check to see if a user preference error occurred
357                         if(data.responseText == 'userpref_error'){
358                                 //user preference error occured, close the dashlet dialog, flash the error message and exit processing
359                                 SUGAR.mySugar.closeDashletsDialog();
360                                 ajaxStatus.flashStatus(SUGAR.language.get('app_strings', 'ERROR_USER_PREFS_DASH'),7000);
361                                 return;
362                         }
363                                 colZero = document.getElementById('col_'+activeTab+'_0');
364                                 newDashlet = document.createElement('li'); // build the list item
365                                 newDashlet.id = 'dashlet_' + data.responseText;
366                                 newDashlet.className = 'noBullet active';
367                                 // hide it first, but append to getRegion
368                                 newDashlet.innerHTML = '<div style="position: absolute; top: -1000px; overflow: hidden;" id="dashlet_entire_' + data.responseText + '"></div>';
369
370                                 colZero.insertBefore(newDashlet, colZero.firstChild); // insert it into the first column
371                                 
372                                 var finishRetrieve = function() {
373                                         dashletEntire = document.getElementById('dashlet_entire_' + data.responseText);
374                                         dd = new ygDDList('dashlet_' + data.responseText); // make it draggable
375                                         dd.setHandleElId('dashlet_header_' + data.responseText);
376                                         dd.onMouseDown = SUGAR.mySugar.onDrag;  
377                                         dd.onDragDrop = SUGAR.mySugar.onDrop;
378
379                                         ajaxStatus.showStatus(SUGAR.language.get('app_strings', 'LBL_ADDED_DASHLET'));
380                                         dashletRegion = YAHOO.util.Dom.getRegion(dashletEntire);
381                                         dashletEntire.style.position = 'relative';
382                                         dashletEntire.style.height = '1px';
383                                         dashletEntire.style.top = '0px';
384                                         dashletEntire.className = 'dashletPanel';
385                                         
386                                         
387                                         var anim = new YAHOO.util.Anim('dashlet_entire_' + data.responseText, { height: {to: dashletRegion.bottom - dashletRegion.top} }, .5 );
388                                         anim.onComplete.subscribe(function() { document.getElementById('dashlet_entire_' + data.responseText).style.height = '100%'; });        
389                                         anim.animate();
390                                         
391                                         newLayout =     SUGAR.mySugar.getLayout(true);
392                                         SUGAR.mySugar.saveLayout(newLayout);    
393 //                                      window.setTimeout('ajaxStatus.hideStatus()', 2000);
394                                 }
395                                 
396                                 if (type == 'module' || type == 'web'){
397                                         url = null;
398                                         type = 'module';
399                                 }
400                                 else if (type == 'predefined_chart'){
401                                         url = 'predefined_chart';
402                                         type = 'predefined_chart';
403                                 }
404                                 else if (type == 'chart'){
405                                         url = 'chart';
406                                         type = 'chart';
407                                 }
408                                 
409                                 SUGAR.mySugar.retrieveDashlet(data.responseText, url, finishRetrieve, true); // retrieve it from the server
410                         }
411                         var cObj = YAHOO.util.Connect.asyncRequest('GET','index.php?to_pdf=1&module='+module+'&action=DynamicAction&DynamicAction=addDashlet&activeTab=' + activeTab + '&id=' + id+'&type=' + type + '&type_module=' + type_module, 
412                                                                                                           {success: success, failure: success}, null);                                            
413
414                         return false;
415                 },
416                 
417                 showDashletsDialog: function() {                                             
418                         columns = SUGAR.mySugar.getLayout();
419                         
420                         var num_dashlets = 0;
421             var i = 0;
422             for ( i = 0 ; i < 3; i++ ) {
423                 if (typeof columns[i] != "undefined") {
424                     num_dashlets = num_dashlets + columns[i].length;
425                 }
426             }
427                         
428                         if((num_dashlets) >= SUGAR.mySugar.maxCount) {
429                                 alert(SUGAR.language.get('app_strings', 'LBL_MAX_DASHLETS_REACHED'));
430                                 return;
431                         }
432                         ajaxStatus.showStatus(SUGAR.language.get('app_strings', 'LBL_LOADING'));
433                         
434                         var success = function(data) {          
435                                 eval(data.responseText);
436                                 dashletsListDiv = document.getElementById('dashletsList');
437                                 dashletsListDiv.innerHTML = response['html'];
438                                 
439                                 document.getElementById('dashletsDialog_c').style.display = '';
440                                 SUGAR.mySugar.dashletsDialog.show();
441
442                                 eval(response['script']);
443                                 ajaxStatus.hideStatus();
444                         }
445                         
446                         var cObj = YAHOO.util.Connect.asyncRequest('GET', 'index.php?to_pdf=true&module='+module+'&action=DynamicAction&DynamicAction=dashletsDialog', {success: success, failure: success});                   
447                         return false;
448                 },
449                 
450                 closeDashletsDialog: function(){
451                         SUGAR.mySugar.dashletsDialog.hide();
452                         window.setTimeout("document.getElementById('dashletsDialog_c').style.display = 'none';", 2000);
453                 },
454
455                 toggleDashletCategories: function(category){
456                         document.getElementById('search_string').value = '';
457                         document.getElementById('searchResults').innerHTML = '';
458                         
459                         var moduleTab = document.getElementById('moduleCategory');
460                         var moduleTabAnchor = document.getElementById('moduleCategoryAnchor');
461                         var moduleListDiv = document.getElementById('moduleDashlets');
462
463                         var chartTab = document.getElementById('chartCategory');
464                         var chartTabAnchor = document.getElementById('chartCategoryAnchor');                    
465                         var chartListDiv = document.getElementById('chartDashlets');                    
466                         
467                         var toolsTab = document.getElementById('toolsCategory');
468                         var toolsTabAnchor = document.getElementById('toolsCategoryAnchor');                    
469                         var toolsListDiv = document.getElementById('toolsDashlets');    
470                         
471                         var webTab = document.getElementById('webCategory');
472                         var webTabAnchor = document.getElementById('webCategoryAnchor');                        
473                         var webListDiv = document.getElementById('webDashlets');        
474                         
475                         switch(category){
476                                 case 'module':
477                                         moduleTab.className = 'active';
478                                         moduleTabAnchor.className = 'current';
479                                         moduleListDiv.style.display = '';
480                                         
481                                         chartTab.className = '';
482                                         chartTabAnchor.className = '';
483                                         chartListDiv.style.display = 'none';
484
485                                         toolsTab.className = '';
486                                         toolsTabAnchor.className = '';
487                                         toolsListDiv.style.display = 'none';
488
489                                         webTab.className = '';
490                                         webTabAnchor.className = '';
491                                         webListDiv.style.display = 'none';
492                                                                         
493                                         break;
494                                 case 'chart':
495                                         moduleTab.className = '';
496                                         moduleTabAnchor.className = '';
497                                         moduleListDiv.style.display = 'none';
498                                         
499                                         chartTab.className = 'active';
500                                         chartTabAnchor.className = 'current';
501                                         chartListDiv.style.display = '';                                        
502
503                                         toolsTab.className = '';
504                                         toolsTabAnchor.className = '';
505                                         toolsListDiv.style.display = 'none';
506
507                                         webTab.className = '';
508                                         webTabAnchor.className = '';
509                                         webListDiv.style.display = 'none';
510                                         
511                                         break;
512                                 case 'tools':
513                                         moduleTab.className = '';
514                                         moduleTabAnchor.className = '';
515                                         moduleListDiv.style.display = 'none';
516                                         
517                                         chartTab.className = '';
518                                         chartTabAnchor.className = '';
519                                         chartListDiv.style.display = 'none';                                    
520
521                                         toolsTab.className = 'active';
522                                         toolsTabAnchor.className = 'current';
523                                         toolsListDiv.style.display = '';
524
525                                         webTab.className = '';
526                                         webTabAnchor.className = '';
527                                         webListDiv.style.display = 'none';
528                                         
529                                         break;
530                 case 'web':
531                                         moduleTab.className = '';
532                                         moduleTabAnchor.className = '';
533                                         moduleListDiv.style.display = 'none';
534                                         
535                                         chartTab.className = '';
536                                         chartTabAnchor.className = '';
537                                         chartListDiv.style.display = 'none';                                    
538
539                                         toolsTab.className = '';
540                                         toolsTabAnchor.className = '';
541                                         toolsListDiv.style.display = 'none';
542
543                                         webTab.className = 'active';
544                                         webTabAnchor.className = 'current';
545                                         webListDiv.style.display = '';                                  
546                                         
547                                         break;
548                                 default:
549                                         break;                                  
550                         }                       
551                         
552                         document.getElementById('search_category').value = category;
553                 },
554                 
555
556                 searchDashlets: function(searchStr, searchCategory){
557                         var moduleTab = document.getElementById('moduleCategory');
558                         var moduleTabAnchor = document.getElementById('moduleCategoryAnchor');
559                         var moduleListDiv = document.getElementById('moduleDashlets');
560
561                         var chartTab = document.getElementById('chartCategory');
562                         var chartTabAnchor = document.getElementById('chartCategoryAnchor');                    
563                         var chartListDiv = document.getElementById('chartDashlets');                    
564                         
565                         var toolsTab = document.getElementById('toolsCategory');
566                         var toolsTabAnchor = document.getElementById('toolsCategoryAnchor');                    
567                         var toolsListDiv = document.getElementById('toolsDashlets');                    
568
569                         if (moduleTab != null && chartTab != null && toolsTab != null){ 
570                                 moduleListDiv.style.display = 'none';
571                                 chartListDiv.style.display = 'none';    
572                                 toolsListDiv.style.display = 'none';
573                         
574                         }
575                         // dashboards case, where there are no tabs
576                         else{
577                                 chartListDiv.style.display = 'none';
578                         }
579                         
580                         var searchResultsDiv = document.getElementById('searchResults');
581                         searchResultsDiv.style.display = '';
582         
583                         var success = function(data) {
584                                 eval(data.responseText);
585
586                                 searchResultsDiv.innerHTML = response['html'];
587                         }
588                         
589                         var cObj = YAHOO.util.Connect.asyncRequest('GET', 'index.php?to_pdf=true&module='+module+'&action=DynamicAction&DynamicAction=searchDashlets&search='+searchStr+'&category='+searchCategory, {success: success, failure: success});
590                         return false;
591                 },
592                 
593                 collapseList: function(chartList){
594                         document.getElementById(chartList+'List').style.display='none';
595                         document.getElementById(chartList+'ExpCol').innerHTML = '<a href="#" onClick="javascript:SUGAR.mySugar.expandList(\''+chartList+'\');"><img border="0" src="' + SUGAR.themes.image_server + 'index.php?entryPoint=getImage&themeName='+SUGAR.themes.theme_name+'&imageName=advanced_search.gif" align="absmiddle" />';
596                 },
597                 
598                 expandList: function(chartList){
599                         document.getElementById(chartList+'List').style.display='';             
600                         document.getElementById(chartList+'ExpCol').innerHTML = '<a href="#" onClick="javascript:SUGAR.mySugar.collapseList(\''+chartList+'\');"><img border="0" src="' + SUGAR.themes.image_server + 'index.php?entryPoint=getImage&themeName='+SUGAR.themes.theme_name+'&imageName=basic_search.gif" align="absmiddle" />';                   
601                 },
602                 
603                 collapseReportList: function(reportChartList){
604                         document.getElementById(reportChartList+'ReportsChartDashletsList').style.display='none';
605                         document.getElementById(reportChartList+'ExpCol').innerHTML = '<a href="#" onClick="javascript:SUGAR.mySugar.expandReportList(\''+reportChartList+'\');"><img border="0" src="' + SUGAR.themes.image_server + 'index.php?entryPoint=getImage&themeName='+SUGAR.themes.theme_name+'&imageName=ProjectPlus.gif" align="absmiddle" />';
606                 },
607                 
608                 expandReportList: function(reportChartList){
609                         document.getElementById(reportChartList+'ReportsChartDashletsList').style.display='';
610                         document.getElementById(reportChartList+'ExpCol').innerHTML = '<a href="#" onClick="javascript:SUGAR.mySugar.collapseReportList(\''+reportChartList+'\');"><img border="0" src="' + SUGAR.themes.image_server + 'index.php?entryPoint=getImage&themeName='+SUGAR.themes.theme_name+'&imageName=ProjectMinus.gif" align="absmiddle" />';
611                 },
612                 
613                 clearSearch: function(){
614                         document.getElementById('search_string').value = '';
615
616                         var moduleTab = document.getElementById('moduleCategory');
617                         var moduleTabAnchor = document.getElementById('moduleCategoryAnchor');
618                         var moduleListDiv = document.getElementById('moduleDashlets');
619                         
620                         document.getElementById('searchResults').innerHTML = '';
621                         if (moduleTab != null){
622                                 SUGAR.mySugar.toggleDashletCategories('module');
623                         }
624                         else{
625                                 document.getElementById('searchResults').style.display = 'none';
626                                 document.getElementById('chartDashlets').style.display = '';
627                         }
628                 },
629                 
630                 doneAddDashlets: function() {
631                         SUGAR.mySugar.dashletsDialog.hide();
632                         return false;
633                 },
634
635                 
636                 
637                 
638                 renderDashletsDialog: function(){       
639                         SUGAR.mySugar.dashletsDialog = new YAHOO.widget.Dialog("dashletsDialog", 
640                         { width : "480px",
641                           height: "520px",
642                           fixedcenter : true,
643                           draggable:false,
644                           visible : false, 
645                          // effect:[{effect:YAHOO.widget.ContainerEffect.SLIDETOP, duration:0.5},{effect:YAHOO.widget.ContainerEffect.FADE,duration:0.5}],
646                           modal : true,
647                           close:false
648                          } );
649
650                         var listeners = new YAHOO.util.KeyListener(document, { keys : 27 }, {fn: function() {SUGAR.mySugar.closeDashletsDialog();} } );
651                         SUGAR.mySugar.dashletsDialog.cfg.queueProperty("keylisteners", listeners);
652
653                         document.getElementById('dashletsDialog').style.display = '';                                                                                                                                                            
654                         SUGAR.mySugar.dashletsDialog.render();
655                         document.getElementById('dashletsDialog_c').style.display = 'none';                     
656                 }       
657          }; 
658 }();