+++ /dev/null
-/*\r
- * Ext JS Library 2.2.1\r
- * Copyright(c) 2006-2009, Ext JS, LLC.\r
- * licensing@extjs.com\r
- * \r
- * http://extjs.com/license\r
- */\r
-\r
-/**\r
- * @class Ext.Updater\r
- * @extends Ext.util.Observable\r
- * Provides AJAX-style update capabilities for Element objects. Updater can be used to {@link #update} an Element once,\r
- * or you can use {@link #startAutoRefresh} to set up an auto-updating Element on a specific interval.<br><br>\r
- * Usage:<br>\r
- * <pre><code>\r
- * // Get it from a Ext.Element object\r
- * var el = Ext.get("foo");\r
- * var mgr = el.getUpdater();\r
- * mgr.update({\r
- url: "http://myserver.com/index.php",\r
- params: {\r
- param1: "foo",\r
- param2: "bar"\r
- }\r
- * });\r
- * ...\r
- * mgr.formUpdate("myFormId", "http://myserver.com/index.php");\r
- * <br>\r
- * // or directly (returns the same Updater instance)\r
- * var mgr = new Ext.Updater("myElementId");\r
- * mgr.startAutoRefresh(60, "http://myserver.com/index.php");\r
- * mgr.on("update", myFcnNeedsToKnow);\r
- * <br>\r
- * // short handed call directly from the element object\r
- * Ext.get("foo").load({\r
- url: "bar.php",\r
- scripts: true,\r
- params: "param1=foo&param2=bar",\r
- text: "Loading Foo..."\r
- * });\r
- * </code></pre>\r
- * @constructor\r
- * Create new Updater directly.\r
- * @param {Mixed} el The element to update\r
- * @param {Boolean} forceNew (optional) By default the constructor checks to see if the passed element already\r
- * has an Updater and if it does it returns the same instance. This will skip that check (useful for extending this class).\r
- */\r
-Ext.Updater = Ext.extend(Ext.util.Observable, {\r
- constructor: function(el, forceNew){\r
- el = Ext.get(el);\r
- if(!forceNew && el.updateManager){\r
- return el.updateManager;\r
- }\r
- /**\r
- * The Element object\r
- * @type Ext.Element\r
- */\r
- this.el = el;\r
- /**\r
- * Cached url to use for refreshes. Overwritten every time update() is called unless "discardUrl" param is set to true.\r
- * @type String\r
- */\r
- this.defaultUrl = null;\r
-\r
- this.addEvents(\r
- /**\r
- * @event beforeupdate\r
- * Fired before an update is made, return false from your handler and the update is cancelled.\r
- * @param {Ext.Element} el\r
- * @param {String/Object/Function} url\r
- * @param {String/Object} params\r
- */\r
- "beforeupdate",\r
- /**\r
- * @event update\r
- * Fired after successful update is made.\r
- * @param {Ext.Element} el\r
- * @param {Object} oResponseObject The response Object\r
- */\r
- "update",\r
- /**\r
- * @event failure\r
- * Fired on update failure.\r
- * @param {Ext.Element} el\r
- * @param {Object} oResponseObject The response Object\r
- */\r
- "failure"\r
- );\r
- var d = Ext.Updater.defaults;\r
- /**\r
- * Blank page URL to use with SSL file uploads (defaults to {@link Ext.Updater.defaults#sslBlankUrl}).\r
- * @type String\r
- */\r
- this.sslBlankUrl = d.sslBlankUrl;\r
- /**\r
- * Whether to append unique parameter on get request to disable caching (defaults to {@link Ext.Updater.defaults#disableCaching}).\r
- * @type Boolean\r
- */\r
- this.disableCaching = d.disableCaching;\r
- /**\r
- * Text for loading indicator (defaults to {@link Ext.Updater.defaults#indicatorText}).\r
- * @type String\r
- */\r
- this.indicatorText = d.indicatorText;\r
- /**\r
- * Whether to show indicatorText when loading (defaults to {@link Ext.Updater.defaults#showLoadIndicator}).\r
- * @type String\r
- */\r
- this.showLoadIndicator = d.showLoadIndicator;\r
- /**\r
- * Timeout for requests or form posts in seconds (defaults to {@link Ext.Updater.defaults#timeout}).\r
- * @type Number\r
- */\r
- this.timeout = d.timeout;\r
- /**\r
- * True to process scripts in the output (defaults to {@link Ext.Updater.defaults#loadScripts}).\r
- * @type Boolean\r
- */\r
- this.loadScripts = d.loadScripts;\r
- /**\r
- * Transaction object of the current executing transaction, or null if there is no active transaction.\r
- */\r
- this.transaction = null;\r
- /**\r
- * Delegate for refresh() prebound to "this", use myUpdater.refreshDelegate.createCallback(arg1, arg2) to bind arguments\r
- * @type Function\r
- */\r
- this.refreshDelegate = this.refresh.createDelegate(this);\r
- /**\r
- * Delegate for update() prebound to "this", use myUpdater.updateDelegate.createCallback(arg1, arg2) to bind arguments\r
- * @type Function\r
- */\r
- this.updateDelegate = this.update.createDelegate(this);\r
- /**\r
- * Delegate for formUpdate() prebound to "this", use myUpdater.formUpdateDelegate.createCallback(arg1, arg2) to bind arguments\r
- * @type Function\r
- */\r
- this.formUpdateDelegate = this.formUpdate.createDelegate(this);\r
-\r
- if(!this.renderer){\r
- /**\r
- * The renderer for this Updater (defaults to {@link Ext.Updater.BasicRenderer}).\r
- */\r
- this.renderer = this.getDefaultRenderer();\r
- }\r
- Ext.Updater.superclass.constructor.call(this);\r
- },\r
- /**\r
- * This is an overrideable method which returns a reference to a default\r
- * renderer class if none is specified when creating the Ext.Updater.\r
- * Defaults to {@link Ext.Updater.BasicRenderer}\r
- */\r
- getDefaultRenderer: function() {\r
- return new Ext.Updater.BasicRenderer();\r
- },\r
- /**\r
- * Get the Element this Updater is bound to\r
- * @return {Ext.Element} The element\r
- */\r
- getEl : function(){\r
- return this.el;\r
- },\r
-\r
- /**\r
- * Performs an <b>asynchronous</b> request, updating this element with the response.\r
- * If params are specified it uses POST, otherwise it uses GET.<br><br>\r
- * <b>Note:</b> Due to the asynchronous nature of remote server requests, the Element\r
- * will not have been fully updated when the function returns. To post-process the returned\r
- * data, use the callback option, or an <b><tt>update</tt></b> event handler.\r
- * @param {Object} options A config object containing any of the following options:<ul>\r
- * <li>url : <b>String/Function</b><p class="sub-desc">The URL to request or a function which\r
- * <i>returns</i> the URL (defaults to the value of {@link Ext.Ajax#url} if not specified).</p></li>\r
- * <li>method : <b>String</b><p class="sub-desc">The HTTP method to\r
- * use. Defaults to POST if the <tt>params</tt> argument is present, otherwise GET.</p></li>\r
- * <li>params : <b>String/Object/Function</b><p class="sub-desc">The\r
- * parameters to pass to the server (defaults to none). These may be specified as a url-encoded\r
- * string, or as an object containing properties which represent parameters,\r
- * or as a function, which returns such an object.</p></li>\r
- * <li>scripts : <b>Boolean</b><p class="sub-desc">If <tt>true</tt>\r
- * any <script> tags embedded in the response text will be extracted\r
- * and executed (defaults to {@link Ext.Updater.defaults#loadScripts}). If this option is specified,\r
- * the callback will be called <i>after</i> the execution of the scripts.</p></li>\r
- * <li>callback : <b>Function</b><p class="sub-desc">A function to\r
- * be called when the response from the server arrives. The following\r
- * parameters are passed:<ul>\r
- * <li><b>el</b> : Ext.Element<p class="sub-desc">The Element being updated.</p></li>\r
- * <li><b>success</b> : Boolean<p class="sub-desc">True for success, false for failure.</p></li>\r
- * <li><b>response</b> : XMLHttpRequest<p class="sub-desc">The XMLHttpRequest which processed the update.</p></li>\r
- * <li><b>options</b> : Object<p class="sub-desc">The config object passed to the update call.</p></li></ul>\r
- * </p></li>\r
- * <li>scope : <b>Object</b><p class="sub-desc">The scope in which\r
- * to execute the callback (The callback's <tt>this</tt> reference.) If the\r
- * <tt>params</tt> argument is a function, this scope is used for that function also.</p></li>\r
- * <li>discardUrl : <b>Boolean</b><p class="sub-desc">By default, the URL of this request becomes\r
- * the default URL for this Updater object, and will be subsequently used in {@link #refresh}\r
- * calls. To bypass this behavior, pass <tt>discardUrl:true</tt> (defaults to false).</p></li>\r
- * <li>timeout : <b>Number</b><p class="sub-desc">The number of seconds to wait for a response before\r
- * timing out (defaults to {@link Ext.Updater.defaults#timeout}).</p></li>\r
- * <li>text : <b>String</b><p class="sub-desc">The text to use as the innerHTML of the\r
- * {@link Ext.Updater.defaults#indicatorText} div (defaults to 'Loading...'). To replace the entire div, not\r
- * just the text, override {@link Ext.Updater.defaults#indicatorText} directly.</p></li>\r
- * <li>nocache : <b>Boolean</b><p class="sub-desc">Only needed for GET\r
- * requests, this option causes an extra, auto-generated parameter to be appended to the request\r
- * to defeat caching (defaults to {@link Ext.Updater.defaults#disableCaching}).</p></li></ul>\r
- * <p>\r
- * For example:\r
-<pre><code>\r
-um.update({\r
- url: "your-url.php",\r
- params: {param1: "foo", param2: "bar"}, // or a URL encoded string\r
- callback: yourFunction,\r
- scope: yourObject, //(optional scope)\r
- discardUrl: true,\r
- nocache: true,\r
- text: "Loading...",\r
- timeout: 60,\r
- scripts: false // Save time by avoiding RegExp execution.\r
-});\r
-</code></pre>\r
- */\r
- update : function(url, params, callback, discardUrl){\r
- if(this.fireEvent("beforeupdate", this.el, url, params) !== false){\r
- var cfg, callerScope;\r
- if(typeof url == "object"){ // must be config object\r
- cfg = url;\r
- url = cfg.url;\r
- params = params || cfg.params;\r
- callback = callback || cfg.callback;\r
- discardUrl = discardUrl || cfg.discardUrl;\r
- callerScope = cfg.scope;\r
- if(typeof cfg.nocache != "undefined"){this.disableCaching = cfg.nocache;};\r
- if(typeof cfg.text != "undefined"){this.indicatorText = '<div class="loading-indicator">'+cfg.text+"</div>";};\r
- if(typeof cfg.scripts != "undefined"){this.loadScripts = cfg.scripts;};\r
- if(typeof cfg.timeout != "undefined"){this.timeout = cfg.timeout;};\r
- }\r
- this.showLoading();\r
-\r
- if(!discardUrl){\r
- this.defaultUrl = url;\r
- }\r
- if(typeof url == "function"){\r
- url = url.call(this);\r
- }\r
-\r
- var o = Ext.apply({}, {\r
- url : url,\r
- params: (typeof params == "function" && callerScope) ? params.createDelegate(callerScope) : params,\r
- success: this.processSuccess,\r
- failure: this.processFailure,\r
- scope: this,\r
- callback: undefined,\r
- timeout: (this.timeout*1000),\r
- disableCaching: this.disableCaching,\r
- argument: {\r
- "options": cfg,\r
- "url": url,\r
- "form": null,\r
- "callback": callback,\r
- "scope": callerScope || window,\r
- "params": params\r
- }\r
- }, cfg);\r
-\r
- this.transaction = Ext.Ajax.request(o);\r
- }\r
- },\r
-\r
- /**\r
- * <p>Performs an async form post, updating this element with the response. If the form has the attribute\r
- * enctype="<a href="http://www.faqs.org/rfcs/rfc2388.html">multipart/form-data</a>", it assumes it's a file upload.\r
- * Uses this.sslBlankUrl for SSL file uploads to prevent IE security warning.</p>\r
- * <p>File uploads are not performed using normal "Ajax" techniques, that is they are <b>not</b>\r
- * performed using XMLHttpRequests. Instead the form is submitted in the standard manner with the\r
- * DOM <tt><form></tt> element temporarily modified to have its\r
- * <a href="http://www.w3.org/TR/REC-html40/present/frames.html#adef-target">target</a> set to refer\r
- * to a dynamically generated, hidden <tt><iframe></tt> which is inserted into the document\r
- * but removed after the return data has been gathered.</p>\r
- * <p>Be aware that file upload packets, sent with the content type <a href="http://www.faqs.org/rfcs/rfc2388.html">multipart/form-data</a>\r
- * and some server technologies (notably JEE) may require some custom processing in order to\r
- * retrieve parameter names and parameter values from the packet content.</p>\r
- * @param {String/HTMLElement} form The form Id or form element\r
- * @param {String} url (optional) The url to pass the form to. If omitted the action attribute on the form will be used.\r
- * @param {Boolean} reset (optional) Whether to try to reset the form after the update\r
- * @param {Function} callback (optional) Callback when transaction is complete. The following\r
- * parameters are passed:<ul>\r
- * <li><b>el</b> : Ext.Element<p class="sub-desc">The Element being updated.</p></li>\r
- * <li><b>success</b> : Boolean<p class="sub-desc">True for success, false for failure.</p></li>\r
- * <li><b>response</b> : XMLHttpRequest<p class="sub-desc">The XMLHttpRequest which processed the update.</p></li></ul>\r
- */\r
- formUpdate : function(form, url, reset, callback){\r
- if(this.fireEvent("beforeupdate", this.el, form, url) !== false){\r
- if(typeof url == "function"){\r
- url = url.call(this);\r
- }\r
- form = Ext.getDom(form)\r
- this.transaction = Ext.Ajax.request({\r
- form: form,\r
- url:url,\r
- success: this.processSuccess,\r
- failure: this.processFailure,\r
- scope: this,\r
- timeout: (this.timeout*1000),\r
- argument: {\r
- "url": url,\r
- "form": form,\r
- "callback": callback,\r
- "reset": reset\r
- }\r
- });\r
- this.showLoading.defer(1, this);\r
- }\r
- },\r
-\r
- /**\r
- * Refresh the element with the last used url or defaultUrl. If there is no url, it returns immediately\r
- * @param {Function} callback (optional) Callback when transaction is complete - called with signature (oElement, bSuccess)\r
- */\r
- refresh : function(callback){\r
- if(this.defaultUrl == null){\r
- return;\r
- }\r
- this.update(this.defaultUrl, null, callback, true);\r
- },\r
-\r
- /**\r
- * Set this element to auto refresh. Can be canceled by calling {@link #stopAutoRefresh}.\r
- * @param {Number} interval How often to update (in seconds).\r
- * @param {String/Object/Function} url (optional) The url for this request, a config object in the same format\r
- * supported by {@link #load}, or a function to call to get the url (defaults to the last used url). Note that while\r
- * the url used in a load call can be reused by this method, other load config options will not be reused and must be\r
- * sepcified as part of a config object passed as this paramter if needed.\r
- * @param {String/Object} params (optional) The parameters to pass as either a url encoded string\r
- * "¶m1=1¶m2=2" or as an object {param1: 1, param2: 2}\r
- * @param {Function} callback (optional) Callback when transaction is complete - called with signature (oElement, bSuccess)\r
- * @param {Boolean} refreshNow (optional) Whether to execute the refresh now, or wait the interval\r
- */\r
- startAutoRefresh : function(interval, url, params, callback, refreshNow){\r
- if(refreshNow){\r
- this.update(url || this.defaultUrl, params, callback, true);\r
- }\r
- if(this.autoRefreshProcId){\r
- clearInterval(this.autoRefreshProcId);\r
- }\r
- this.autoRefreshProcId = setInterval(this.update.createDelegate(this, [url || this.defaultUrl, params, callback, true]), interval*1000);\r
- },\r
-\r
- /**\r
- * Stop auto refresh on this element.\r
- */\r
- stopAutoRefresh : function(){\r
- if(this.autoRefreshProcId){\r
- clearInterval(this.autoRefreshProcId);\r
- delete this.autoRefreshProcId;\r
- }\r
- },\r
-\r
- /**\r
- * Returns true if the Updater is currently set to auto refresh its content (see {@link #startAutoRefresh}), otherwise false.\r
- */\r
- isAutoRefreshing : function(){\r
- return this.autoRefreshProcId ? true : false;\r
- },\r
-\r
- /**\r
- * Display the element's "loading" state. By default, the element is updated with {@link #indicatorText}. This\r
- * method may be overridden to perform a custom action while this Updater is actively updating its contents.\r
- */\r
- showLoading : function(){\r
- if(this.showLoadIndicator){\r
- this.el.update(this.indicatorText);\r
- }\r
- },\r
-\r
- // private\r
- processSuccess : function(response){\r
- this.transaction = null;\r
- if(response.argument.form && response.argument.reset){\r
- try{ // put in try/catch since some older FF releases had problems with this\r
- response.argument.form.reset();\r
- }catch(e){}\r
- }\r
- if(this.loadScripts){\r
- this.renderer.render(this.el, response, this,\r
- this.updateComplete.createDelegate(this, [response]));\r
- }else{\r
- this.renderer.render(this.el, response, this);\r
- this.updateComplete(response);\r
- }\r
- },\r
-\r
- // private\r
- updateComplete : function(response){\r
- this.fireEvent("update", this.el, response);\r
- if(typeof response.argument.callback == "function"){\r
- response.argument.callback.call(response.argument.scope, this.el, true, response, response.argument.options);\r
- }\r
- },\r
-\r
- // private\r
- processFailure : function(response){\r
- this.transaction = null;\r
- this.fireEvent("failure", this.el, response);\r
- if(typeof response.argument.callback == "function"){\r
- response.argument.callback.call(response.argument.scope, this.el, false, response, response.argument.options);\r
- }\r
- },\r
-\r
- /**\r
- * Sets the content renderer for this Updater. See {@link Ext.Updater.BasicRenderer#render} for more details.\r
- * @param {Object} renderer The object implementing the render() method\r
- */\r
- setRenderer : function(renderer){\r
- this.renderer = renderer;\r
- },\r
-\r
- /**\r
- * Returns the content renderer for this Updater. See {@link Ext.Updater.BasicRenderer#render} for more details.\r
- * @return {Object}\r
- */\r
- getRenderer : function(){\r
- return this.renderer;\r
- },\r
-\r
- /**\r
- * Sets the default URL used for updates.\r
- * @param {String/Function} defaultUrl The url or a function to call to get the url\r
- */\r
- setDefaultUrl : function(defaultUrl){\r
- this.defaultUrl = defaultUrl;\r
- },\r
-\r
- /**\r
- * Aborts the currently executing transaction, if any.\r
- */\r
- abort : function(){\r
- if(this.transaction){\r
- Ext.Ajax.abort(this.transaction);\r
- }\r
- },\r
-\r
- /**\r
- * Returns true if an update is in progress, otherwise false.\r
- * @return {Boolean}\r
- */\r
- isUpdating : function(){\r
- if(this.transaction){\r
- return Ext.Ajax.isLoading(this.transaction);\r
- }\r
- return false;\r
- }\r
-});\r
-\r
-/**\r
- * @class Ext.Updater.defaults\r
- * The defaults collection enables customizing the default properties of Updater\r
- */\r
- Ext.Updater.defaults = {\r
- /**\r
- * Timeout for requests or form posts in seconds (defaults to 30 seconds).\r
- * @type Number\r
- */\r
- timeout : 30,\r
- /**\r
- * True to process scripts by default (defaults to false).\r
- * @type Boolean\r
- */\r
- loadScripts : false,\r
- /**\r
- * Blank page URL to use with SSL file uploads (defaults to {@link Ext#SSL_SECURE_URL} if set, or "javascript:false").\r
- * @type String\r
- */\r
- sslBlankUrl : (Ext.SSL_SECURE_URL || "javascript:false"),\r
- /**\r
- * True to append a unique parameter to GET requests to disable caching (defaults to false).\r
- * @type Boolean\r
- */\r
- disableCaching : false,\r
- /**\r
- * Whether or not to show {@link #indicatorText} during loading (defaults to true).\r
- * @type Boolean\r
- */\r
- showLoadIndicator : true,\r
- /**\r
- * Text for loading indicator (defaults to '<div class="loading-indicator">Loading...</div>').\r
- * @type String\r
- */\r
- indicatorText : '<div class="loading-indicator">Loading...</div>'\r
- };\r
-\r
-/**\r
- * Static convenience method. <b>This method is deprecated in favor of el.load({url:'foo.php', ...})</b>.\r
- * Usage:\r
- * <pre><code>Ext.Updater.updateElement("my-div", "stuff.php");</code></pre>\r
- * @param {Mixed} el The element to update\r
- * @param {String} url The url\r
- * @param {String/Object} params (optional) Url encoded param string or an object of name/value pairs\r
- * @param {Object} options (optional) A config object with any of the Updater properties you want to set - for\r
- * example: {disableCaching:true, indicatorText: "Loading data..."}\r
- * @static\r
- * @deprecated\r
- * @member Ext.Updater\r
- */\r
-Ext.Updater.updateElement = function(el, url, params, options){\r
- var um = Ext.get(el).getUpdater();\r
- Ext.apply(um, options);\r
- um.update(url, params, options ? options.callback : null);\r
-};\r
-/**\r
- * @class Ext.Updater.BasicRenderer\r
- * Default Content renderer. Updates the elements innerHTML with the responseText.\r
- */\r
-Ext.Updater.BasicRenderer = function(){};\r
-\r
-Ext.Updater.BasicRenderer.prototype = {\r
- /**\r
- * This is called when the transaction is completed and it's time to update the element - The BasicRenderer\r
- * updates the elements innerHTML with the responseText - To perform a custom render (i.e. XML or JSON processing),\r
- * create an object with a "render(el, response)" method and pass it to setRenderer on the Updater.\r
- * @param {Ext.Element} el The element being rendered\r
- * @param {Object} response The XMLHttpRequest object\r
- * @param {Updater} updateManager The calling update manager\r
- * @param {Function} callback A callback that will need to be called if loadScripts is true on the Updater\r
- */\r
- render : function(el, response, updateManager, callback){\r
- el.update(response.responseText, updateManager.loadScripts, callback);\r
- }\r
-};\r
-\r
-Ext.UpdateManager = Ext.Updater;\r