1 /*********************************************************************************
2 * SugarCRM Community Edition is a customer relationship management program developed by
3 * SugarCRM, Inc. Copyright (C) 2004-2013 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 ********************************************************************************/
40 loadingWindow : false,
41 callback : function(o)
44 if (typeof window.onbeforeunload == "function")
45 window.onbeforeunload = null;
48 var r = YAHOO.lang.JSON.parse(o.responseText);
53 document.title = html_entity_decode(r.title);
57 action_sugar_grp1 = r.action;
61 SUGAR.ajaxUI.setFavicon(r.favicon);
64 var c = document.getElementById("content");
65 // Bug #49205 : Subpanels fail to load when selecting subpanel tab
66 // hide content of placeholder before apply new one
67 // @see SUGAR.util.evalScript
68 c.style.visibility = 'hidden';
70 SUGAR.util.evalScript(cont);
71 // all javascripts have been processed - show content of placeholder
72 c.style.visibility = 'visible';
76 SUGAR.themes.setModuleTabs(r.moduleList);
80 // set response time from ajax response
81 if(typeof(r.responseTime) != 'undefined'){
82 var rt = $("#responseTime");
84 rt.html(rt.html().replace(/[\d]+\.[\d]+/, r.responseTime));
86 else if(typeof(logoStats) != "undefined"){
87 $("#logo").attr("title", logoStats.replace(/[\d]+\.[\d]+/, r.responseTime)).tipTip({maxWidth: "auto", edgeOffset: 10});
90 // Bug #49205 : Subpanels fail to load when selecting subpanel tab
91 // hide ajax loading message after all scripts are processed
92 SUGAR.ajaxUI.hideLoadingPanel();
94 // Bug #49205 : Subpanels fail to load when selecting subpanel tab
95 // hide ajax loading message after all scripts are processed
96 SUGAR.ajaxUI.hideLoadingPanel();
97 SUGAR.ajaxUI.showErrorMessage(o.responseText);
99 SUGAR_callsInProgress--;
101 showErrorMessage : function(errorMessage)
103 if (!SUGAR.ajaxUI.errorPanel) {
104 SUGAR.ajaxUI.errorPanel = new YAHOO.widget.Panel("ajaxUIErrorPanel", {
107 constraintoviewport: true,
113 var panel = SUGAR.ajaxUI.errorPanel;
114 panel.setHeader(SUGAR.language.get('app_strings','ERR_AJAX_LOAD')) ;
115 panel.setBody('<iframe id="ajaxErrorFrame" style="width:780px;height:550px;border:none;marginheight="0" marginwidth="0" frameborder="0""></iframe>');
116 panel.setFooter(SUGAR.language.get('app_strings','ERR_AJAX_LOAD_FOOTER')) ;
117 panel.render(document.body);
120 var f = document.getElementById("ajaxErrorFrame");
121 return f != null && f.contentWindow != null && f.contentWindow.document != null;
123 document.getElementById("ajaxErrorFrame").contentWindow.document.body.innerHTML = errorMessage;
124 window.setTimeout('throw "AjaxUI error parsing response"', 300);
127 //fire off a delayed check to make sure error message was rendered.
128 SUGAR.ajaxUI.errorMessage = errorMessage;
129 window.setTimeout('if((typeof(document.getElementById("ajaxErrorFrame")) == "undefined" || typeof(document.getElementById("ajaxErrorFrame")) == null || document.getElementById("ajaxErrorFrame").contentWindow.document.body.innerHTML == "")){document.getElementById("ajaxErrorFrame").contentWindow.document.body.innerHTML=SUGAR.ajaxUI.errorMessage;}',3000);
134 throw "AjaxUI error parsing response";
136 canAjaxLoadModule : function(module)
138 var checkLS = /&LicState=check/.exec(window.location.search);
140 // Return false if ajax ui is completely disabled, or if license state is set to check
141 if( checkLS || (typeof(SUGAR.config.disableAjaxUI) != 'undefined' && SUGAR.config.disableAjaxUI == true)){
145 var bannedModules = SUGAR.config.stockAjaxBannedModules;
146 //If banned modules isn't there, we are probably on a page that isn't ajaxUI compatible
147 if (typeof(bannedModules) == 'undefined')
149 // Mechanism to allow for overriding or adding to this list
150 if(typeof(SUGAR.config.addAjaxBannedModules) != 'undefined'){
151 bannedModules.concat(SUGAR.config.addAjaxBannedModules);
153 if(typeof(SUGAR.config.overrideAjaxBannedModules) != 'undefined'){
154 bannedModules = SUGAR.config.overrideAjaxBannedModules;
157 return SUGAR.util.arrayIndexOf(bannedModules, module) == -1;
160 loadContent : function(url, params)
162 if(YAHOO.lang.trim(url) != "")
164 //Don't ajax load certain modules
165 var mRegex = /module=([^&]*)/.exec(url);
166 var module = mRegex ? mRegex[1] : false;
167 if (module && SUGAR.ajaxUI.canAjaxLoadModule(module))
169 YAHOO.util.History.navigate('ajaxUILoc', url);
171 window.location = url;
179 if(YAHOO.lang.trim(url) != "")
181 var con = YAHOO.util.Connect, ui = SUGAR.ajaxUI;
182 if (ui.lastURL == url)
184 var inAjaxUI = /action=ajaxui/.exec(window.location);
185 if (typeof (window.onbeforeunload) == "function" && window.onbeforeunload())
187 //If there is an unload function, we need to check it ourselves
188 if (!confirm(window.onbeforeunload()))
192 //User doesn't want to navigate
193 window.location.hash = "";
197 YAHOO.util.History.navigate('ajaxUILoc', ui.lastURL);
201 window.onbeforeunload = null;
203 if (ui.lastCall && con.isCallInProgress(ui.lastCall)) {
204 con.abort(ui.lastCall);
206 var mRegex = /module=([^&]*)/.exec(url);
207 var module = mRegex ? mRegex[1] : false;
208 //If we can't ajax load the module (blacklisted), set the URL directly.
209 if (!ui.canAjaxLoadModule(module)) {
210 window.location = url;
215 var loadLanguageJS = '';
216 if(module && typeof(SUGAR.language.languages[module]) == 'undefined'){
217 loadLanguageJS = '&loadLanguageJS=1';
221 //If we aren't in the ajaxUI yet, we need to reload the page to get setup properly
223 window.location.replace("index.php?action=ajaxui#ajaxUILoc=" + encodeURIComponent(url));
225 //if we use replace under IE, it will cache the page as the replaced version and thus no longer load the previous page.
226 window.location.hash = "#";
227 window.location.assign("index.php?action=ajaxui#ajaxUILoc=" + encodeURIComponent(url));
231 SUGAR_callsInProgress++;
232 SUGAR.ajaxUI.showLoadingPanel();
233 ui.lastCall = YAHOO.util.Connect.asyncRequest('GET', url + '&ajax_load=1' + loadLanguageJS, {
234 success: SUGAR.ajaxUI.callback,
236 SUGAR_callsInProgress--;
237 SUGAR.ajaxUI.hideLoadingPanel();
238 SUGAR.ajaxUI.showErrorMessage(SUGAR.language.get('app_strings','ERR_AJAX_LOAD_FAILURE'));
245 submitForm : function(formname, params)
247 var con = YAHOO.util.Connect, SA = SUGAR.ajaxUI;
248 if (SA.lastCall && con.isCallInProgress(SA.lastCall)) {
249 con.abort(SA.lastCall);
251 //Reset the EmailAddressWidget before loading a new page
253 //Don't ajax load certain modules
254 var form = YAHOO.util.Dom.get(formname) || document.forms[formname];
255 if (SA.canAjaxLoadModule(form.module.value)
256 //Do not try to submit a form that contains a file input via ajax.
257 && typeof(YAHOO.util.Selector.query("input[type=file]", form)[0]) == "undefined"
258 //Do not try to ajax submit a form if the ajaxUI is not initialized
259 && /action=ajaxui/.exec(window.location))
261 var string = con.setForm(form);
262 var baseUrl = "index.php?action=ajaxui#ajaxUILoc=";
264 //Use POST for long forms and GET for short forms (GET allow resubmit via reload)
265 if(string.length > 200)
267 SUGAR.ajaxUI.showLoadingPanel();
268 form.onsubmit = function(){ return true; };
271 con.resetFormState();
272 window.location = baseUrl + encodeURIComponent("index.php?" + string);
277 if( typeof(YAHOO.util.Selector.query("input[type=submit]", form)[0]) != "undefined"
278 && YAHOO.util.Selector.query("input[type=submit]", form)[0].value == "Save")
280 ajaxStatus.showStatus(SUGAR.language.get('app_strings', 'LBL_SAVING'));
288 cleanGlobals : function()
291 QSProcessedFieldsArray = {};
293 //Reset the EmailAddressWidget before loading a new page
294 if (SUGAR.EmailAddressWidget){
295 SUGAR.EmailAddressWidget.instances = {};
296 SUGAR.EmailAddressWidget.count = {};
298 YAHOO.util.Event.removeListener(window, 'resize');
299 //Hide any connector dialogs
300 if(typeof(dialog) != 'undefined' && typeof(dialog.destroy) == 'function'){
306 firstLoad : function()
308 //Setup Browser History
309 var url = YAHOO.util.History.getBookmarkedState('ajaxUILoc');
310 var aRegex = /action=([^&#]*)/.exec(window.location);
311 var action = aRegex ? aRegex[1] : false;
312 var mRegex = /module=([^&#]*)/.exec(window.location);
313 var module = mRegex ? mRegex[1] : false;
314 if (module != "ModuleBuilder")
316 var go = url != null || action == "ajaxui";
317 url = url ? url : 'index.php?module=Home&action=index';
318 YAHOO.util.History.register('ajaxUILoc', url, SUGAR.ajaxUI.go);
319 YAHOO.util.History.initialize("ajaxUI-history-field", "ajaxUI-history-iframe");
320 SUGAR.ajaxUI.hist_loaded = true;
322 SUGAR.ajaxUI.go(url);
324 SUGAR_callsInProgress--;
328 var url = YAHOO.util.History.getBookmarkedState('ajaxUILoc');
329 SUGAR.util.openWindow(
332 'menubar=1,status=0,resizable=1,scrollbars=1,toolbar=0,location=1'
335 showLoadingPanel: function()
337 if (!SUGAR.ajaxUI.loadingPanel)
339 SUGAR.ajaxUI.loadingPanel = new YAHOO.widget.Panel("ajaxloading",
345 constraintoviewport:false,
349 SUGAR.ajaxUI.loadingPanel.setBody('<div id="loadingPage" align="center" style="vertical-align:middle;"><img src="' + SUGAR.themes.loading_image + '" align="absmiddle" /> <b>' + SUGAR.language.get('app_strings', 'LBL_LOADING_PAGE') +'</b></div>');
350 SUGAR.ajaxUI.loadingPanel.render(document.body);
353 if (document.getElementById('ajaxloading_c'))
354 document.getElementById('ajaxloading_c').style.display = '';
356 SUGAR.ajaxUI.loadingPanel.show();
359 hideLoadingPanel: function()
361 SUGAR.ajaxUI.loadingPanel.hide();
363 if (document.getElementById('ajaxloading_c'))
364 document.getElementById('ajaxloading_c').style.display = 'none';
366 setFavicon: function(data)
368 var head = document.getElementsByTagName("head")[0];
370 // first remove all rel="icon" links as long as updating an existing one
371 // could take no effect
372 var links = head.getElementsByTagName("link");
373 var re = /\bicon\b/i;
374 for (var i = 0; i < links.length; i++) {
375 if (re.test(links[i].rel))
377 head.removeChild(links[i]);
381 var link = document.createElement("link");
383 link.href = data.url;
384 // type attribute is important for Google Chrome browser
385 link.type = data.type;
387 head.appendChild(link);