1 /*********************************************************************************
2 * SugarCRM Community Edition is a customer relationship management program developed by
3 * SugarCRM, Inc. Copyright (C) 2004-2011 SugarCRM Inc.
5 * This program is free software; you can redistribute it and/or modify it under
6 * the terms of the GNU Affero General Public License version 3 as published by the
7 * Free Software Foundation with the addition of the following permission added
8 * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
9 * IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
10 * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
12 * This program is distributed in the hope that it will be useful, but WITHOUT
13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14 * FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
17 * You should have received a copy of the GNU Affero General Public License along with
18 * this program; if not, see http://www.gnu.org/licenses or write to the Free
19 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
22 * You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
23 * SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
25 * The interactive user interfaces in modified source and object code versions
26 * of this program must display Appropriate Legal Notices, as required under
27 * Section 5 of the GNU Affero General Public License version 3.
29 * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
30 * these Appropriate Legal Notices must retain the display of the "Powered by
31 * SugarCRM" logo. If the display of the logo is not reasonably feasible for
32 * technical reasons, the Appropriate Legal Notices must display the words
33 * "Powered by SugarCRM".
34 ********************************************************************************/
38 SUGAR.mySugar = function() {
39 var originalLayout = null;
40 var configureDashletId = null;
41 var currentDashlet = null;
42 var leftColumnInnerHTML = null;
43 var leftColObj = null;
47 var closeDashletsDialogTimer = null;
49 var activeTab = activePage;
50 var current_user = current_user_id;
52 var module = moduleName;
54 var charts = new Object();
56 if (module == 'Dashboard'){
57 cookiePageIndex = current_user + "_activeDashboardPage";
60 cookiePageIndex = current_user + "_activePage";
81 // get the current dashlet layout
82 getLayout: function(asString) {
83 columns = new Array();
84 for(je = 0; je < 3; je++) {
85 dashlets = document.getElementById('col_'+activeTab+'_'+ je);
87 if (dashlets != null){
88 dashletIds = new Array();
89 for(wp = 0; wp < dashlets.childNodes.length; wp++) {
90 if(typeof dashlets.childNodes[wp].id != 'undefined' && dashlets.childNodes[wp].id.match(/dashlet_[\w-]*/)) {
91 dashletIds.push(dashlets.childNodes[wp].id.replace(/dashlet_/,''));
95 columns[je] = dashletIds.join(',');
97 columns[je] = dashletIds;
101 if(asString) return columns.join('|');
105 // called when dashlet is picked up
106 onDrag: function(e, id) {
107 originalLayout = SUGAR.mySugar.getLayout(true);
110 // called when dashlet is dropped
111 onDrop: function(e, id) {
112 newLayout = SUGAR.mySugar.getLayout(true);
113 if(originalLayout != newLayout) { // only save if the layout has changed
114 SUGAR.mySugar.saveLayout(newLayout);
115 SUGAR.mySugar.sugarCharts.loadSugarCharts(); // called safely because there is a check to be sure the array exists
119 // save the layout of the dashlet
120 saveLayout: function(order) {
121 ajaxStatus.showStatus(SUGAR.language.get('app_strings', 'LBL_SAVING_LAYOUT'));
122 var success = function(data) {
123 ajaxStatus.showStatus(SUGAR.language.get('app_strings', 'LBL_SAVED_LAYOUT'));
124 window.setTimeout('ajaxStatus.hideStatus()', 2000);
127 url = 'index.php?to_pdf=1&module='+module+'&action=DynamicAction&DynamicAction=saveLayout&layout=' + order + '&selectedPage=' + activeTab;
128 var cObj = YAHOO.util.Connect.asyncRequest('GET', url, {success: success, failure: success});
132 uncoverPage: function(id) {
134 document.getElementById('dlg_c').style.display = 'none';
137 if ( document.getElementById('dashletType') == null ) {
140 dashletType = document.getElementById('dashletType').value;
142 SUGAR.mySugar.retrieveDashlet(SUGAR.mySugar.configureDashletId, dashletType);
145 // call to configure a Dashlet
146 configureDashlet: function(id) {
147 ajaxStatus.showStatus(SUGAR.language.get('app_strings', 'LBL_LOADING'));
148 configureDlg = new YAHOO.widget.SimpleDialog("dlg",
151 effect:[{effect:YAHOO.widget.ContainerEffect.SLIDE, duration:0.5},
152 {effect:YAHOO.widget.ContainerEffect.FADE,duration:0.5}],
158 fillInConfigureDiv = function(data){
159 ajaxStatus.hideStatus();
160 // uncomment the line below to debug w/ FireBug
161 // console.log(data.responseText);
163 eval(data.responseText);
166 result = new Array();
167 result['header'] = 'error';
168 result['body'] = 'There was an error handling this request.';
170 configureDlg.setHeader(result['header']);
171 configureDlg.setBody(result['body']);
172 var listeners = new YAHOO.util.KeyListener(document, { keys : 27 }, {fn: function() {this.hide();}, scope: configureDlg, correctScope:true} );
173 configureDlg.cfg.queueProperty("keylisteners", listeners);
175 configureDlg.render(document.body);
177 configureDlg.configFixedCenter(null, false) ;
178 SUGAR.util.evalScript(result['body']);
181 SUGAR.mySugar.configureDashletId = id; // save the id of the dashlet being configured
182 var cObj = YAHOO.util.Connect.asyncRequest('GET','index.php?to_pdf=1&module='+module+'&action=DynamicAction&DynamicAction=configureDashlet&id=' + id,
183 {success: fillInConfigureDiv, failure: fillInConfigureDiv}, null);
187 /** returns dashlets contents
188 * if url is defined, dashlet will be retrieve with it, otherwise use default url
190 * @param string id id of the dashlet to refresh
191 * @param string url url to be used
192 * @param function callback callback function after refresh
193 * @param bool dynamic does the script load dynamic javascript, set to true if you user needs to refresh the dashlet after load
195 retrieveDashlet: function(id, url, callback, dynamic) {
196 ajaxStatus.showStatus(SUGAR.language.get('app_strings', 'LBL_LOADING'));
199 url = 'index.php?action=DynamicAction&DynamicAction=displayDashlet&session_commit=1&module='+module+'&to_pdf=1&id=' + id;
200 is_chart_dashlet = false;
202 else if (url == 'predefined_chart'){
203 url = 'index.php?action=DynamicAction&DynamicAction=displayDashlet&session_commit=1&module='+module+'&to_pdf=1&id=' + id;
204 scriptUrl = 'index.php?action=DynamicAction&DynamicAction=getPredefinedChartScript&session_commit=1&module='+module+'&to_pdf=1&id=' + id;
205 is_chart_dashlet = true;
210 url += '&dynamic=true';
213 var fillInDashlet = function(data) {
215 ajaxStatus.hideStatus();
217 SUGAR.mySugar.currentDashlet.innerHTML = data.responseText;
220 SUGAR.util.evalScript(data.responseText);
221 if(callback) callback();
223 var processChartScript = function(scriptData){
224 SUGAR.util.evalScript(scriptData.responseText);
226 SUGAR.mySugar.sugarCharts.loadSugarCharts(activePage);
229 if(typeof(is_chart_dashlet)=='undefined'){
230 is_chart_dashlet = false;
232 if (is_chart_dashlet){
233 var chartScriptObj = YAHOO.util.Connect.asyncRequest('GET', scriptUrl,
234 {success: processChartScript, failure: processChartScript}, null);
238 SUGAR.mySugar.currentDashlet = document.getElementById('dashlet_entire_' + id);
239 var cObj = YAHOO.util.Connect.asyncRequest('GET', url,
240 {success: fillInDashlet, failure: fillInDashlet}, null);
244 // for the display columns widget
245 setChooser: function() {
246 var displayColumnsDef = new Array();
247 var hideTabsDef = new Array();
249 var left_td = document.getElementById('display_tabs_td');
250 var right_td = document.getElementById('hide_tabs_td');
252 var displayTabs = left_td.getElementsByTagName('select')[0];
253 var hideTabs = right_td.getElementsByTagName('select')[0];
255 for(i = 0; i < displayTabs.options.length; i++) {
256 displayColumnsDef.push(displayTabs.options[i].value);
259 if(typeof hideTabs != 'undefined') {
260 for(i = 0; i < hideTabs.options.length; i++) {
261 hideTabsDef.push(hideTabs.options[i].value);
265 document.getElementById('displayColumnsDef').value = displayColumnsDef.join('|');
266 document.getElementById('hideTabsDef').value = hideTabsDef.join('|');
269 deleteDashlet: function(id) {
270 if(confirm(SUGAR.language.get('app_strings', 'LBL_REMOVE_DASHLET_CONFIRM'))) {
271 ajaxStatus.showStatus(SUGAR.language.get('app_strings', 'LBL_REMOVING_DASHLET'));
274 var success = function(data) {
275 dashlet = document.getElementById('dashlet_' + id);
276 dashlet.parentNode.removeChild(dashlet);
277 ajaxStatus.showStatus(SUGAR.language.get('app_strings', 'LBL_REMOVED_DASHLET'));
278 window.setTimeout('ajaxStatus.hideStatus()', 2000);
282 var cObj = YAHOO.util.Connect.asyncRequest('GET','index.php?to_pdf=1&module='+module+'&action=DynamicAction&DynamicAction=deleteDashlet&activePage=' + activeTab + '&id=' + id,
283 {success: success, failure: success}, null);
286 var anim = new YAHOO.util.Anim('dashlet_entire_' + id, { height: {to: 1} }, .5 );
287 anim.onComplete.subscribe(del);
288 document.getElementById('dashlet_entire_' + id).style.overflow = 'hidden';
297 addDashlet: function(id, type, type_module) {
298 ajaxStatus.hideStatus();
299 columns = SUGAR.mySugar.getLayout();
301 var num_dashlets = columns[0].length;
302 if (typeof columns[1] == undefined){
303 num_dashlets = num_dashlets + columns[1].length;
306 if((num_dashlets) >= SUGAR.mySugar.maxCount) {
307 alert(SUGAR.language.get('app_strings', 'LBL_MAX_DASHLETS_REACHED'));
310 /* if((columns[0].length + columns[1].length) >= SUGAR.mySugar.maxCount) {
311 alert(SUGAR.language.get('Home', 'LBL_MAX_DASHLETS_REACHED'));
314 ajaxStatus.showStatus(SUGAR.language.get('app_strings', 'LBL_ADDING_DASHLET'));
315 var success = function(data) {
317 colZero = document.getElementById('col_'+activeTab+'_0');
318 newDashlet = document.createElement('li'); // build the list item
319 newDashlet.id = 'dashlet_' + data.responseText;
320 newDashlet.className = 'noBullet active';
321 // hide it first, but append to getRegion
322 newDashlet.innerHTML = '<div style="position: absolute; top: -1000px; overflow: hidden;" id="dashlet_entire_' + data.responseText + '"></div>';
324 colZero.insertBefore(newDashlet, colZero.firstChild); // insert it into the first column
326 var finishRetrieve = function() {
327 dashletEntire = document.getElementById('dashlet_entire_' + data.responseText);
328 dd = new ygDDList('dashlet_' + data.responseText); // make it draggable
329 dd.setHandleElId('dashlet_header_' + data.responseText);
330 dd.onMouseDown = SUGAR.mySugar.onDrag;
331 dd.onDragDrop = SUGAR.mySugar.onDrop;
333 ajaxStatus.showStatus(SUGAR.language.get('app_strings', 'LBL_ADDED_DASHLET'));
334 dashletRegion = YAHOO.util.Dom.getRegion(dashletEntire);
335 dashletEntire.style.position = 'relative';
336 dashletEntire.style.height = '1px';
337 dashletEntire.style.top = '0px';
338 dashletEntire.className = 'dashletPanel';
341 var anim = new YAHOO.util.Anim('dashlet_entire_' + data.responseText, { height: {to: dashletRegion.bottom - dashletRegion.top} }, .5 );
342 anim.onComplete.subscribe(function() { document.getElementById('dashlet_entire_' + data.responseText).style.height = '100%'; });
345 newLayout = SUGAR.mySugar.getLayout(true);
346 SUGAR.mySugar.saveLayout(newLayout);
347 // window.setTimeout('ajaxStatus.hideStatus()', 2000);
350 if (type == 'module' || type == 'web'){
354 else if (type == 'predefined_chart'){
355 url = 'predefined_chart';
356 type = 'predefined_chart';
358 else if (type == 'chart'){
363 SUGAR.mySugar.retrieveDashlet(data.responseText, url, finishRetrieve, true); // retrieve it from the server
366 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=' + escape(type_module),
367 {success: success, failure: success}, null);
372 showDashletsDialog: function() {
373 columns = SUGAR.mySugar.getLayout();
375 if (this.closeDashletsDialogTimer != null) {
376 window.clearTimeout(this.closeDashletsDialogTimer);
379 var num_dashlets = 0;
381 for ( i = 0 ; i < 3; i++ ) {
382 if (typeof columns[i] != "undefined") {
383 num_dashlets = num_dashlets + columns[i].length;
387 if((num_dashlets) >= SUGAR.mySugar.maxCount) {
388 alert(SUGAR.language.get('app_strings', 'LBL_MAX_DASHLETS_REACHED'));
391 ajaxStatus.showStatus(SUGAR.language.get('app_strings', 'LBL_LOADING'));
393 var success = function(data) {
394 eval(data.responseText);
395 dashletsListDiv = document.getElementById('dashletsList');
396 dashletsListDiv.innerHTML = response['html'];
398 document.getElementById('dashletsDialog_c').style.display = '';
399 SUGAR.mySugar.dashletsDialog.show();
401 eval(response['script']);
402 ajaxStatus.hideStatus();
405 var cObj = YAHOO.util.Connect.asyncRequest('GET', 'index.php?to_pdf=true&module='+module+'&action=DynamicAction&DynamicAction=dashletsDialog', {success: success, failure: success});
409 closeDashletsDialog: function(){
410 SUGAR.mySugar.dashletsDialog.hide();
411 if (this.closeDashletsDialogTimer != null) {
412 window.clearTimeout(this.closeDashletsDialogTimer);
414 this.closeDashletsDialogTimer = window.setTimeout("document.getElementById('dashletsDialog_c').style.display = 'none';", 2000);
417 toggleDashletCategories: function(category){
418 document.getElementById('search_string').value = '';
419 document.getElementById('searchResults').innerHTML = '';
421 var moduleTab = document.getElementById('moduleCategory');
422 var moduleTabAnchor = document.getElementById('moduleCategoryAnchor');
423 var moduleListDiv = document.getElementById('moduleDashlets');
425 var chartTab = document.getElementById('chartCategory');
426 var chartTabAnchor = document.getElementById('chartCategoryAnchor');
427 var chartListDiv = document.getElementById('chartDashlets');
429 var toolsTab = document.getElementById('toolsCategory');
430 var toolsTabAnchor = document.getElementById('toolsCategoryAnchor');
431 var toolsListDiv = document.getElementById('toolsDashlets');
433 var webTab = document.getElementById('webCategory');
434 var webTabAnchor = document.getElementById('webCategoryAnchor');
435 var webListDiv = document.getElementById('webDashlets');
439 moduleTab.className = 'active';
440 moduleTabAnchor.className = 'current';
441 moduleListDiv.style.display = '';
443 chartTab.className = '';
444 chartTabAnchor.className = '';
445 chartListDiv.style.display = 'none';
447 toolsTab.className = '';
448 toolsTabAnchor.className = '';
449 toolsListDiv.style.display = 'none';
451 webTab.className = '';
452 webTabAnchor.className = '';
453 webListDiv.style.display = 'none';
457 moduleTab.className = '';
458 moduleTabAnchor.className = '';
459 moduleListDiv.style.display = 'none';
461 chartTab.className = 'active';
462 chartTabAnchor.className = 'current';
463 chartListDiv.style.display = '';
465 toolsTab.className = '';
466 toolsTabAnchor.className = '';
467 toolsListDiv.style.display = 'none';
469 webTab.className = '';
470 webTabAnchor.className = '';
471 webListDiv.style.display = 'none';
475 moduleTab.className = '';
476 moduleTabAnchor.className = '';
477 moduleListDiv.style.display = 'none';
479 chartTab.className = '';
480 chartTabAnchor.className = '';
481 chartListDiv.style.display = 'none';
483 toolsTab.className = 'active';
484 toolsTabAnchor.className = 'current';
485 toolsListDiv.style.display = '';
487 webTab.className = '';
488 webTabAnchor.className = '';
489 webListDiv.style.display = 'none';
493 moduleTab.className = '';
494 moduleTabAnchor.className = '';
495 moduleListDiv.style.display = 'none';
497 chartTab.className = '';
498 chartTabAnchor.className = '';
499 chartListDiv.style.display = 'none';
501 toolsTab.className = '';
502 toolsTabAnchor.className = '';
503 toolsListDiv.style.display = 'none';
505 webTab.className = 'active';
506 webTabAnchor.className = 'current';
507 webListDiv.style.display = '';
514 document.getElementById('search_category').value = category;
518 searchDashlets: function(searchStr, searchCategory){
519 var moduleTab = document.getElementById('moduleCategory');
520 var moduleTabAnchor = document.getElementById('moduleCategoryAnchor');
521 var moduleListDiv = document.getElementById('moduleDashlets');
523 var chartTab = document.getElementById('chartCategory');
524 var chartTabAnchor = document.getElementById('chartCategoryAnchor');
525 var chartListDiv = document.getElementById('chartDashlets');
527 var toolsTab = document.getElementById('toolsCategory');
528 var toolsTabAnchor = document.getElementById('toolsCategoryAnchor');
529 var toolsListDiv = document.getElementById('toolsDashlets');
531 if (moduleTab != null && chartTab != null && toolsTab != null){
532 moduleListDiv.style.display = 'none';
533 chartListDiv.style.display = 'none';
534 toolsListDiv.style.display = 'none';
537 // dashboards case, where there are no tabs
539 chartListDiv.style.display = 'none';
542 var searchResultsDiv = document.getElementById('searchResults');
543 searchResultsDiv.style.display = '';
545 var success = function(data) {
546 eval(data.responseText);
548 searchResultsDiv.innerHTML = response['html'];
551 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});
555 collapseList: function(chartList){
556 document.getElementById(chartList+'List').style.display='none';
557 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" />';
560 expandList: function(chartList){
561 document.getElementById(chartList+'List').style.display='';
562 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" />';
565 collapseReportList: function(reportChartList){
566 document.getElementById(reportChartList+'ReportsChartDashletsList').style.display='none';
567 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" />';
570 expandReportList: function(reportChartList){
571 document.getElementById(reportChartList+'ReportsChartDashletsList').style.display='';
572 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" />';
575 clearSearch: function(){
576 document.getElementById('search_string').value = '';
578 var moduleTab = document.getElementById('moduleCategory');
579 var moduleTabAnchor = document.getElementById('moduleCategoryAnchor');
580 var moduleListDiv = document.getElementById('moduleDashlets');
582 document.getElementById('searchResults').innerHTML = '';
583 if (moduleTab != null){
584 SUGAR.mySugar.toggleDashletCategories('module');
587 document.getElementById('searchResults').style.display = 'none';
588 document.getElementById('chartDashlets').style.display = '';
592 doneAddDashlets: function() {
593 SUGAR.mySugar.dashletsDialog.hide();
600 renderDashletsDialog: function(){
601 SUGAR.mySugar.dashletsDialog = new YAHOO.widget.Dialog("dashletsDialog",
607 // effect:[{effect:YAHOO.widget.ContainerEffect.SLIDETOP, duration:0.5},{effect:YAHOO.widget.ContainerEffect.FADE,duration:0.5}],
612 var listeners = new YAHOO.util.KeyListener(document, { keys : 27 }, {fn: function() {SUGAR.mySugar.closeDashletsDialog();} } );
613 SUGAR.mySugar.dashletsDialog.cfg.queueProperty("keylisteners", listeners);
615 document.getElementById('dashletsDialog').style.display = '';
616 SUGAR.mySugar.dashletsDialog.render();
617 document.getElementById('dashletsDialog_c').style.display = 'none';