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 ajaxStatus.hideStatus();
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;
63 //SUGAR.themes.setCurrentTab(r.menu);
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 if (!SUGAR.ajaxUI.errorPanel) {
76 SUGAR.ajaxUI.errorPanel = new YAHOO.widget.Panel("ajaxUIErrorPanel", {
79 constraintoviewport: true,
85 var panel = SUGAR.ajaxUI.errorPanel;
86 panel.setHeader( SUGAR.language.get('app_strings','ERR_AJAX_LOAD')) ;
87 panel.setBody('<iframe id="ajaxErrorFrame" style="width:780px;height:550px;border:none;marginheight="0" marginwidth="0" frameborder="0""></iframe>');
88 panel.render(document.body);
91 var f = document.getElementById("ajaxErrorFrame");
92 return f != null && f.contentWindow != null && f.contentWindow.document != null;
94 document.getElementById("ajaxErrorFrame").contentWindow.document.body.innerHTML = o.responseText;
95 window.setTimeout('throw "AjaxUI error parsing response"', 300);
100 throw "AjaxUI error parsing response";
104 canAjaxLoadModule : function(module)
106 // Return false if ajax ui is completely disabled
107 if(typeof(SUGAR.config.disableAjaxUI) != 'undefined' && SUGAR.config.disableAjaxUI == true){
111 var bannedModules = SUGAR.config.stockAjaxBannedModules;
112 //If banned modules isn't there, we are probably on a page that isn't ajaxUI compatible
113 if (typeof(bannedModules) == 'undefined')
115 // Mechanism to allow for overriding or adding to this list
116 if(typeof(SUGAR.config.addAjaxBannedModules) != 'undefined'){
117 bannedModules.concat(SUGAR.config.addAjaxBannedModules);
119 if(typeof(SUGAR.config.overrideAjaxBannedModules) != 'undefined'){
120 bannedModules = SUGAR.config.overrideAjaxBannedModules;
123 return SUGAR.util.arrayIndexOf(bannedModules, module) == -1;
126 loadContent : function(url, params)
128 if(YAHOO.lang.trim(url) != "")
130 //Don't ajax load certain modules
131 var mRegex = /module=([^&]*)/.exec(url);
132 var module = mRegex ? mRegex[1] : false;
133 if (module && SUGAR.ajaxUI.canAjaxLoadModule(module))
135 YAHOO.util.History.navigate('ajaxUILoc', url);
137 window.location = url;
144 if(YAHOO.lang.trim(url) != "")
146 var con = YAHOO.util.Connect, ui = SUGAR.ajaxUI;
147 if (ui.lastURL == url)
149 var inAjaxUI = /action=ajaxui/.exec(window.location);
150 if (inAjaxUI && typeof (window.onbeforeunload) == "function"
151 && window.onbeforeunload() && !confirm(window.onbeforeunload()))
153 YAHOO.util.History.navigate('ajaxUILoc', ui.lastURL);
156 if (ui.lastCall && con.isCallInProgress(ui.lastCall)) {
157 con.abort(ui.lastCall);
159 var mRegex = /module=([^&]*)/.exec(url);
160 var module = mRegex ? mRegex[1] : false;
161 //If we can't ajax load the module (blacklisted), set the URL directly.
162 if (!ui.canAjaxLoadModule(module)) {
163 window.location = url;
168 var loadLanguageJS = '';
169 if(module && typeof(SUGAR.language.languages[module]) == 'undefined'){
170 loadLanguageJS = '&loadLanguageJS=1';
174 //If we aren't in the ajaxUI yet, we need to reload the page to get setup properly
175 window.location = "index.php?action=ajaxui#ajaxUILoc=" + encodeURIComponent(url);
177 ajaxStatus.showStatus( SUGAR.language.get('app_strings','LBL_LOADING')) ;
178 ui.lastCall = YAHOO.util.Connect.asyncRequest('GET', url + '&ajax_load=1' + loadLanguageJS, {
179 success: SUGAR.ajaxUI.callback
185 submitForm : function(formname, params)
187 var con = YAHOO.util.Connect, SA = SUGAR.ajaxUI;
188 if (SA.lastCall && con.isCallInProgress(SA.lastCall)) {
189 con.abort(SA.lastCall);
191 //Reset the EmailAddressWidget before loading a new page
193 //Don't ajax load certain modules
194 var form = YAHOO.util.Dom.get(formname) || document.forms[formname];
195 if (SA.canAjaxLoadModule(form.module.value)
196 //Do not try to submit a form that contains a file input via ajax.
197 && typeof(YAHOO.util.Selector.query("input[type=file]", form)[0]) == "undefined"
198 //Do not try to ajax submit a form if the ajaxUI is not initialized
199 && /action=ajaxui/.exec(window.location))
201 var string = con.setForm(form);
202 var baseUrl = "index.php?action=ajaxui#ajaxUILoc=";
204 //Use POST for long forms and GET for short forms (GET allow resubmit via reload)
205 ajaxStatus.showStatus( SUGAR.language.get('app_strings','LBL_LOADING')) ;
206 if(string.length > 200)
208 con.asyncRequest('POST', 'index.php?ajax_load=1', {
211 window.location=baseUrl;
213 con.resetFormState();
214 window.location = baseUrl + encodeURIComponent("index.php?" + string);
223 cleanGlobals : function()
226 QSProcessedFieldsArray = {};
228 //Reset the EmailAddressWidget before loading a new page
229 if (SUGAR.EmailAddressWidget){
230 SUGAR.EmailAddressWidget.instances = {};
231 SUGAR.EmailAddressWidget.count = {};
233 YAHOO.util.Event.removeListener(window, 'resize');
236 firstLoad : function()
238 //Setup Browser History
239 var url = YAHOO.util.History.getBookmarkedState('ajaxUILoc');
240 var aRegex = /action=([^&]*)/.exec(window.location);
241 var action = aRegex ? aRegex[1] : false;
242 var mRegex = /module=([^&]*)/.exec(window.location);
243 var module = mRegex ? mRegex[1] : false;
244 if (module != "ModuleBuilder")
246 var go = url != null || action == "ajaxui";
247 url = url ? url : 'index.php?module=Home&action=index';
248 YAHOO.util.History.register('ajaxUILoc', url, SUGAR.ajaxUI.go);
249 YAHOO.util.History.initialize("ajaxUI-history-field", "ajaxUI-history-iframe");
250 SUGAR.ajaxUI.hist_loaded = true;
252 SUGAR.ajaxUI.go(url);
254 SUGAR_callsInProgress--;
258 var url = YAHOO.util.History.getBookmarkedState('ajaxUILoc');
259 SUGAR.util.openWindow(
262 'menubar=1,status=0,resizable=1,scrollbars=1,toolbar=0,location=1'