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);
69 // set response time from ajax response
70 if(typeof(r.responseTime) != 'undefined'){
71 var rt = document.getElementById('responseTime');
73 rt.innerHTML = r.responseTime;
77 SUGAR.ajaxUI.showErrorMessage(o.responseText);
80 showErrorMessage : function(errorMessage)
82 if (!SUGAR.ajaxUI.errorPanel) {
83 SUGAR.ajaxUI.errorPanel = new YAHOO.widget.Panel("ajaxUIErrorPanel", {
86 constraintoviewport: true,
92 var panel = SUGAR.ajaxUI.errorPanel;
93 panel.setHeader(SUGAR.language.get('app_strings','ERR_AJAX_LOAD')) ;
94 panel.setBody('<iframe id="ajaxErrorFrame" style="width:780px;height:550px;border:none;marginheight="0" marginwidth="0" frameborder="0""></iframe>');
95 panel.setFooter(SUGAR.language.get('app_strings','ERR_AJAX_LOAD_FOOTER')) ;
96 panel.render(document.body);
99 var f = document.getElementById("ajaxErrorFrame");
100 return f != null && f.contentWindow != null && f.contentWindow.document != null;
102 document.getElementById("ajaxErrorFrame").contentWindow.document.body.innerHTML = errorMessage;
103 window.setTimeout('throw "AjaxUI error parsing response"', 300);
108 throw "AjaxUI error parsing response";
110 canAjaxLoadModule : function(module)
112 // Return false if ajax ui is completely disabled
113 if(typeof(SUGAR.config.disableAjaxUI) != 'undefined' && SUGAR.config.disableAjaxUI == true){
117 var bannedModules = SUGAR.config.stockAjaxBannedModules;
118 //If banned modules isn't there, we are probably on a page that isn't ajaxUI compatible
119 if (typeof(bannedModules) == 'undefined')
121 // Mechanism to allow for overriding or adding to this list
122 if(typeof(SUGAR.config.addAjaxBannedModules) != 'undefined'){
123 bannedModules.concat(SUGAR.config.addAjaxBannedModules);
125 if(typeof(SUGAR.config.overrideAjaxBannedModules) != 'undefined'){
126 bannedModules = SUGAR.config.overrideAjaxBannedModules;
129 return SUGAR.util.arrayIndexOf(bannedModules, module) == -1;
132 loadContent : function(url, params)
134 if(YAHOO.lang.trim(url) != "")
136 //Don't ajax load certain modules
137 var mRegex = /module=([^&]*)/.exec(url);
138 var module = mRegex ? mRegex[1] : false;
139 if (module && SUGAR.ajaxUI.canAjaxLoadModule(module))
141 YAHOO.util.History.navigate('ajaxUILoc', url);
143 window.location = url;
150 if(YAHOO.lang.trim(url) != "")
152 var con = YAHOO.util.Connect, ui = SUGAR.ajaxUI;
153 if (ui.lastURL == url)
155 var inAjaxUI = /action=ajaxui/.exec(window.location);
156 if (typeof (window.onbeforeunload) == "function" && window.onbeforeunload())
158 //If there is an unload function, we need to check it ourselves
159 if (!confirm(window.onbeforeunload()))
163 //User doesn't want to navigate
164 window.location.hash = "";
168 YAHOO.util.History.navigate('ajaxUILoc', ui.lastURL);
172 window.onbeforeunload = null;
174 if (ui.lastCall && con.isCallInProgress(ui.lastCall)) {
175 con.abort(ui.lastCall);
177 var mRegex = /module=([^&]*)/.exec(url);
178 var module = mRegex ? mRegex[1] : false;
179 //If we can't ajax load the module (blacklisted), set the URL directly.
180 if (!ui.canAjaxLoadModule(module)) {
181 window.location = url;
186 var loadLanguageJS = '';
187 if(module && typeof(SUGAR.language.languages[module]) == 'undefined'){
188 loadLanguageJS = '&loadLanguageJS=1';
192 //If we aren't in the ajaxUI yet, we need to reload the page to get setup properly
194 window.location.replace("index.php?action=ajaxui#ajaxUILoc=" + encodeURIComponent(url));
196 //if we use replace under IE, it will cache the page as the replaced version and thus no longer load the previous page.
197 window.location.hash = "#";
198 window.location.assign("index.php?action=ajaxui#ajaxUILoc=" + encodeURIComponent(url));
202 SUGAR.ajaxUI.showLoadingPanel();
203 ui.lastCall = YAHOO.util.Connect.asyncRequest('GET', url + '&ajax_load=1' + loadLanguageJS, {
204 success: SUGAR.ajaxUI.callback,
206 SUGAR.ajaxUI.hideLoadingPanel();
207 SUGAR.ajaxUI.showErrorMessage(SUGAR.language.get('app_strings','ERR_AJAX_LOAD_FAILURE'));
214 submitForm : function(formname, params)
216 var con = YAHOO.util.Connect, SA = SUGAR.ajaxUI;
217 if (SA.lastCall && con.isCallInProgress(SA.lastCall)) {
218 con.abort(SA.lastCall);
220 //Reset the EmailAddressWidget before loading a new page
222 //Don't ajax load certain modules
223 var form = YAHOO.util.Dom.get(formname) || document.forms[formname];
224 if (SA.canAjaxLoadModule(form.module.value)
225 //Do not try to submit a form that contains a file input via ajax.
226 && typeof(YAHOO.util.Selector.query("input[type=file]", form)[0]) == "undefined"
227 //Do not try to ajax submit a form if the ajaxUI is not initialized
228 && /action=ajaxui/.exec(window.location))
230 var string = con.setForm(form);
231 var baseUrl = "index.php?action=ajaxui#ajaxUILoc=";
233 //Use POST for long forms and GET for short forms (GET allow resubmit via reload)
234 if(string.length > 200)
236 SUGAR.ajaxUI.showLoadingPanel();
237 form.onsubmit = function(){ return true; };
240 con.resetFormState();
241 window.location = baseUrl + encodeURIComponent("index.php?" + string);
250 cleanGlobals : function()
253 QSProcessedFieldsArray = {};
255 //Reset the EmailAddressWidget before loading a new page
256 if (SUGAR.EmailAddressWidget){
257 SUGAR.EmailAddressWidget.instances = {};
258 SUGAR.EmailAddressWidget.count = {};
260 YAHOO.util.Event.removeListener(window, 'resize');
261 //Hide any connector dialogs
262 if(typeof(dialog) != 'undefined' && typeof(dialog.destroy) == 'function'){
268 firstLoad : function()
270 //Setup Browser History
271 var url = YAHOO.util.History.getBookmarkedState('ajaxUILoc');
272 var aRegex = /action=([^&#]*)/.exec(window.location);
273 var action = aRegex ? aRegex[1] : false;
274 var mRegex = /module=([^&#]*)/.exec(window.location);
275 var module = mRegex ? mRegex[1] : false;
276 if (module != "ModuleBuilder")
278 var go = url != null || action == "ajaxui";
279 url = url ? url : 'index.php?module=Home&action=index';
280 YAHOO.util.History.register('ajaxUILoc', url, SUGAR.ajaxUI.go);
281 YAHOO.util.History.initialize("ajaxUI-history-field", "ajaxUI-history-iframe");
282 SUGAR.ajaxUI.hist_loaded = true;
284 SUGAR.ajaxUI.go(url);
286 SUGAR_callsInProgress--;
290 var url = YAHOO.util.History.getBookmarkedState('ajaxUILoc');
291 SUGAR.util.openWindow(
294 'menubar=1,status=0,resizable=1,scrollbars=1,toolbar=0,location=1'
297 showLoadingPanel: function()
299 if (!SUGAR.ajaxUI.loadingPanel)
301 SUGAR.ajaxUI.loadingPanel = new YAHOO.widget.Panel("ajaxloading",
307 constraintoviewport:false,
311 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>');
312 SUGAR.ajaxUI.loadingPanel.render(document.body);
315 if (document.getElementById('ajaxloading_c'))
316 document.getElementById('ajaxloading_c').style.display = '';
318 SUGAR.ajaxUI.loadingPanel.show();
321 hideLoadingPanel: function()
323 SUGAR.ajaxUI.loadingPanel.hide();
325 if (document.getElementById('ajaxloading_c'))
326 document.getElementById('ajaxloading_c').style.display = 'none';