You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

549 lines
28 KiB

2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  5. <title>The source code</title>
  6. <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
  7. <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
  8. <style type="text/css">
  9. .highlight { display: block; background-color: #ddd; }
  10. </style>
  11. <script type="text/javascript">
  12. function highlight() {
  13. document.getElementById(location.hash.replace(/#/, "")).className = "highlight";
  14. }
  15. </script>
  16. </head>
  17. <body onload="prettyPrint(); highlight();">
  18. <pre class="prettyprint lang-js"><span id='Ext-Updater-method-constructor'><span id='Ext-Updater'>/**
  19. </span></span> * @class Ext.Updater
  20. * @extends Ext.util.Observable
  21. * Provides AJAX-style update capabilities for Element objects. Updater can be used to {@link #update}
  22. * an {@link Ext.Element} once, or you can use {@link #startAutoRefresh} to set up an auto-updating
  23. * {@link Ext.Element Element} on a specific interval.&lt;br&gt;&lt;br&gt;
  24. * Usage:&lt;br&gt;
  25. * &lt;pre&gt;&lt;code&gt;
  26. * var el = Ext.get(&quot;foo&quot;); // Get Ext.Element object
  27. * var mgr = el.getUpdater();
  28. * mgr.update({
  29. url: &quot;http://myserver.com/index.php&quot;,
  30. params: {
  31. param1: &quot;foo&quot;,
  32. param2: &quot;bar&quot;
  33. }
  34. * });
  35. * ...
  36. * mgr.formUpdate(&quot;myFormId&quot;, &quot;http://myserver.com/index.php&quot;);
  37. * &lt;br&gt;
  38. * // or directly (returns the same Updater instance)
  39. * var mgr = new Ext.Updater(&quot;myElementId&quot;);
  40. * mgr.startAutoRefresh(60, &quot;http://myserver.com/index.php&quot;);
  41. * mgr.on(&quot;update&quot;, myFcnNeedsToKnow);
  42. * &lt;br&gt;
  43. * // short handed call directly from the element object
  44. * Ext.get(&quot;foo&quot;).load({
  45. url: &quot;bar.php&quot;,
  46. scripts: true,
  47. params: &quot;param1=foo&amp;amp;param2=bar&quot;,
  48. text: &quot;Loading Foo...&quot;
  49. * });
  50. * &lt;/code&gt;&lt;/pre&gt;
  51. * @constructor
  52. * Create new Updater directly.
  53. * @param {Mixed} el The element to update
  54. * @param {Boolean} forceNew (optional) By default the constructor checks to see if the passed element already
  55. * has an Updater and if it does it returns the same instance. This will skip that check (useful for extending this class).
  56. */
  57. Ext.UpdateManager = Ext.Updater = Ext.extend(Ext.util.Observable,
  58. function() {
  59. var BEFOREUPDATE = &quot;beforeupdate&quot;,
  60. UPDATE = &quot;update&quot;,
  61. FAILURE = &quot;failure&quot;;
  62. // private
  63. function processSuccess(response){
  64. var me = this;
  65. me.transaction = null;
  66. if (response.argument.form &amp;&amp; response.argument.reset) {
  67. try { // put in try/catch since some older FF releases had problems with this
  68. response.argument.form.reset();
  69. } catch(e){}
  70. }
  71. if (me.loadScripts) {
  72. me.renderer.render(me.el, response, me,
  73. updateComplete.createDelegate(me, [response]));
  74. } else {
  75. me.renderer.render(me.el, response, me);
  76. updateComplete.call(me, response);
  77. }
  78. }
  79. // private
  80. function updateComplete(response, type, success){
  81. this.fireEvent(type || UPDATE, this.el, response);
  82. if(Ext.isFunction(response.argument.callback)){
  83. response.argument.callback.call(response.argument.scope, this.el, Ext.isEmpty(success) ? true : false, response, response.argument.options);
  84. }
  85. }
  86. // private
  87. function processFailure(response){
  88. updateComplete.call(this, response, FAILURE, !!(this.transaction = null));
  89. }
  90. return {
  91. constructor: function(el, forceNew){
  92. var me = this;
  93. el = Ext.get(el);
  94. if(!forceNew &amp;&amp; el.updateManager){
  95. return el.updateManager;
  96. }
  97. <span id='Ext-Updater-property-el'> /**
  98. </span> * The Element object
  99. * @type Ext.Element
  100. */
  101. me.el = el;
  102. <span id='Ext-Updater-property-defaultUrl'> /**
  103. </span> * Cached url to use for refreshes. Overwritten every time update() is called unless &quot;discardUrl&quot; param is set to true.
  104. * @type String
  105. */
  106. me.defaultUrl = null;
  107. me.addEvents(
  108. <span id='Ext-Updater-event-beforeupdate'> /**
  109. </span> * @event beforeupdate
  110. * Fired before an update is made, return false from your handler and the update is cancelled.
  111. * @param {Ext.Element} el
  112. * @param {String/Object/Function} url
  113. * @param {String/Object} params
  114. */
  115. BEFOREUPDATE,
  116. <span id='Ext-Updater-event-update'> /**
  117. </span> * @event update
  118. * Fired after successful update is made.
  119. * @param {Ext.Element} el
  120. * @param {Object} oResponseObject The response Object
  121. */
  122. UPDATE,
  123. <span id='Ext-Updater-event-failure'> /**
  124. </span> * @event failure
  125. * Fired on update failure.
  126. * @param {Ext.Element} el
  127. * @param {Object} oResponseObject The response Object
  128. */
  129. FAILURE
  130. );
  131. Ext.apply(me, Ext.Updater.defaults);
  132. <span id='Ext-Updater-property-sslBlankUrl'> /**
  133. </span> * Blank page URL to use with SSL file uploads (defaults to {@link Ext.Updater.defaults#sslBlankUrl}).
  134. * @property sslBlankUrl
  135. * @type String
  136. */
  137. <span id='Ext-Updater-property-disableCaching'> /**
  138. </span> * Whether to append unique parameter on get request to disable caching (defaults to {@link Ext.Updater.defaults#disableCaching}).
  139. * @property disableCaching
  140. * @type Boolean
  141. */
  142. <span id='Ext-Updater-property-indicatorText'> /**
  143. </span> * Text for loading indicator (defaults to {@link Ext.Updater.defaults#indicatorText}).
  144. * @property indicatorText
  145. * @type String
  146. */
  147. <span id='Ext-Updater-property-showLoadIndicator'> /**
  148. </span> * Whether to show indicatorText when loading (defaults to {@link Ext.Updater.defaults#showLoadIndicator}).
  149. * @property showLoadIndicator
  150. * @type String
  151. */
  152. <span id='Ext-Updater-property-timeout'> /**
  153. </span> * Timeout for requests or form posts in seconds (defaults to {@link Ext.Updater.defaults#timeout}).
  154. * @property timeout
  155. * @type Number
  156. */
  157. <span id='Ext-Updater-property-loadScripts'> /**
  158. </span> * True to process scripts in the output (defaults to {@link Ext.Updater.defaults#loadScripts}).
  159. * @property loadScripts
  160. * @type Boolean
  161. */
  162. <span id='Ext-Updater-property-transaction'> /**
  163. </span> * Transaction object of the current executing transaction, or null if there is no active transaction.
  164. */
  165. me.transaction = null;
  166. <span id='Ext-Updater-property-refreshDelegate'> /**
  167. </span> * Delegate for refresh() prebound to &quot;this&quot;, use myUpdater.refreshDelegate.createCallback(arg1, arg2) to bind arguments
  168. * @type Function
  169. */
  170. me.refreshDelegate = me.refresh.createDelegate(me);
  171. <span id='Ext-Updater-property-updateDelegate'> /**
  172. </span> * Delegate for update() prebound to &quot;this&quot;, use myUpdater.updateDelegate.createCallback(arg1, arg2) to bind arguments
  173. * @type Function
  174. */
  175. me.updateDelegate = me.update.createDelegate(me);
  176. <span id='Ext-Updater-property-formUpdateDelegate'> /**
  177. </span> * Delegate for formUpdate() prebound to &quot;this&quot;, use myUpdater.formUpdateDelegate.createCallback(arg1, arg2) to bind arguments
  178. * @type Function
  179. */
  180. me.formUpdateDelegate = (me.formUpdate || function(){}).createDelegate(me);
  181. <span id='Ext-Updater-property-renderer'> /**
  182. </span> * The renderer for this Updater (defaults to {@link Ext.Updater.BasicRenderer}).
  183. */
  184. me.renderer = me.renderer || me.getDefaultRenderer();
  185. Ext.Updater.superclass.constructor.call(me);
  186. },
  187. <span id='Ext-Updater-method-setRenderer'> /**
  188. </span> * Sets the content renderer for this Updater. See {@link Ext.Updater.BasicRenderer#render} for more details.
  189. * @param {Object} renderer The object implementing the render() method
  190. */
  191. setRenderer : function(renderer){
  192. this.renderer = renderer;
  193. },
  194. <span id='Ext-Updater-method-getRenderer'> /**
  195. </span> * Returns the current content renderer for this Updater. See {@link Ext.Updater.BasicRenderer#render} for more details.
  196. * @return {Object}
  197. */
  198. getRenderer : function(){
  199. return this.renderer;
  200. },
  201. <span id='Ext-Updater-method-getDefaultRenderer'> /**
  202. </span> * This is an overrideable method which returns a reference to a default
  203. * renderer class if none is specified when creating the Ext.Updater.
  204. * Defaults to {@link Ext.Updater.BasicRenderer}
  205. */
  206. getDefaultRenderer: function() {
  207. return new Ext.Updater.BasicRenderer();
  208. },
  209. <span id='Ext-Updater-method-setDefaultUrl'> /**
  210. </span> * Sets the default URL used for updates.
  211. * @param {String/Function} defaultUrl The url or a function to call to get the url
  212. */
  213. setDefaultUrl : function(defaultUrl){
  214. this.defaultUrl = defaultUrl;
  215. },
  216. <span id='Ext-Updater-method-getEl'> /**
  217. </span> * Get the Element this Updater is bound to
  218. * @return {Ext.Element} The element
  219. */
  220. getEl : function(){
  221. return this.el;
  222. },
  223. <span id='Ext-Updater-method-update'> /**
  224. </span> * Performs an &lt;b&gt;asynchronous&lt;/b&gt; request, updating this element with the response.
  225. * If params are specified it uses POST, otherwise it uses GET.&lt;br&gt;&lt;br&gt;
  226. * &lt;b&gt;Note:&lt;/b&gt; Due to the asynchronous nature of remote server requests, the Element
  227. * will not have been fully updated when the function returns. To post-process the returned
  228. * data, use the callback option, or an &lt;b&gt;&lt;code&gt;update&lt;/code&gt;&lt;/b&gt; event handler.
  229. * @param {Object} options A config object containing any of the following options:&lt;ul&gt;
  230. * &lt;li&gt;url : &lt;b&gt;String/Function&lt;/b&gt;&lt;p class=&quot;sub-desc&quot;&gt;The URL to request or a function which
  231. * &lt;i&gt;returns&lt;/i&gt; the URL (defaults to the value of {@link Ext.Ajax#url} if not specified).&lt;/p&gt;&lt;/li&gt;
  232. * &lt;li&gt;method : &lt;b&gt;String&lt;/b&gt;&lt;p class=&quot;sub-desc&quot;&gt;The HTTP method to
  233. * use. Defaults to POST if the &lt;code&gt;params&lt;/code&gt; argument is present, otherwise GET.&lt;/p&gt;&lt;/li&gt;
  234. * &lt;li&gt;params : &lt;b&gt;String/Object/Function&lt;/b&gt;&lt;p class=&quot;sub-desc&quot;&gt;The
  235. * parameters to pass to the server (defaults to none). These may be specified as a url-encoded
  236. * string, or as an object containing properties which represent parameters,
  237. * or as a function, which returns such an object.&lt;/p&gt;&lt;/li&gt;
  238. * &lt;li&gt;scripts : &lt;b&gt;Boolean&lt;/b&gt;&lt;p class=&quot;sub-desc&quot;&gt;If &lt;code&gt;true&lt;/code&gt;
  239. * any &amp;lt;script&amp;gt; tags embedded in the response text will be extracted
  240. * and executed (defaults to {@link Ext.Updater.defaults#loadScripts}). If this option is specified,
  241. * the callback will be called &lt;i&gt;after&lt;/i&gt; the execution of the scripts.&lt;/p&gt;&lt;/li&gt;
  242. * &lt;li&gt;callback : &lt;b&gt;Function&lt;/b&gt;&lt;p class=&quot;sub-desc&quot;&gt;A function to
  243. * be called when the response from the server arrives. The following
  244. * parameters are passed:&lt;ul&gt;
  245. * &lt;li&gt;&lt;b&gt;el&lt;/b&gt; : Ext.Element&lt;p class=&quot;sub-desc&quot;&gt;The Element being updated.&lt;/p&gt;&lt;/li&gt;
  246. * &lt;li&gt;&lt;b&gt;success&lt;/b&gt; : Boolean&lt;p class=&quot;sub-desc&quot;&gt;True for success, false for failure.&lt;/p&gt;&lt;/li&gt;
  247. * &lt;li&gt;&lt;b&gt;response&lt;/b&gt; : XMLHttpRequest&lt;p class=&quot;sub-desc&quot;&gt;The XMLHttpRequest which processed the update.&lt;/p&gt;&lt;/li&gt;
  248. * &lt;li&gt;&lt;b&gt;options&lt;/b&gt; : Object&lt;p class=&quot;sub-desc&quot;&gt;The config object passed to the update call.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;
  249. * &lt;/p&gt;&lt;/li&gt;
  250. * &lt;li&gt;scope : &lt;b&gt;Object&lt;/b&gt;&lt;p class=&quot;sub-desc&quot;&gt;The scope in which
  251. * to execute the callback (The callback's &lt;code&gt;this&lt;/code&gt; reference.) If the
  252. * &lt;code&gt;params&lt;/code&gt; argument is a function, this scope is used for that function also.&lt;/p&gt;&lt;/li&gt;
  253. * &lt;li&gt;discardUrl : &lt;b&gt;Boolean&lt;/b&gt;&lt;p class=&quot;sub-desc&quot;&gt;By default, the URL of this request becomes
  254. * the default URL for this Updater object, and will be subsequently used in {@link #refresh}
  255. * calls. To bypass this behavior, pass &lt;code&gt;discardUrl:true&lt;/code&gt; (defaults to false).&lt;/p&gt;&lt;/li&gt;
  256. * &lt;li&gt;timeout : &lt;b&gt;Number&lt;/b&gt;&lt;p class=&quot;sub-desc&quot;&gt;The number of seconds to wait for a response before
  257. * timing out (defaults to {@link Ext.Updater.defaults#timeout}).&lt;/p&gt;&lt;/li&gt;
  258. * &lt;li&gt;text : &lt;b&gt;String&lt;/b&gt;&lt;p class=&quot;sub-desc&quot;&gt;The text to use as the innerHTML of the
  259. * {@link Ext.Updater.defaults#indicatorText} div (defaults to 'Loading...'). To replace the entire div, not
  260. * just the text, override {@link Ext.Updater.defaults#indicatorText} directly.&lt;/p&gt;&lt;/li&gt;
  261. * &lt;li&gt;nocache : &lt;b&gt;Boolean&lt;/b&gt;&lt;p class=&quot;sub-desc&quot;&gt;Only needed for GET
  262. * requests, this option causes an extra, auto-generated parameter to be appended to the request
  263. * to defeat caching (defaults to {@link Ext.Updater.defaults#disableCaching}).&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;
  264. * &lt;p&gt;
  265. * For example:
  266. &lt;pre&gt;&lt;code&gt;
  267. um.update({
  268. url: &quot;your-url.php&quot;,
  269. params: {param1: &quot;foo&quot;, param2: &quot;bar&quot;}, // or a URL encoded string
  270. callback: yourFunction,
  271. scope: yourObject, //(optional scope)
  272. discardUrl: true,
  273. nocache: true,
  274. text: &quot;Loading...&quot;,
  275. timeout: 60,
  276. scripts: false // Save time by avoiding RegExp execution.
  277. });
  278. &lt;/code&gt;&lt;/pre&gt;
  279. */
  280. update : function(url, params, callback, discardUrl){
  281. var me = this,
  282. cfg,
  283. callerScope;
  284. if(me.fireEvent(BEFOREUPDATE, me.el, url, params) !== false){
  285. if(Ext.isObject(url)){ // must be config object
  286. cfg = url;
  287. url = cfg.url;
  288. params = params || cfg.params;
  289. callback = callback || cfg.callback;
  290. discardUrl = discardUrl || cfg.discardUrl;
  291. callerScope = cfg.scope;
  292. if(!Ext.isEmpty(cfg.nocache)){me.disableCaching = cfg.nocache;};
  293. if(!Ext.isEmpty(cfg.text)){me.indicatorText = '&lt;div class=&quot;loading-indicator&quot;&gt;'+cfg.text+&quot;&lt;/div&gt;&quot;;};
  294. if(!Ext.isEmpty(cfg.scripts)){me.loadScripts = cfg.scripts;};
  295. if(!Ext.isEmpty(cfg.timeout)){me.timeout = cfg.timeout;};
  296. }
  297. me.showLoading();
  298. if(!discardUrl){
  299. me.defaultUrl = url;
  300. }
  301. if(Ext.isFunction(url)){
  302. url = url.call(me);
  303. }
  304. var o = Ext.apply({}, {
  305. url : url,
  306. params: (Ext.isFunction(params) &amp;&amp; callerScope) ? params.createDelegate(callerScope) : params,
  307. success: processSuccess,
  308. failure: processFailure,
  309. scope: me,
  310. callback: undefined,
  311. timeout: (me.timeout*1000),
  312. disableCaching: me.disableCaching,
  313. argument: {
  314. &quot;options&quot;: cfg,
  315. &quot;url&quot;: url,
  316. &quot;form&quot;: null,
  317. &quot;callback&quot;: callback,
  318. &quot;scope&quot;: callerScope || window,
  319. &quot;params&quot;: params
  320. }
  321. }, cfg);
  322. me.transaction = Ext.Ajax.request(o);
  323. }
  324. },
  325. <span id='Ext-Updater-method-formUpdate'> /**
  326. </span> * &lt;p&gt;Performs an asynchronous form post, updating this element with the response. If the form has the attribute
  327. * enctype=&quot;&lt;a href=&quot;http://www.faqs.org/rfcs/rfc2388.html&quot;&gt;multipart/form-data&lt;/a&gt;&quot;, it assumes it's a file upload.
  328. * Uses this.sslBlankUrl for SSL file uploads to prevent IE security warning.&lt;/p&gt;
  329. * &lt;p&gt;File uploads are not performed using normal &quot;Ajax&quot; techniques, that is they are &lt;b&gt;not&lt;/b&gt;
  330. * performed using XMLHttpRequests. Instead the form is submitted in the standard manner with the
  331. * DOM &lt;code&gt;&amp;lt;form&gt;&lt;/code&gt; element temporarily modified to have its
  332. * &lt;a href=&quot;http://www.w3.org/TR/REC-html40/present/frames.html#adef-target&quot;&gt;target&lt;/a&gt; set to refer
  333. * to a dynamically generated, hidden &lt;code&gt;&amp;lt;iframe&gt;&lt;/code&gt; which is inserted into the document
  334. * but removed after the return data has been gathered.&lt;/p&gt;
  335. * &lt;p&gt;Be aware that file upload packets, sent with the content type &lt;a href=&quot;http://www.faqs.org/rfcs/rfc2388.html&quot;&gt;multipart/form-data&lt;/a&gt;
  336. * and some server technologies (notably JEE) may require some custom processing in order to
  337. * retrieve parameter names and parameter values from the packet content.&lt;/p&gt;
  338. * @param {String/HTMLElement} form The form Id or form element
  339. * @param {String} url (optional) The url to pass the form to. If omitted the action attribute on the form will be used.
  340. * @param {Boolean} reset (optional) Whether to try to reset the form after the update
  341. * @param {Function} callback (optional) Callback when transaction is complete. The following
  342. * parameters are passed:&lt;ul&gt;
  343. * &lt;li&gt;&lt;b&gt;el&lt;/b&gt; : Ext.Element&lt;p class=&quot;sub-desc&quot;&gt;The Element being updated.&lt;/p&gt;&lt;/li&gt;
  344. * &lt;li&gt;&lt;b&gt;success&lt;/b&gt; : Boolean&lt;p class=&quot;sub-desc&quot;&gt;True for success, false for failure.&lt;/p&gt;&lt;/li&gt;
  345. * &lt;li&gt;&lt;b&gt;response&lt;/b&gt; : XMLHttpRequest&lt;p class=&quot;sub-desc&quot;&gt;The XMLHttpRequest which processed the update.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;
  346. */
  347. formUpdate : function(form, url, reset, callback){
  348. var me = this;
  349. if(me.fireEvent(BEFOREUPDATE, me.el, form, url) !== false){
  350. if(Ext.isFunction(url)){
  351. url = url.call(me);
  352. }
  353. form = Ext.getDom(form);
  354. me.transaction = Ext.Ajax.request({
  355. form: form,
  356. url:url,
  357. success: processSuccess,
  358. failure: processFailure,
  359. scope: me,
  360. timeout: (me.timeout*1000),
  361. argument: {
  362. &quot;url&quot;: url,
  363. &quot;form&quot;: form,
  364. &quot;callback&quot;: callback,
  365. &quot;reset&quot;: reset
  366. }
  367. });
  368. me.showLoading.defer(1, me);
  369. }
  370. },
  371. <span id='Ext-Updater-method-startAutoRefresh'> /**
  372. </span> * Set this element to auto refresh. Can be canceled by calling {@link #stopAutoRefresh}.
  373. * @param {Number} interval How often to update (in seconds).
  374. * @param {String/Object/Function} url (optional) The url for this request, a config object in the same format
  375. * supported by {@link #load}, or a function to call to get the url (defaults to the last used url). Note that while
  376. * the url used in a load call can be reused by this method, other load config options will not be reused and must be
  377. * sepcified as part of a config object passed as this paramter if needed.
  378. * @param {String/Object} params (optional) The parameters to pass as either a url encoded string
  379. * &quot;&amp;param1=1&amp;param2=2&quot; or as an object {param1: 1, param2: 2}
  380. * @param {Function} callback (optional) Callback when transaction is complete - called with signature (oElement, bSuccess)
  381. * @param {Boolean} refreshNow (optional) Whether to execute the refresh now, or wait the interval
  382. */
  383. startAutoRefresh : function(interval, url, params, callback, refreshNow){
  384. var me = this;
  385. if(refreshNow){
  386. me.update(url || me.defaultUrl, params, callback, true);
  387. }
  388. if(me.autoRefreshProcId){
  389. clearInterval(me.autoRefreshProcId);
  390. }
  391. me.autoRefreshProcId = setInterval(me.update.createDelegate(me, [url || me.defaultUrl, params, callback, true]), interval * 1000);
  392. },
  393. <span id='Ext-Updater-method-stopAutoRefresh'> /**
  394. </span> * Stop auto refresh on this element.
  395. */
  396. stopAutoRefresh : function(){
  397. if(this.autoRefreshProcId){
  398. clearInterval(this.autoRefreshProcId);
  399. delete this.autoRefreshProcId;
  400. }
  401. },
  402. <span id='Ext-Updater-method-isAutoRefreshing'> /**
  403. </span> * Returns true if the Updater is currently set to auto refresh its content (see {@link #startAutoRefresh}), otherwise false.
  404. */
  405. isAutoRefreshing : function(){
  406. return !!this.autoRefreshProcId;
  407. },
  408. <span id='Ext-Updater-method-showLoading'> /**
  409. </span> * Display the element's &quot;loading&quot; state. By default, the element is updated with {@link #indicatorText}. This
  410. * method may be overridden to perform a custom action while this Updater is actively updating its contents.
  411. */
  412. showLoading : function(){
  413. if(this.showLoadIndicator){
  414. this.el.dom.innerHTML = this.indicatorText;
  415. }
  416. },
  417. <span id='Ext-Updater-method-abort'> /**
  418. </span> * Aborts the currently executing transaction, if any.
  419. */
  420. abort : function(){
  421. if(this.transaction){
  422. Ext.Ajax.abort(this.transaction);
  423. }
  424. },
  425. <span id='Ext-Updater-method-isUpdating'> /**
  426. </span> * Returns true if an update is in progress, otherwise false.
  427. * @return {Boolean}
  428. */
  429. isUpdating : function(){
  430. return this.transaction ? Ext.Ajax.isLoading(this.transaction) : false;
  431. },
  432. <span id='Ext-Updater-method-refresh'> /**
  433. </span> * Refresh the element with the last used url or defaultUrl. If there is no url, it returns immediately
  434. * @param {Function} callback (optional) Callback when transaction is complete - called with signature (oElement, bSuccess)
  435. */
  436. refresh : function(callback){
  437. if(this.defaultUrl){
  438. this.update(this.defaultUrl, null, callback, true);
  439. }
  440. }
  441. };
  442. }());
  443. <span id='Ext-Updater-defaults'>/**
  444. </span> * @class Ext.Updater.defaults
  445. * The defaults collection enables customizing the default properties of Updater
  446. */
  447. Ext.Updater.defaults = {
  448. <span id='Ext-Updater-defaults-property-timeout'> /**
  449. </span> * Timeout for requests or form posts in seconds (defaults to 30 seconds).
  450. * @type Number
  451. */
  452. timeout : 30,
  453. <span id='Ext-Updater-defaults-property-disableCaching'> /**
  454. </span> * True to append a unique parameter to GET requests to disable caching (defaults to false).
  455. * @type Boolean
  456. */
  457. disableCaching : false,
  458. <span id='Ext-Updater-defaults-property-showLoadIndicator'> /**
  459. </span> * Whether or not to show {@link #indicatorText} during loading (defaults to true).
  460. * @type Boolean
  461. */
  462. showLoadIndicator : true,
  463. <span id='Ext-Updater-defaults-property-indicatorText'> /**
  464. </span> * Text for loading indicator (defaults to '&amp;lt;div class=&quot;loading-indicator&quot;&amp;gt;Loading...&amp;lt;/div&amp;gt;').
  465. * @type String
  466. */
  467. indicatorText : '&lt;div class=&quot;loading-indicator&quot;&gt;Loading...&lt;/div&gt;',
  468. <span id='Ext-Updater-defaults-property-loadScripts'> /**
  469. </span> * True to process scripts by default (defaults to false).
  470. * @type Boolean
  471. */
  472. loadScripts : false,
  473. <span id='Ext-Updater-defaults-property-sslBlankUrl'> /**
  474. </span> * Blank page URL to use with SSL file uploads (defaults to {@link Ext#SSL_SECURE_URL} if set, or &quot;javascript:false&quot;).
  475. * @type String
  476. */
  477. sslBlankUrl : Ext.SSL_SECURE_URL
  478. };
  479. <span id='Ext-Updater-static-method-updateElement'>/**
  480. </span> * Static convenience method. &lt;b&gt;This method is deprecated in favor of el.load({url:'foo.php', ...})&lt;/b&gt;.
  481. * Usage:
  482. * &lt;pre&gt;&lt;code&gt;Ext.Updater.updateElement(&quot;my-div&quot;, &quot;stuff.php&quot;);&lt;/code&gt;&lt;/pre&gt;
  483. * @param {Mixed} el The element to update
  484. * @param {String} url The url
  485. * @param {String/Object} params (optional) Url encoded param string or an object of name/value pairs
  486. * @param {Object} options (optional) A config object with any of the Updater properties you want to set - for
  487. * example: {disableCaching:true, indicatorText: &quot;Loading data...&quot;}
  488. * @static
  489. * @deprecated
  490. * @member Ext.Updater
  491. */
  492. Ext.Updater.updateElement = function(el, url, params, options){
  493. var um = Ext.get(el).getUpdater();
  494. Ext.apply(um, options);
  495. um.update(url, params, options ? options.callback : null);
  496. };
  497. <span id='Ext-Updater-BasicRenderer'>/**
  498. </span> * @class Ext.Updater.BasicRenderer
  499. * &lt;p&gt;This class is a base class implementing a simple render method which updates an element using results from an Ajax request.&lt;/p&gt;
  500. * &lt;p&gt;The BasicRenderer updates the element's innerHTML with the responseText. To perform a custom render (i.e. XML or JSON processing),
  501. * create an object with a conforming {@link #render} method and pass it to setRenderer on the Updater.&lt;/p&gt;
  502. */
  503. Ext.Updater.BasicRenderer = function(){};
  504. Ext.Updater.BasicRenderer.prototype = {
  505. <span id='Ext-Updater-BasicRenderer-method-render'> /**
  506. </span> * This method is called when an Ajax response is received, and an Element needs updating.
  507. * @param {Ext.Element} el The element being rendered
  508. * @param {Object} xhr The XMLHttpRequest object
  509. * @param {Updater} updateManager The calling update manager
  510. * @param {Function} callback A callback that will need to be called if loadScripts is true on the Updater
  511. */
  512. render : function(el, response, updateManager, callback){
  513. el.update(response.responseText, updateManager.loadScripts, callback);
  514. }
  515. };</pre>
  516. </body>
  517. </html>