1 /*********************************************************************************
2 * SugarCRM 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 activeTab = activePage;
48 var current_user = current_user_id;
50 var module = moduleName;
52 var charts = new Object();
54 if (module == 'Dashboard'){
55 cookiePageIndex = current_user + "_activeDashboardPage";
58 cookiePageIndex = current_user + "_activePage";
72 clearChartsArray: function(){
73 charts[activeTab] = new Object();
76 addToChartsArray: function(name, xmlFile, width, height, styleSheet, colorScheme, langFile){
78 if (charts[activeTab] == null){
79 charts[activeTab] = new Object();
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;
91 loadSugarChart: function(name, xmlFile, width, height, styleSheet, colorScheme, langFile){
92 loadChartSWF(name, xmlFile, width, height, styleSheet, colorScheme, langFile);
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']);
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);
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_/,''));
129 columns[je] = dashletIds.join(',');
131 columns[je] = dashletIds;
135 if(asString) return columns.join('|');
139 // called when dashlet is picked up
140 onDrag: function(e, id) {
141 originalLayout = SUGAR.mySugar.getLayout(true);
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
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);
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});
166 uncoverPage: function(id) {
168 document.getElementById('dlg_c').style.display = 'none';
171 if ( document.getElementById('dashletType') == null ) {
174 dashletType = document.getElementById('dashletType').value;
176 SUGAR.mySugar.retrieveDashlet(SUGAR.mySugar.configureDashletId, dashletType);
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",
185 effect:[{effect:YAHOO.widget.ContainerEffect.SLIDE, duration:0.5},
186 {effect:YAHOO.widget.ContainerEffect.FADE,duration:0.5}],
192 fillInConfigureDiv = function(data){
193 ajaxStatus.hideStatus();
194 // uncomment the line below to debug w/ FireBug
195 // console.log(data.responseText);
197 eval(data.responseText);
200 result = new Array();
201 result['header'] = 'error';
202 result['body'] = 'There was an error handling this request.';
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);
209 configureDlg.render(document.body);
211 configureDlg.configFixedCenter(null, false) ;
212 SUGAR.util.evalScript(result['body']);
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);
221 /** returns dashlets contents
222 * if url is defined, dashlet will be retrieve with it, otherwise use default url
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
229 retrieveDashlet: function(id, url, callback, dynamic) {
230 ajaxStatus.showStatus(SUGAR.language.get('app_strings', 'LBL_LOADING'));
233 url = 'index.php?action=DynamicAction&DynamicAction=displayDashlet&session_commit=1&module='+module+'&to_pdf=1&id=' + id;
234 is_chart_dashlet = false;
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;
244 url += '&dynamic=true';
247 var fillInDashlet = function(data) {
249 ajaxStatus.hideStatus();
251 SUGAR.mySugar.currentDashlet.innerHTML = data.responseText;
254 SUGAR.util.evalScript(data.responseText);
255 if(callback) callback();
257 var processChartScript = function(scriptData){
258 SUGAR.util.evalScript(scriptData.responseText);
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']);
268 if(typeof(is_chart_dashlet)=='undefined'){
269 is_chart_dashlet = false;
271 if (is_chart_dashlet){
272 var chartScriptObj = YAHOO.util.Connect.asyncRequest('GET', scriptUrl,
273 {success: processChartScript, failure: processChartScript}, null);
277 SUGAR.mySugar.currentDashlet = document.getElementById('dashlet_entire_' + id);
278 var cObj = YAHOO.util.Connect.asyncRequest('GET', url,
279 {success: fillInDashlet, failure: fillInDashlet}, null);
283 // for the display columns widget
284 setChooser: function() {
285 var displayColumnsDef = new Array();
286 var hideTabsDef = new Array();
288 var left_td = document.getElementById('display_tabs_td');
289 var right_td = document.getElementById('hide_tabs_td');
291 var displayTabs = left_td.getElementsByTagName('select')[0];
292 var hideTabs = right_td.getElementsByTagName('select')[0];
294 for(i = 0; i < displayTabs.options.length; i++) {
295 displayColumnsDef.push(displayTabs.options[i].value);
298 if(typeof hideTabs != 'undefined') {
299 for(i = 0; i < hideTabs.options.length; i++) {
300 hideTabsDef.push(hideTabs.options[i].value);
304 document.getElementById('displayColumnsDef').value = displayColumnsDef.join('|');
305 document.getElementById('hideTabsDef').value = hideTabsDef.join('|');
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'));
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);
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);
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';
336 addDashlet: function(id, type, type_module) {
337 ajaxStatus.hideStatus();
338 columns = SUGAR.mySugar.getLayout();
340 var num_dashlets = columns[0].length;
341 if (typeof columns[1] == undefined){
342 num_dashlets = num_dashlets + columns[1].length;
345 if((num_dashlets) >= SUGAR.mySugar.maxCount) {
346 alert(SUGAR.language.get('app_strings', 'LBL_MAX_DASHLETS_REACHED'));
349 /* if((columns[0].length + columns[1].length) >= SUGAR.mySugar.maxCount) {
350 alert(SUGAR.language.get('Home', 'LBL_MAX_DASHLETS_REACHED'));
353 ajaxStatus.showStatus(SUGAR.language.get('app_strings', 'LBL_ADDING_DASHLET'));
354 var success = function(data) {
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);
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>';
370 colZero.insertBefore(newDashlet, colZero.firstChild); // insert it into the first column
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;
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';
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%'; });
391 newLayout = SUGAR.mySugar.getLayout(true);
392 SUGAR.mySugar.saveLayout(newLayout);
393 // window.setTimeout('ajaxStatus.hideStatus()', 2000);
396 if (type == 'module' || type == 'web'){
400 else if (type == 'predefined_chart'){
401 url = 'predefined_chart';
402 type = 'predefined_chart';
404 else if (type == 'chart'){
409 SUGAR.mySugar.retrieveDashlet(data.responseText, url, finishRetrieve, true); // retrieve it from the server
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);
417 showDashletsDialog: function() {
418 columns = SUGAR.mySugar.getLayout();
420 var num_dashlets = 0;
422 for ( i = 0 ; i < 3; i++ ) {
423 if (typeof columns[i] != "undefined") {
424 num_dashlets = num_dashlets + columns[i].length;
428 if((num_dashlets) >= SUGAR.mySugar.maxCount) {
429 alert(SUGAR.language.get('app_strings', 'LBL_MAX_DASHLETS_REACHED'));
432 ajaxStatus.showStatus(SUGAR.language.get('app_strings', 'LBL_LOADING'));
434 var success = function(data) {
435 eval(data.responseText);
436 dashletsListDiv = document.getElementById('dashletsList');
437 dashletsListDiv.innerHTML = response['html'];
439 document.getElementById('dashletsDialog_c').style.display = '';
440 SUGAR.mySugar.dashletsDialog.show();
442 eval(response['script']);
443 ajaxStatus.hideStatus();
446 var cObj = YAHOO.util.Connect.asyncRequest('GET', 'index.php?to_pdf=true&module='+module+'&action=DynamicAction&DynamicAction=dashletsDialog', {success: success, failure: success});
450 closeDashletsDialog: function(){
451 SUGAR.mySugar.dashletsDialog.hide();
452 window.setTimeout("document.getElementById('dashletsDialog_c').style.display = 'none';", 2000);
455 toggleDashletCategories: function(category){
456 document.getElementById('search_string').value = '';
457 document.getElementById('searchResults').innerHTML = '';
459 var moduleTab = document.getElementById('moduleCategory');
460 var moduleTabAnchor = document.getElementById('moduleCategoryAnchor');
461 var moduleListDiv = document.getElementById('moduleDashlets');
463 var chartTab = document.getElementById('chartCategory');
464 var chartTabAnchor = document.getElementById('chartCategoryAnchor');
465 var chartListDiv = document.getElementById('chartDashlets');
467 var toolsTab = document.getElementById('toolsCategory');
468 var toolsTabAnchor = document.getElementById('toolsCategoryAnchor');
469 var toolsListDiv = document.getElementById('toolsDashlets');
471 var webTab = document.getElementById('webCategory');
472 var webTabAnchor = document.getElementById('webCategoryAnchor');
473 var webListDiv = document.getElementById('webDashlets');
477 moduleTab.className = 'active';
478 moduleTabAnchor.className = 'current';
479 moduleListDiv.style.display = '';
481 chartTab.className = '';
482 chartTabAnchor.className = '';
483 chartListDiv.style.display = 'none';
485 toolsTab.className = '';
486 toolsTabAnchor.className = '';
487 toolsListDiv.style.display = 'none';
489 webTab.className = '';
490 webTabAnchor.className = '';
491 webListDiv.style.display = 'none';
495 moduleTab.className = '';
496 moduleTabAnchor.className = '';
497 moduleListDiv.style.display = 'none';
499 chartTab.className = 'active';
500 chartTabAnchor.className = 'current';
501 chartListDiv.style.display = '';
503 toolsTab.className = '';
504 toolsTabAnchor.className = '';
505 toolsListDiv.style.display = 'none';
507 webTab.className = '';
508 webTabAnchor.className = '';
509 webListDiv.style.display = 'none';
513 moduleTab.className = '';
514 moduleTabAnchor.className = '';
515 moduleListDiv.style.display = 'none';
517 chartTab.className = '';
518 chartTabAnchor.className = '';
519 chartListDiv.style.display = 'none';
521 toolsTab.className = 'active';
522 toolsTabAnchor.className = 'current';
523 toolsListDiv.style.display = '';
525 webTab.className = '';
526 webTabAnchor.className = '';
527 webListDiv.style.display = 'none';
531 moduleTab.className = '';
532 moduleTabAnchor.className = '';
533 moduleListDiv.style.display = 'none';
535 chartTab.className = '';
536 chartTabAnchor.className = '';
537 chartListDiv.style.display = 'none';
539 toolsTab.className = '';
540 toolsTabAnchor.className = '';
541 toolsListDiv.style.display = 'none';
543 webTab.className = 'active';
544 webTabAnchor.className = 'current';
545 webListDiv.style.display = '';
552 document.getElementById('search_category').value = category;
556 searchDashlets: function(searchStr, searchCategory){
557 var moduleTab = document.getElementById('moduleCategory');
558 var moduleTabAnchor = document.getElementById('moduleCategoryAnchor');
559 var moduleListDiv = document.getElementById('moduleDashlets');
561 var chartTab = document.getElementById('chartCategory');
562 var chartTabAnchor = document.getElementById('chartCategoryAnchor');
563 var chartListDiv = document.getElementById('chartDashlets');
565 var toolsTab = document.getElementById('toolsCategory');
566 var toolsTabAnchor = document.getElementById('toolsCategoryAnchor');
567 var toolsListDiv = document.getElementById('toolsDashlets');
569 if (moduleTab != null && chartTab != null && toolsTab != null){
570 moduleListDiv.style.display = 'none';
571 chartListDiv.style.display = 'none';
572 toolsListDiv.style.display = 'none';
575 // dashboards case, where there are no tabs
577 chartListDiv.style.display = 'none';
580 var searchResultsDiv = document.getElementById('searchResults');
581 searchResultsDiv.style.display = '';
583 var success = function(data) {
584 eval(data.responseText);
586 searchResultsDiv.innerHTML = response['html'];
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});
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" />';
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" />';
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" />';
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" />';
613 clearSearch: function(){
614 document.getElementById('search_string').value = '';
616 var moduleTab = document.getElementById('moduleCategory');
617 var moduleTabAnchor = document.getElementById('moduleCategoryAnchor');
618 var moduleListDiv = document.getElementById('moduleDashlets');
620 document.getElementById('searchResults').innerHTML = '';
621 if (moduleTab != null){
622 SUGAR.mySugar.toggleDashletCategories('module');
625 document.getElementById('searchResults').style.display = 'none';
626 document.getElementById('chartDashlets').style.display = '';
630 doneAddDashlets: function() {
631 SUGAR.mySugar.dashletsDialog.hide();
638 renderDashletsDialog: function(){
639 SUGAR.mySugar.dashletsDialog = new YAHOO.widget.Dialog("dashletsDialog",
645 // effect:[{effect:YAHOO.widget.ContainerEffect.SLIDETOP, duration:0.5},{effect:YAHOO.widget.ContainerEffect.FADE,duration:0.5}],
650 var listeners = new YAHOO.util.KeyListener(document, { keys : 27 }, {fn: function() {SUGAR.mySugar.closeDashletsDialog();} } );
651 SUGAR.mySugar.dashletsDialog.cfg.queueProperty("keylisteners", listeners);
653 document.getElementById('dashletsDialog').style.display = '';
654 SUGAR.mySugar.dashletsDialog.render();
655 document.getElementById('dashletsDialog_c').style.display = 'none';