1 /*********************************************************************************
2 * SugarCRM Community Edition is a customer relationship management program developed by
3 * SugarCRM, Inc. Copyright (C) 2004-2012 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;
47 SUGAR.ajaxUI.hideLoadingPanel();
49 var r = YAHOO.lang.JSON.parse(o.responseText);
54 document.title = html_entity_decode(r.title);
58 action_sugar_grp1 = r.action;
62 SUGAR.ajaxUI.setFavicon(r.favicon);
65 var c = document.getElementById("content");
67 SUGAR.util.evalScript(cont);
71 SUGAR.themes.setModuleTabs(r.moduleList);
75 // set response time from ajax response
76 if(typeof(r.responseTime) != 'undefined'){
77 var rt = $("#responseTime");
79 rt.html(rt.html().replace(/[\d]+\.[\d]+/, r.responseTime));
81 else if(typeof(logoStats) != "undefined"){
82 $("#logo").attr("title", logoStats.replace(/[\d]+\.[\d]+/, r.responseTime)).tipTip({maxWidth: "auto", edgeOffset: 10});
86 SUGAR.ajaxUI.showErrorMessage(o.responseText);
89 showErrorMessage : function(errorMessage)
91 if (!SUGAR.ajaxUI.errorPanel) {
92 SUGAR.ajaxUI.errorPanel = new YAHOO.widget.Panel("ajaxUIErrorPanel", {
95 constraintoviewport: true,
101 var panel = SUGAR.ajaxUI.errorPanel;
102 panel.setHeader(SUGAR.language.get('app_strings','ERR_AJAX_LOAD')) ;
103 panel.setBody('<iframe id="ajaxErrorFrame" style="width:780px;height:550px;border:none;marginheight="0" marginwidth="0" frameborder="0""></iframe>');
104 panel.setFooter(SUGAR.language.get('app_strings','ERR_AJAX_LOAD_FOOTER')) ;
105 panel.render(document.body);
108 var f = document.getElementById("ajaxErrorFrame");
109 return f != null && f.contentWindow != null && f.contentWindow.document != null;
111 document.getElementById("ajaxErrorFrame").contentWindow.document.body.innerHTML = errorMessage;
112 window.setTimeout('throw "AjaxUI error parsing response"', 300);
115 //fire off a delayed check to make sure error message was rendered.
116 SUGAR.ajaxUI.errorMessage = errorMessage;
117 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);
122 throw "AjaxUI error parsing response";
124 canAjaxLoadModule : function(module)
126 var checkLS = /&LicState=check/.exec(window.location.search);
128 // Return false if ajax ui is completely disabled, or if license state is set to check
129 if( checkLS || (typeof(SUGAR.config.disableAjaxUI) != 'undefined' && SUGAR.config.disableAjaxUI == true)){
133 var bannedModules = SUGAR.config.stockAjaxBannedModules;
134 //If banned modules isn't there, we are probably on a page that isn't ajaxUI compatible
135 if (typeof(bannedModules) == 'undefined')
137 // Mechanism to allow for overriding or adding to this list
138 if(typeof(SUGAR.config.addAjaxBannedModules) != 'undefined'){
139 bannedModules.concat(SUGAR.config.addAjaxBannedModules);
141 if(typeof(SUGAR.config.overrideAjaxBannedModules) != 'undefined'){
142 bannedModules = SUGAR.config.overrideAjaxBannedModules;
145 return SUGAR.util.arrayIndexOf(bannedModules, module) == -1;
148 loadContent : function(url, params)
150 if(YAHOO.lang.trim(url) != "")
152 //Don't ajax load certain modules
153 var mRegex = /module=([^&]*)/.exec(url);
154 var module = mRegex ? mRegex[1] : false;
155 if (module && SUGAR.ajaxUI.canAjaxLoadModule(module))
157 YAHOO.util.History.navigate('ajaxUILoc', url);
159 window.location = url;
166 if(YAHOO.lang.trim(url) != "")
168 var con = YAHOO.util.Connect, ui = SUGAR.ajaxUI;
169 if (ui.lastURL == url)
171 var inAjaxUI = /action=ajaxui/.exec(window.location);
172 if (typeof (window.onbeforeunload) == "function" && window.onbeforeunload())
174 //If there is an unload function, we need to check it ourselves
175 if (!confirm(window.onbeforeunload()))
179 //User doesn't want to navigate
180 window.location.hash = "";
184 YAHOO.util.History.navigate('ajaxUILoc', ui.lastURL);
188 window.onbeforeunload = null;
190 if (ui.lastCall && con.isCallInProgress(ui.lastCall)) {
191 con.abort(ui.lastCall);
193 var mRegex = /module=([^&]*)/.exec(url);
194 var module = mRegex ? mRegex[1] : false;
195 //If we can't ajax load the module (blacklisted), set the URL directly.
196 if (!ui.canAjaxLoadModule(module)) {
197 window.location = url;
202 var loadLanguageJS = '';
203 if(module && typeof(SUGAR.language.languages[module]) == 'undefined'){
204 loadLanguageJS = '&loadLanguageJS=1';
208 //If we aren't in the ajaxUI yet, we need to reload the page to get setup properly
210 window.location.replace("index.php?action=ajaxui#ajaxUILoc=" + encodeURIComponent(url));
212 //if we use replace under IE, it will cache the page as the replaced version and thus no longer load the previous page.
213 window.location.hash = "#";
214 window.location.assign("index.php?action=ajaxui#ajaxUILoc=" + encodeURIComponent(url));
218 SUGAR.ajaxUI.showLoadingPanel();
219 ui.lastCall = YAHOO.util.Connect.asyncRequest('GET', url + '&ajax_load=1' + loadLanguageJS, {
220 success: SUGAR.ajaxUI.callback,
222 SUGAR.ajaxUI.hideLoadingPanel();
223 SUGAR.ajaxUI.showErrorMessage(SUGAR.language.get('app_strings','ERR_AJAX_LOAD_FAILURE'));
230 submitForm : function(formname, params)
232 var con = YAHOO.util.Connect, SA = SUGAR.ajaxUI;
233 if (SA.lastCall && con.isCallInProgress(SA.lastCall)) {
234 con.abort(SA.lastCall);
236 //Reset the EmailAddressWidget before loading a new page
238 //Don't ajax load certain modules
239 var form = YAHOO.util.Dom.get(formname) || document.forms[formname];
240 if (SA.canAjaxLoadModule(form.module.value)
241 //Do not try to submit a form that contains a file input via ajax.
242 && typeof(YAHOO.util.Selector.query("input[type=file]", form)[0]) == "undefined"
243 //Do not try to ajax submit a form if the ajaxUI is not initialized
244 && /action=ajaxui/.exec(window.location))
246 var string = con.setForm(form);
247 var baseUrl = "index.php?action=ajaxui#ajaxUILoc=";
249 //Use POST for long forms and GET for short forms (GET allow resubmit via reload)
250 if(string.length > 200)
252 SUGAR.ajaxUI.showLoadingPanel();
253 form.onsubmit = function(){ return true; };
256 con.resetFormState();
257 window.location = baseUrl + encodeURIComponent("index.php?" + string);
262 if( typeof(YAHOO.util.Selector.query("input[type=submit]", form)[0]) != "undefined"
263 && YAHOO.util.Selector.query("input[type=submit]", form)[0].value == "Save")
265 ajaxStatus.showStatus(SUGAR.language.get('app_strings', 'LBL_SAVING'));
273 cleanGlobals : function()
276 QSProcessedFieldsArray = {};
278 //Reset the EmailAddressWidget before loading a new page
279 if (SUGAR.EmailAddressWidget){
280 SUGAR.EmailAddressWidget.instances = {};
281 SUGAR.EmailAddressWidget.count = {};
283 YAHOO.util.Event.removeListener(window, 'resize');
284 //Hide any connector dialogs
285 if(typeof(dialog) != 'undefined' && typeof(dialog.destroy) == 'function'){
291 firstLoad : function()
293 //Setup Browser History
294 var url = YAHOO.util.History.getBookmarkedState('ajaxUILoc');
295 var aRegex = /action=([^&#]*)/.exec(window.location);
296 var action = aRegex ? aRegex[1] : false;
297 var mRegex = /module=([^&#]*)/.exec(window.location);
298 var module = mRegex ? mRegex[1] : false;
299 if (module != "ModuleBuilder")
301 var go = url != null || action == "ajaxui";
302 url = url ? url : 'index.php?module=Home&action=index';
303 YAHOO.util.History.register('ajaxUILoc', url, SUGAR.ajaxUI.go);
304 YAHOO.util.History.initialize("ajaxUI-history-field", "ajaxUI-history-iframe");
305 SUGAR.ajaxUI.hist_loaded = true;
307 SUGAR.ajaxUI.go(url);
309 SUGAR_callsInProgress--;
313 var url = YAHOO.util.History.getBookmarkedState('ajaxUILoc');
314 SUGAR.util.openWindow(
317 'menubar=1,status=0,resizable=1,scrollbars=1,toolbar=0,location=1'
320 showLoadingPanel: function()
322 if (!SUGAR.ajaxUI.loadingPanel)
324 SUGAR.ajaxUI.loadingPanel = new YAHOO.widget.Panel("ajaxloading",
330 constraintoviewport:false,
334 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>');
335 SUGAR.ajaxUI.loadingPanel.render(document.body);
338 if (document.getElementById('ajaxloading_c'))
339 document.getElementById('ajaxloading_c').style.display = '';
341 SUGAR.ajaxUI.loadingPanel.show();
344 hideLoadingPanel: function()
346 SUGAR.ajaxUI.loadingPanel.hide();
348 if (document.getElementById('ajaxloading_c'))
349 document.getElementById('ajaxloading_c').style.display = 'none';
351 setFavicon: function(data)
353 var head = document.getElementsByTagName("head")[0];
355 // first remove all rel="icon" links as long as updating an existing one
356 // could take no effect
357 var links = head.getElementsByTagName("link");
358 var re = /\bicon\b/i;
359 for (var i = 0; i < links.length; i++) {
360 if (re.test(links[i].rel))
362 head.removeChild(links[i]);
366 var link = document.createElement("link");
368 link.href = data.url;
369 // type attribute is important for Google Chrome browser
370 link.type = data.type;
372 head.appendChild(link);