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 ********************************************************************************/
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);
53 SUGAR.themes.setModuleTabs(r.moduleList);
57 document.title = html_entity_decode(r.title);
61 action_sugar_grp1 = r.action;
64 var c = document.getElementById("content");
66 SUGAR.util.evalScript(cont);
67 // set response time from ajax response
68 if(typeof(r.responseTime) != 'undefined'){
69 var rt = document.getElementById('responseTime');
71 rt.innerHTML = r.responseTime;
75 SUGAR.ajaxUI.showErrorMessage(o.responseText);
78 showErrorMessage : function(errorMessage)
80 if (!SUGAR.ajaxUI.errorPanel) {
81 SUGAR.ajaxUI.errorPanel = new YAHOO.widget.Panel("ajaxUIErrorPanel", {
84 constraintoviewport: true,
90 var panel = SUGAR.ajaxUI.errorPanel;
91 panel.setHeader(SUGAR.language.get('app_strings','ERR_AJAX_LOAD')) ;
92 panel.setBody('<iframe id="ajaxErrorFrame" style="width:780px;height:550px;border:none;marginheight="0" marginwidth="0" frameborder="0""></iframe>');
93 panel.setFooter(SUGAR.language.get('app_strings','ERR_AJAX_LOAD_FOOTER')) ;
94 panel.render(document.body);
97 var f = document.getElementById("ajaxErrorFrame");
98 return f != null && f.contentWindow != null && f.contentWindow.document != null;
100 document.getElementById("ajaxErrorFrame").contentWindow.document.body.innerHTML = errorMessage;
101 window.setTimeout('throw "AjaxUI error parsing response"', 300);
106 throw "AjaxUI error parsing response";
108 canAjaxLoadModule : function(module)
110 // Return false if ajax ui is completely disabled
111 if(typeof(SUGAR.config.disableAjaxUI) != 'undefined' && SUGAR.config.disableAjaxUI == true){
115 var bannedModules = SUGAR.config.stockAjaxBannedModules;
116 //If banned modules isn't there, we are probably on a page that isn't ajaxUI compatible
117 if (typeof(bannedModules) == 'undefined')
119 // Mechanism to allow for overriding or adding to this list
120 if(typeof(SUGAR.config.addAjaxBannedModules) != 'undefined'){
121 bannedModules.concat(SUGAR.config.addAjaxBannedModules);
123 if(typeof(SUGAR.config.overrideAjaxBannedModules) != 'undefined'){
124 bannedModules = SUGAR.config.overrideAjaxBannedModules;
127 return SUGAR.util.arrayIndexOf(bannedModules, module) == -1;
130 loadContent : function(url, params)
132 if(YAHOO.lang.trim(url) != "")
134 //Don't ajax load certain modules
135 var mRegex = /module=([^&]*)/.exec(url);
136 var module = mRegex ? mRegex[1] : false;
137 if (module && SUGAR.ajaxUI.canAjaxLoadModule(module))
139 YAHOO.util.History.navigate('ajaxUILoc', url);
141 window.location = url;
148 if(YAHOO.lang.trim(url) != "")
150 var con = YAHOO.util.Connect, ui = SUGAR.ajaxUI;
151 if (ui.lastURL == url)
153 var inAjaxUI = /action=ajaxui/.exec(window.location);
154 if (inAjaxUI && typeof (window.onbeforeunload) == "function"
155 && window.onbeforeunload() && !confirm(window.onbeforeunload()))
157 YAHOO.util.History.navigate('ajaxUILoc', ui.lastURL);
160 if (ui.lastCall && con.isCallInProgress(ui.lastCall)) {
161 con.abort(ui.lastCall);
163 var mRegex = /module=([^&]*)/.exec(url);
164 var module = mRegex ? mRegex[1] : false;
165 //If we can't ajax load the module (blacklisted), set the URL directly.
166 if (!ui.canAjaxLoadModule(module)) {
167 window.location = url;
172 var loadLanguageJS = '';
173 if(module && typeof(SUGAR.language.languages[module]) == 'undefined'){
174 loadLanguageJS = '&loadLanguageJS=1';
178 //If we aren't in the ajaxUI yet, we need to reload the page to get setup properly
180 window.location.replace("index.php?action=ajaxui#ajaxUILoc=" + encodeURIComponent(url));
182 //if we use replace under IE, it will cache the page as the replaced version and thus no longer load the previous page.
183 window.location.hash = "#";
184 window.location.assign("index.php?action=ajaxui#ajaxUILoc=" + encodeURIComponent(url));
188 SUGAR.ajaxUI.showLoadingPanel();
189 ui.lastCall = YAHOO.util.Connect.asyncRequest('GET', url + '&ajax_load=1' + loadLanguageJS, {
190 success: SUGAR.ajaxUI.callback,
192 SUGAR.ajaxUI.hideLoadingPanel();
193 SUGAR.ajaxUI.showErrorMessage(SUGAR.language.get('app_strings','ERR_AJAX_LOAD_FAILURE'));
200 submitForm : function(formname, params)
202 var con = YAHOO.util.Connect, SA = SUGAR.ajaxUI;
203 if (SA.lastCall && con.isCallInProgress(SA.lastCall)) {
204 con.abort(SA.lastCall);
206 //Reset the EmailAddressWidget before loading a new page
208 //Don't ajax load certain modules
209 var form = YAHOO.util.Dom.get(formname) || document.forms[formname];
210 if (SA.canAjaxLoadModule(form.module.value)
211 //Do not try to submit a form that contains a file input via ajax.
212 && typeof(YAHOO.util.Selector.query("input[type=file]", form)[0]) == "undefined"
213 //Do not try to ajax submit a form if the ajaxUI is not initialized
214 && /action=ajaxui/.exec(window.location))
216 var string = con.setForm(form);
217 var baseUrl = "index.php?action=ajaxui#ajaxUILoc=";
219 //Use POST for long forms and GET for short forms (GET allow resubmit via reload)
220 if(string.length > 200)
222 SUGAR.ajaxUI.showLoadingPanel();
223 form.onsubmit = function(){ return true; };
226 con.resetFormState();
227 window.location = baseUrl + encodeURIComponent("index.php?" + string);
236 cleanGlobals : function()
239 QSProcessedFieldsArray = {};
241 //Reset the EmailAddressWidget before loading a new page
242 if (SUGAR.EmailAddressWidget){
243 SUGAR.EmailAddressWidget.instances = {};
244 SUGAR.EmailAddressWidget.count = {};
246 YAHOO.util.Event.removeListener(window, 'resize');
247 //Hide any connector dialogs
248 if(typeof(dialog) != 'undefined' && typeof(dialog.destroy) == 'function'){
254 firstLoad : function()
256 //Setup Browser History
257 var url = YAHOO.util.History.getBookmarkedState('ajaxUILoc');
258 var aRegex = /action=([^&#]*)/.exec(window.location);
259 var action = aRegex ? aRegex[1] : false;
260 var mRegex = /module=([^&#]*)/.exec(window.location);
261 var module = mRegex ? mRegex[1] : false;
262 if (module != "ModuleBuilder")
264 var go = url != null || action == "ajaxui";
265 url = url ? url : 'index.php?module=Home&action=index';
266 YAHOO.util.History.register('ajaxUILoc', url, SUGAR.ajaxUI.go);
267 YAHOO.util.History.initialize("ajaxUI-history-field", "ajaxUI-history-iframe");
268 SUGAR.ajaxUI.hist_loaded = true;
270 SUGAR.ajaxUI.go(url);
272 SUGAR_callsInProgress--;
276 var url = YAHOO.util.History.getBookmarkedState('ajaxUILoc');
277 SUGAR.util.openWindow(
280 'menubar=1,status=0,resizable=1,scrollbars=1,toolbar=0,location=1'
283 showLoadingPanel: function()
285 if (!SUGAR.ajaxUI.loadingPanel)
287 SUGAR.ajaxUI.loadingPanel = new YAHOO.widget.Panel("ajaxloading",
293 constraintoviewport:false,
297 SUGAR.ajaxUI.loadingPanel.setBody('<div id="loadingPage" align="center" style="vertical-align:middle;"><img src="' + SUGAR.themes.image_server + 'index.php?entryPoint=getImage&themeName='+SUGAR.themes.theme_name+'&imageName=img_loading.gif" align="absmiddle" /> <b>' + SUGAR.language.get('app_strings', 'LBL_LOADING_PAGE') +'</b></div>');
298 SUGAR.ajaxUI.loadingPanel.render(document.body);
301 if (document.getElementById('ajaxloading_c'))
302 document.getElementById('ajaxloading_c').style.display = '';
304 SUGAR.ajaxUI.loadingPanel.show();
307 hideLoadingPanel: function()
309 SUGAR.ajaxUI.loadingPanel.hide();
311 if (document.getElementById('ajaxloading_c'))
312 document.getElementById('ajaxloading_c').style.display = 'none';