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 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";
79 // get the current dashlet layout
80 getLayout: function(asString) {
81 columns = new Array();
82 for(je = 0; je < 3; je++) {
83 dashlets = document.getElementById('col_'+activeTab+'_'+ je);
85 if (dashlets != null){
86 dashletIds = new Array();
87 for(wp = 0; wp < dashlets.childNodes.length; wp++) {
88 if(typeof dashlets.childNodes[wp].id != 'undefined' && dashlets.childNodes[wp].id.match(/dashlet_[\w-]*/)) {
89 dashletIds.push(dashlets.childNodes[wp].id.replace(/dashlet_/,''));
93 columns[je] = dashletIds.join(',');
95 columns[je] = dashletIds;
99 if(asString) return columns.join('|');
103 // called when dashlet is picked up
104 onDrag: function(e, id) {
105 originalLayout = SUGAR.mySugar.getLayout(true);
108 // called when dashlet is dropped
109 onDrop: function(e, id) {
110 newLayout = SUGAR.mySugar.getLayout(true);
111 if(originalLayout != newLayout) { // only save if the layout has changed
112 SUGAR.mySugar.saveLayout(newLayout);
113 SUGAR.mySugar.sugarCharts.loadSugarCharts(); // called safely because there is a check to be sure the array exists
117 // save the layout of the dashlet
118 saveLayout: function(order) {
119 ajaxStatus.showStatus(SUGAR.language.get('app_strings', 'LBL_SAVING_LAYOUT'));
120 var success = function(data) {
121 ajaxStatus.showStatus(SUGAR.language.get('app_strings', 'LBL_SAVED_LAYOUT'));
122 window.setTimeout('ajaxStatus.hideStatus()', 2000);
125 url = 'index.php?to_pdf=1&module='+module+'&action=DynamicAction&DynamicAction=saveLayout&layout=' + order + '&selectedPage=' + activeTab;
126 var cObj = YAHOO.util.Connect.asyncRequest('GET', url, {success: success, failure: success});
130 uncoverPage: function(id) {
132 document.getElementById('dlg_c').style.display = 'none';
135 if ( document.getElementById('dashletType') == null ) {
138 dashletType = document.getElementById('dashletType').value;
140 SUGAR.mySugar.retrieveDashlet(SUGAR.mySugar.configureDashletId, dashletType);
143 // call to configure a Dashlet
144 configureDashlet: function(id) {
145 ajaxStatus.showStatus(SUGAR.language.get('app_strings', 'LBL_LOADING'));
146 configureDlg = new YAHOO.widget.SimpleDialog("dlg",
149 effect:[{effect:YAHOO.widget.ContainerEffect.SLIDE, duration:0.5},
150 {effect:YAHOO.widget.ContainerEffect.FADE,duration:0.5}],
156 fillInConfigureDiv = function(data){
157 ajaxStatus.hideStatus();
158 // uncomment the line below to debug w/ FireBug
159 // console.log(data.responseText);
161 eval(data.responseText);
164 result = new Array();
165 result['header'] = 'error';
166 result['body'] = 'There was an error handling this request.';
168 configureDlg.setHeader(result['header']);
169 configureDlg.setBody(result['body']);
170 var listeners = new YAHOO.util.KeyListener(document, { keys : 27 }, {fn: function() {this.hide();}, scope: configureDlg, correctScope:true} );
171 configureDlg.cfg.queueProperty("keylisteners", listeners);
173 configureDlg.render(document.body);
175 configureDlg.configFixedCenter(null, false) ;
176 SUGAR.util.evalScript(result['body']);
179 SUGAR.mySugar.configureDashletId = id; // save the id of the dashlet being configured
180 var cObj = YAHOO.util.Connect.asyncRequest('GET','index.php?to_pdf=1&module='+module+'&action=DynamicAction&DynamicAction=configureDashlet&id=' + id,
181 {success: fillInConfigureDiv, failure: fillInConfigureDiv}, null);
185 /** returns dashlets contents
186 * if url is defined, dashlet will be retrieve with it, otherwise use default url
188 * @param string id id of the dashlet to refresh
189 * @param string url url to be used
190 * @param function callback callback function after refresh
191 * @param bool dynamic does the script load dynamic javascript, set to true if you user needs to refresh the dashlet after load
193 retrieveDashlet: function(id, url, callback, dynamic) {
194 ajaxStatus.showStatus(SUGAR.language.get('app_strings', 'LBL_LOADING'));
197 url = 'index.php?action=DynamicAction&DynamicAction=displayDashlet&session_commit=1&module='+module+'&to_pdf=1&id=' + id;
198 is_chart_dashlet = false;
200 else if (url == 'predefined_chart'){
201 url = 'index.php?action=DynamicAction&DynamicAction=displayDashlet&session_commit=1&module='+module+'&to_pdf=1&id=' + id;
202 scriptUrl = 'index.php?action=DynamicAction&DynamicAction=getPredefinedChartScript&session_commit=1&module='+module+'&to_pdf=1&id=' + id;
203 is_chart_dashlet = true;
208 url += '&dynamic=true';
211 var fillInDashlet = function(data) {
213 ajaxStatus.hideStatus();
215 SUGAR.mySugar.currentDashlet.innerHTML = data.responseText;
218 SUGAR.util.evalScript(data.responseText);
219 if(callback) callback();
221 var processChartScript = function(scriptData){
222 SUGAR.util.evalScript(scriptData.responseText);
224 SUGAR.mySugar.sugarCharts.loadSugarCharts(activePage);
227 if(typeof(is_chart_dashlet)=='undefined'){
228 is_chart_dashlet = false;
230 if (is_chart_dashlet){
231 var chartScriptObj = YAHOO.util.Connect.asyncRequest('GET', scriptUrl,
232 {success: processChartScript, failure: processChartScript}, null);
236 SUGAR.mySugar.currentDashlet = document.getElementById('dashlet_entire_' + id);
237 var cObj = YAHOO.util.Connect.asyncRequest('GET', url,
238 {success: fillInDashlet, failure: fillInDashlet}, null);
242 // for the display columns widget
243 setChooser: function() {
244 var displayColumnsDef = new Array();
245 var hideTabsDef = new Array();
247 var left_td = document.getElementById('display_tabs_td');
248 var right_td = document.getElementById('hide_tabs_td');
250 var displayTabs = left_td.getElementsByTagName('select')[0];
251 var hideTabs = right_td.getElementsByTagName('select')[0];
253 for(i = 0; i < displayTabs.options.length; i++) {
254 displayColumnsDef.push(displayTabs.options[i].value);
257 if(typeof hideTabs != 'undefined') {
258 for(i = 0; i < hideTabs.options.length; i++) {
259 hideTabsDef.push(hideTabs.options[i].value);
263 document.getElementById('displayColumnsDef').value = displayColumnsDef.join('|');
264 document.getElementById('hideTabsDef').value = hideTabsDef.join('|');
267 deleteDashlet: function(id) {
268 if(confirm(SUGAR.language.get('app_strings', 'LBL_REMOVE_DASHLET_CONFIRM'))) {
269 ajaxStatus.showStatus(SUGAR.language.get('app_strings', 'LBL_REMOVING_DASHLET'));
272 var success = function(data) {
273 dashlet = document.getElementById('dashlet_' + id);
274 dashlet.parentNode.removeChild(dashlet);
275 ajaxStatus.showStatus(SUGAR.language.get('app_strings', 'LBL_REMOVED_DASHLET'));
276 window.setTimeout('ajaxStatus.hideStatus()', 2000);
280 var cObj = YAHOO.util.Connect.asyncRequest('GET','index.php?to_pdf=1&module='+module+'&action=DynamicAction&DynamicAction=deleteDashlet&activePage=' + activeTab + '&id=' + id,
281 {success: success, failure: success}, null);
284 var anim = new YAHOO.util.Anim('dashlet_entire_' + id, { height: {to: 1} }, .5 );
285 anim.onComplete.subscribe(del);
286 document.getElementById('dashlet_entire_' + id).style.overflow = 'hidden';
295 addDashlet: function(id, type, type_module) {
296 ajaxStatus.hideStatus();
297 columns = SUGAR.mySugar.getLayout();
299 var num_dashlets = columns[0].length;
300 if (typeof columns[1] == undefined){
301 num_dashlets = num_dashlets + columns[1].length;
304 if((num_dashlets) >= SUGAR.mySugar.maxCount) {
305 alert(SUGAR.language.get('app_strings', 'LBL_MAX_DASHLETS_REACHED'));
308 /* if((columns[0].length + columns[1].length) >= SUGAR.mySugar.maxCount) {
309 alert(SUGAR.language.get('Home', 'LBL_MAX_DASHLETS_REACHED'));
312 ajaxStatus.showStatus(SUGAR.language.get('app_strings', 'LBL_ADDING_DASHLET'));
313 var success = function(data) {
315 colZero = document.getElementById('col_'+activeTab+'_0');
316 newDashlet = document.createElement('li'); // build the list item
317 newDashlet.id = 'dashlet_' + data.responseText;
318 newDashlet.className = 'noBullet active';
319 // hide it first, but append to getRegion
320 newDashlet.innerHTML = '<div style="position: absolute; top: -1000px; overflow: hidden;" id="dashlet_entire_' + data.responseText + '"></div>';
322 colZero.insertBefore(newDashlet, colZero.firstChild); // insert it into the first column
324 var finishRetrieve = function() {
325 dashletEntire = document.getElementById('dashlet_entire_' + data.responseText);
326 dd = new ygDDList('dashlet_' + data.responseText); // make it draggable
327 dd.setHandleElId('dashlet_header_' + data.responseText);
328 dd.onMouseDown = SUGAR.mySugar.onDrag;
329 dd.onDragDrop = SUGAR.mySugar.onDrop;
331 ajaxStatus.showStatus(SUGAR.language.get('app_strings', 'LBL_ADDED_DASHLET'));
332 dashletRegion = YAHOO.util.Dom.getRegion(dashletEntire);
333 dashletEntire.style.position = 'relative';
334 dashletEntire.style.height = '1px';
335 dashletEntire.style.top = '0px';
336 dashletEntire.className = 'dashletPanel';
339 var anim = new YAHOO.util.Anim('dashlet_entire_' + data.responseText, { height: {to: dashletRegion.bottom - dashletRegion.top} }, .5 );
340 anim.onComplete.subscribe(function() { document.getElementById('dashlet_entire_' + data.responseText).style.height = '100%'; });
343 newLayout = SUGAR.mySugar.getLayout(true);
344 SUGAR.mySugar.saveLayout(newLayout);
345 // window.setTimeout('ajaxStatus.hideStatus()', 2000);
348 if (type == 'module' || type == 'web'){
352 else if (type == 'predefined_chart'){
353 url = 'predefined_chart';
354 type = 'predefined_chart';
356 else if (type == 'chart'){
361 SUGAR.mySugar.retrieveDashlet(data.responseText, url, finishRetrieve, true); // retrieve it from the server
363 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,
364 {success: success, failure: success}, null);
369 showDashletsDialog: function() {
370 columns = SUGAR.mySugar.getLayout();
372 var num_dashlets = 0;
374 for ( i = 0 ; i < 3; i++ ) {
375 if (typeof columns[i] != "undefined") {
376 num_dashlets = num_dashlets + columns[i].length;
380 if((num_dashlets) >= SUGAR.mySugar.maxCount) {
381 alert(SUGAR.language.get('app_strings', 'LBL_MAX_DASHLETS_REACHED'));
384 ajaxStatus.showStatus(SUGAR.language.get('app_strings', 'LBL_LOADING'));
386 var success = function(data) {
387 eval(data.responseText);
388 dashletsListDiv = document.getElementById('dashletsList');
389 dashletsListDiv.innerHTML = response['html'];
391 document.getElementById('dashletsDialog_c').style.display = '';
392 SUGAR.mySugar.dashletsDialog.show();
394 eval(response['script']);
395 ajaxStatus.hideStatus();
398 var cObj = YAHOO.util.Connect.asyncRequest('GET', 'index.php?to_pdf=true&module='+module+'&action=DynamicAction&DynamicAction=dashletsDialog', {success: success, failure: success});
402 closeDashletsDialog: function(){
403 SUGAR.mySugar.dashletsDialog.hide();
404 window.setTimeout("document.getElementById('dashletsDialog_c').style.display = 'none';", 2000);
407 toggleDashletCategories: function(category){
408 document.getElementById('search_string').value = '';
409 document.getElementById('searchResults').innerHTML = '';
411 var moduleTab = document.getElementById('moduleCategory');
412 var moduleTabAnchor = document.getElementById('moduleCategoryAnchor');
413 var moduleListDiv = document.getElementById('moduleDashlets');
415 var chartTab = document.getElementById('chartCategory');
416 var chartTabAnchor = document.getElementById('chartCategoryAnchor');
417 var chartListDiv = document.getElementById('chartDashlets');
419 var toolsTab = document.getElementById('toolsCategory');
420 var toolsTabAnchor = document.getElementById('toolsCategoryAnchor');
421 var toolsListDiv = document.getElementById('toolsDashlets');
423 var webTab = document.getElementById('webCategory');
424 var webTabAnchor = document.getElementById('webCategoryAnchor');
425 var webListDiv = document.getElementById('webDashlets');
429 moduleTab.className = 'active';
430 moduleTabAnchor.className = 'current';
431 moduleListDiv.style.display = '';
433 chartTab.className = '';
434 chartTabAnchor.className = '';
435 chartListDiv.style.display = 'none';
437 toolsTab.className = '';
438 toolsTabAnchor.className = '';
439 toolsListDiv.style.display = 'none';
441 webTab.className = '';
442 webTabAnchor.className = '';
443 webListDiv.style.display = 'none';
447 moduleTab.className = '';
448 moduleTabAnchor.className = '';
449 moduleListDiv.style.display = 'none';
451 chartTab.className = 'active';
452 chartTabAnchor.className = 'current';
453 chartListDiv.style.display = '';
455 toolsTab.className = '';
456 toolsTabAnchor.className = '';
457 toolsListDiv.style.display = 'none';
459 webTab.className = '';
460 webTabAnchor.className = '';
461 webListDiv.style.display = 'none';
465 moduleTab.className = '';
466 moduleTabAnchor.className = '';
467 moduleListDiv.style.display = 'none';
469 chartTab.className = '';
470 chartTabAnchor.className = '';
471 chartListDiv.style.display = 'none';
473 toolsTab.className = 'active';
474 toolsTabAnchor.className = 'current';
475 toolsListDiv.style.display = '';
477 webTab.className = '';
478 webTabAnchor.className = '';
479 webListDiv.style.display = 'none';
483 moduleTab.className = '';
484 moduleTabAnchor.className = '';
485 moduleListDiv.style.display = 'none';
487 chartTab.className = '';
488 chartTabAnchor.className = '';
489 chartListDiv.style.display = 'none';
491 toolsTab.className = '';
492 toolsTabAnchor.className = '';
493 toolsListDiv.style.display = 'none';
495 webTab.className = 'active';
496 webTabAnchor.className = 'current';
497 webListDiv.style.display = '';
504 document.getElementById('search_category').value = category;
508 searchDashlets: function(searchStr, searchCategory){
509 var moduleTab = document.getElementById('moduleCategory');
510 var moduleTabAnchor = document.getElementById('moduleCategoryAnchor');
511 var moduleListDiv = document.getElementById('moduleDashlets');
513 var chartTab = document.getElementById('chartCategory');
514 var chartTabAnchor = document.getElementById('chartCategoryAnchor');
515 var chartListDiv = document.getElementById('chartDashlets');
517 var toolsTab = document.getElementById('toolsCategory');
518 var toolsTabAnchor = document.getElementById('toolsCategoryAnchor');
519 var toolsListDiv = document.getElementById('toolsDashlets');
521 if (moduleTab != null && chartTab != null && toolsTab != null){
522 moduleListDiv.style.display = 'none';
523 chartListDiv.style.display = 'none';
524 toolsListDiv.style.display = 'none';
527 // dashboards case, where there are no tabs
529 chartListDiv.style.display = 'none';
532 var searchResultsDiv = document.getElementById('searchResults');
533 searchResultsDiv.style.display = '';
535 var success = function(data) {
536 eval(data.responseText);
538 searchResultsDiv.innerHTML = response['html'];
541 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});
545 collapseList: function(chartList){
546 document.getElementById(chartList+'List').style.display='none';
547 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" />';
550 expandList: function(chartList){
551 document.getElementById(chartList+'List').style.display='';
552 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" />';
555 collapseReportList: function(reportChartList){
556 document.getElementById(reportChartList+'ReportsChartDashletsList').style.display='none';
557 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" />';
560 expandReportList: function(reportChartList){
561 document.getElementById(reportChartList+'ReportsChartDashletsList').style.display='';
562 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" />';
565 clearSearch: function(){
566 document.getElementById('search_string').value = '';
568 var moduleTab = document.getElementById('moduleCategory');
569 var moduleTabAnchor = document.getElementById('moduleCategoryAnchor');
570 var moduleListDiv = document.getElementById('moduleDashlets');
572 document.getElementById('searchResults').innerHTML = '';
573 if (moduleTab != null){
574 SUGAR.mySugar.toggleDashletCategories('module');
577 document.getElementById('searchResults').style.display = 'none';
578 document.getElementById('chartDashlets').style.display = '';
582 doneAddDashlets: function() {
583 SUGAR.mySugar.dashletsDialog.hide();
590 renderDashletsDialog: function(){
591 SUGAR.mySugar.dashletsDialog = new YAHOO.widget.Dialog("dashletsDialog",
597 // effect:[{effect:YAHOO.widget.ContainerEffect.SLIDETOP, duration:0.5},{effect:YAHOO.widget.ContainerEffect.FADE,duration:0.5}],
602 var listeners = new YAHOO.util.KeyListener(document, { keys : 27 }, {fn: function() {SUGAR.mySugar.closeDashletsDialog();} } );
603 SUGAR.mySugar.dashletsDialog.cfg.queueProperty("keylisteners", listeners);
605 document.getElementById('dashletsDialog').style.display = '';
606 SUGAR.mySugar.dashletsDialog.render();
607 document.getElementById('dashletsDialog_c').style.display = 'none';