1
<html><head><title>UpdateManager.js</title><link rel="stylesheet" type="text/css" href="../resources/style.css" media="screen"/></head><body><h1>UpdateManager.js</h1><pre class="highlighted"><code><i>/**
3
* @extends Ext.util.Observable
4
* Provides AJAX-style update capabilities <b>for</b> Element objects. Updater can be used to {@link #update} an Element once,
5
* or you can use {@link #startAutoRefresh} to set up an auto-updating Element on a specific interval.<br><br>
7
* <pre><code>
8
* <i>// Get it from a Ext.Element object</i>
9
* <b>var</b> el = Ext.get("foo");
10
* <b>var</b> mgr = el.getUpdater();
12
url: "http:<i>//myserver.com/index.php",</i>
14
param1: "foo",
15
param2: "bar"
19
* mgr.formUpdate("myFormId", "http:<i>//myserver.com/index.php");</i>
21
* <i>// or directly (returns the same Updater instance)</i>
22
* <b>var</b> mgr = <b>new</b> Ext.Updater("myElementId");
23
* mgr.startAutoRefresh(60, "http:<i>//myserver.com/index.php");</i>
24
* mgr.on("update", myFcnNeedsToKnow);
26
* <i>// short handed call directly from the element object</i>
27
* Ext.get("foo").load({
28
url: "bar.php",
30
params: "param1=foo&amp;param2=bar",
31
text: "Loading Foo..."
33
* </code></pre>
35
* Create <b>new</b> Updater directly.
36
* @param {Mixed} el The element to update
37
* @param {Boolean} forceNew (optional) By <b>default</b> the constructor checks to see <b>if</b> the passed element already
38
* has an Updater and <b>if</b> it does it returns the same instance. This will skip that check (useful <b>for</b> extending <b>this</b> class).
40
Ext.Updater = Ext.extend(Ext.util.Observable, {
41
constructor: <b>function</b>(el, forceNew){
43
<b>if</b>(!forceNew && el.updateManager){
44
<b>return</b> el.updateManager;
52
* Cached url to use <b>for</b> refreshes. Overwritten every time update() is called unless "discardUrl" param is set to true.
55
<b>this</b>.defaultUrl = null;
57
<b>this</b>.addEvents(
60
* Fired before an update is made, <b>return</b> false from your handler and the update is cancelled.
61
* @param {Ext.Element} el
62
* @param {String/Object/Function} url
63
* @param {String/Object} params
65
"beforeupdate",
68
* Fired after successful update is made.
69
* @param {Ext.Element} el
70
* @param {Object} oResponseObject The response Object
75
* Fired on update failure.
76
* @param {Ext.Element} el
77
* @param {Object} oResponseObject The response Object
81
<b>var</b> d = Ext.Updater.defaults;
83
* Blank page URL to use <b>with</b> SSL file uploads (defaults to {@link Ext.Updater.defaults#sslBlankUrl}).
86
<b>this</b>.sslBlankUrl = d.sslBlankUrl;
88
* Whether to append unique parameter on get request to disable caching (defaults to {@link Ext.Updater.defaults#disableCaching}).
91
<b>this</b>.disableCaching = d.disableCaching;
93
* Text <b>for</b> loading indicator (defaults to {@link Ext.Updater.defaults#indicatorText}).
96
<b>this</b>.indicatorText = d.indicatorText;
98
* Whether to show indicatorText when loading (defaults to {@link Ext.Updater.defaults#showLoadIndicator}).
101
<b>this</b>.showLoadIndicator = d.showLoadIndicator;
103
* Timeout <b>for</b> requests or form posts <b>in</b> seconds (defaults to {@link Ext.Updater.defaults#timeout}).
106
<b>this</b>.timeout = d.timeout;
108
* True to process scripts <b>in</b> the output (defaults to {@link Ext.Updater.defaults#loadScripts}).
111
<b>this</b>.loadScripts = d.loadScripts;
113
* Transaction object of the current executing transaction, or null <b>if</b> there is no active transaction.
115
<b>this</b>.transaction = null;
117
* Delegate <b>for</b> refresh() prebound to "<b>this</b>", use myUpdater.refreshDelegate.createCallback(arg1, arg2) to bind arguments
120
<b>this</b>.refreshDelegate = <b>this</b>.refresh.createDelegate(<b>this</b>);
122
* Delegate <b>for</b> update() prebound to "<b>this</b>", use myUpdater.updateDelegate.createCallback(arg1, arg2) to bind arguments
125
<b>this</b>.updateDelegate = <b>this</b>.update.createDelegate(<b>this</b>);
127
* Delegate <b>for</b> formUpdate() prebound to "<b>this</b>", use myUpdater.formUpdateDelegate.createCallback(arg1, arg2) to bind arguments
130
<b>this</b>.formUpdateDelegate = <b>this</b>.formUpdate.createDelegate(<b>this</b>);
132
<b>if</b>(!<b>this</b>.renderer){
134
* The renderer <b>for</b> this Updater (defaults to {@link Ext.Updater.BasicRenderer}).
136
<b>this</b>.renderer = <b>this</b>.getDefaultRenderer();
138
Ext.Updater.superclass.constructor.call(<b>this</b>);
141
* This is an overrideable method which returns a reference to a <b>default</b>
142
* renderer class <b>if</b> none is specified when creating the Ext.Updater.
143
* Defaults to {@link Ext.Updater.BasicRenderer}
145
getDefaultRenderer: <b>function</b>() {
146
<b>return</b> new Ext.Updater.BasicRenderer();
149
* Get the Element <b>this</b> Updater is bound to
150
* @<b>return</b> {Ext.Element} The element
152
getEl : <b>function</b>(){
153
<b>return</b> this.el;
157
* Performs an <b>asynchronous</b> request, updating <b>this</b> element <b>with</b> the response.
158
* If params are specified it uses POST, otherwise it uses GET.<br><br>
159
* <b>Note:</b> Due to the asynchronous nature of remote server requests, the Element
160
* will not have been fully updated when the <b>function</b> returns. To post-process the returned
161
* data, use the callback option, or an <b><tt>update</tt></b> event handler.
162
* @param {Object} options A config object containing any of the following options:<ul>
163
* <li>url : <b>String/Function</b><p class="sub-desc">The URL to request or a <b>function</b> which
164
* <i>returns</i> the URL (defaults to the value of {@link Ext.Ajax#url} <b>if</b> not specified).</p></li>
165
* <li>method : <b>String</b><p class="sub-desc">The HTTP method to
166
* use. Defaults to POST <b>if</b> the <tt>params</tt> argument is present, otherwise GET.</p></li>
167
* <li>params : <b>String/Object/Function</b><p class="sub-desc">The
168
* parameters to pass to the server (defaults to none). These may be specified as a url-encoded
169
* string, or as an object containing properties which represent parameters,
170
* or as a <b>function</b>, which returns such an object.</p></li>
171
* <li>scripts : <b>Boolean</b><p class="sub-desc">If <tt>true</tt>
172
* any &lt;script&gt; tags embedded <b>in</b> the response text will be extracted
173
* and executed (defaults to {@link Ext.Updater.defaults#loadScripts}). If <b>this</b> option is specified,
174
* the callback will be called <i>after</i> the execution of the scripts.</p></li>
175
* <li>callback : <b>Function</b><p class="sub-desc">A <b>function</b> to
176
* be called when the response from the server arrives. The following
177
* parameters are passed:<ul>
178
* <li><b>el</b> : Ext.Element<p class="sub-desc">The Element being updated.</p></li>
179
* <li><b>success</b> : Boolean<p class="sub-desc">True <b>for</b> success, false <b>for</b> failure.</p></li>
180
* <li><b>response</b> : XMLHttpRequest<p class="sub-desc">The XMLHttpRequest which processed the update.</p></li>
181
* <li><b>options</b> : Object<p class="sub-desc">The config object passed to the update call.</p></li></ul>
182
* </p></li>
183
* <li>scope : <b>Object</b><p class="sub-desc">The scope <b>in</b> which
184
* to execute the callback (The callback's <tt><b>this</b></tt> reference.) If the
185
* <tt>params</tt> argument is a <b>function</b>, <b>this</b> scope is used <b>for</b> that <b>function</b> also.</p></li>
186
* <li>discardUrl : <b>Boolean</b><p class="sub-desc">By <b>default</b>, the URL of <b>this</b> request becomes
187
* the <b>default</b> URL <b>for</b> this Updater object, and will be subsequently used <b>in</b> {@link #refresh}
188
* calls. To bypass <b>this</b> behavior, pass <tt>discardUrl:true</tt> (defaults to false).</p></li>
189
* <li>timeout : <b>Number</b><p class="sub-desc">The number of seconds to wait <b>for</b> a response before
190
* timing out (defaults to {@link Ext.Updater.defaults#timeout}).</p></li>
191
* <li>text : <b>String</b><p class="sub-desc">The text to use as the innerHTML of the
192
* {@link Ext.Updater.defaults#indicatorText} div (defaults to <em>'Loading...'</em>). To replace the entire div, not
193
* just the text, override {@link Ext.Updater.defaults#indicatorText} directly.</p></li>
194
* <li>nocache : <b>Boolean</b><p class="sub-desc">Only needed <b>for</b> GET
195
* requests, <b>this</b> option causes an extra, auto-generated parameter to be appended to the request
196
* to defeat caching (defaults to {@link Ext.Updater.defaults#disableCaching}).</p></li></ul>
199
<pre><code>
201
url: "your-url.php",
202
params: {param1: "foo", param2: "bar"}, <i>// or a URL encoded string</i>
203
callback: yourFunction,
204
scope: yourObject, <i>//(optional scope)</i>
207
text: "Loading...",
209
scripts: false <i>// Save time by avoiding RegExp execution.</i>
211
</code></pre>
213
update : <b>function</b>(url, params, callback, discardUrl){
214
<b>if</b>(this.fireEvent("beforeupdate", <b>this</b>.el, url, params) !== false){
215
<b>var</b> cfg, callerScope;
216
<b>if</b>(typeof url == "object"){ <i>// must be config object</i>
219
params = params || cfg.params;
220
callback = callback || cfg.callback;
221
discardUrl = discardUrl || cfg.discardUrl;
222
callerScope = cfg.scope;
223
<b>if</b>(typeof cfg.nocache != "undefined"){<b>this</b>.disableCaching = cfg.nocache;};
224
<b>if</b>(typeof cfg.text != "undefined"){<b>this</b>.indicatorText = <em>'<div class="loading-indicator">'</em>+cfg.text+"</div>";};
225
<b>if</b>(typeof cfg.scripts != "undefined"){<b>this</b>.loadScripts = cfg.scripts;};
226
<b>if</b>(typeof cfg.timeout != "undefined"){<b>this</b>.timeout = cfg.timeout;};
228
<b>this</b>.showLoading();
230
<b>if</b>(!discardUrl){
231
<b>this</b>.defaultUrl = url;
233
<b>if</b>(typeof url == "<b>function</b>"){
234
url = url.call(<b>this</b>);
237
<b>var</b> o = Ext.apply({}, {
239
params: (<b>typeof</b> params == "<b>function</b>" && callerScope) ? params.createDelegate(callerScope) : params,
240
success: <b>this</b>.processSuccess,
241
failure: <b>this</b>.processFailure,
244
timeout: (<b>this</b>.timeout*1000),
245
disableCaching: <b>this</b>.disableCaching,
247
"options": cfg,
248
"url": url,
249
"form": null,
250
"callback": callback,
251
"scope": callerScope || window,
252
"params": params
256
<b>this</b>.transaction = Ext.Ajax.request(o);
261
* <p>Performs an async form post, updating <b>this</b> element <b>with</b> the response. If the form has the attribute
262
* enctype="<a href="http:<i>//www.faqs.org/rfcs/rfc2388.html">multipart/form-data</a>", it assumes it's a file upload.</i>
263
* Uses <b>this</b>.sslBlankUrl <b>for</b> SSL file uploads to prevent IE security warning.</p>
264
* <p>File uploads are not performed using normal "Ajax" techniques, that is they are <b>not</b>
265
* performed using XMLHttpRequests. Instead the form is submitted <b>in</b> the standard manner <b>with</b> the
266
* DOM <tt>&lt;form></tt> element temporarily modified to have its
267
* <a href="http:<i>//www.w3.org/TR/REC-html40/present/frames.html#adef-target">target</a> set to refer</i>
268
* to a dynamically generated, hidden <tt>&lt;iframe></tt> which is inserted into the document
269
* but removed after the <b>return</b> data has been gathered.</p>
270
* <p>Be aware that file upload packets, sent <b>with</b> the content type <a href="http:<i>//www.faqs.org/rfcs/rfc2388.html">multipart/form-data</a></i>
271
* and some server technologies (notably JEE) may require some custom processing <b>in</b> order to
272
* retrieve parameter names and parameter values from the packet content.</p>
273
* @param {String/HTMLElement} form The form Id or form element
274
* @param {String} url (optional) The url to pass the form to. If omitted the action attribute on the form will be used.
275
* @param {Boolean} reset (optional) Whether to try to reset the form after the update
276
* @param {Function} callback (optional) Callback when transaction is complete. The following
277
* parameters are passed:<ul>
278
* <li><b>el</b> : Ext.Element<p class="sub-desc">The Element being updated.</p></li>
279
* <li><b>success</b> : Boolean<p class="sub-desc">True <b>for</b> success, false <b>for</b> failure.</p></li>
280
* <li><b>response</b> : XMLHttpRequest<p class="sub-desc">The XMLHttpRequest which processed the update.</p></li></ul>
282
formUpdate : <b>function</b>(form, url, reset, callback){
283
<b>if</b>(this.fireEvent("beforeupdate", <b>this</b>.el, form, url) !== false){
284
<b>if</b>(typeof url == "<b>function</b>"){
285
url = url.call(<b>this</b>);
287
form = Ext.getDom(form)
288
<b>this</b>.transaction = Ext.Ajax.request({
291
success: <b>this</b>.processSuccess,
292
failure: <b>this</b>.processFailure,
294
timeout: (<b>this</b>.timeout*1000),
296
"url": url,
297
"form": form,
298
"callback": callback,
299
"reset": reset
302
<b>this</b>.showLoading.defer(1, <b>this</b>);
307
* Refresh the element <b>with</b> the last used url or defaultUrl. If there is no url, it returns immediately
308
* @param {Function} callback (optional) Callback when transaction is complete - called <b>with</b> signature (oElement, bSuccess)
310
refresh : <b>function</b>(callback){
311
<b>if</b>(this.defaultUrl == null){
314
<b>this</b>.update(<b>this</b>.defaultUrl, null, callback, true);
318
* Set <b>this</b> element to auto refresh. Can be canceled by calling {@link #stopAutoRefresh}.
319
* @param {Number} interval How often to update (<b>in</b> seconds).
320
* @param {String/Object/Function} url (optional) The url <b>for</b> this request, a config object <b>in</b> the same format
321
* supported by {@link #load}, or a <b>function</b> to call to get the url (defaults to the last used url). Note that <b>while</b>
322
* the url used <b>in</b> a load call can be reused by <b>this</b> method, other load config options will not be reused and must be
323
* sepcified as part of a config object passed as <b>this</b> paramter <b>if</b> needed.
324
* @param {String/Object} params (optional) The parameters to pass as either a url encoded string
325
* "&param1=1&param2=2" or as an object {param1: 1, param2: 2}
326
* @param {Function} callback (optional) Callback when transaction is complete - called <b>with</b> signature (oElement, bSuccess)
327
* @param {Boolean} refreshNow (optional) Whether to execute the refresh now, or wait the interval
329
startAutoRefresh : <b>function</b>(interval, url, params, callback, refreshNow){
330
<b>if</b>(refreshNow){
331
<b>this</b>.update(url || <b>this</b>.defaultUrl, params, callback, true);
333
<b>if</b>(this.autoRefreshProcId){
334
clearInterval(<b>this</b>.autoRefreshProcId);
336
<b>this</b>.autoRefreshProcId = setInterval(<b>this</b>.update.createDelegate(<b>this</b>, [url || <b>this</b>.defaultUrl, params, callback, true]), interval*1000);
340
* Stop auto refresh on <b>this</b> element.
342
stopAutoRefresh : <b>function</b>(){
343
<b>if</b>(this.autoRefreshProcId){
344
clearInterval(<b>this</b>.autoRefreshProcId);
345
<b>delete</b> this.autoRefreshProcId;
350
* Returns true <b>if</b> the Updater is currently set to auto refresh its content (see {@link #startAutoRefresh}), otherwise false.
352
isAutoRefreshing : <b>function</b>(){
353
<b>return</b> this.autoRefreshProcId ? true : false;
357
* Display the element's "loading" state. By <b>default</b>, the element is updated <b>with</b> {@link #indicatorText}. This
358
* method may be overridden to perform a custom action <b>while</b> this Updater is actively updating its contents.
360
showLoading : <b>function</b>(){
361
<b>if</b>(this.showLoadIndicator){
362
<b>this</b>.el.update(<b>this</b>.indicatorText);
367
processSuccess : <b>function</b>(response){
368
<b>this</b>.transaction = null;
369
<b>if</b>(response.argument.form && response.argument.reset){
370
try{ <i>// put <b>in</b> try/catch since some older FF releases had problems <b>with</b> this</i>
371
response.argument.form.reset();
374
<b>if</b>(this.loadScripts){
375
<b>this</b>.renderer.render(<b>this</b>.el, response, <b>this</b>,
376
<b>this</b>.updateComplete.createDelegate(<b>this</b>, [response]));
378
<b>this</b>.renderer.render(<b>this</b>.el, response, <b>this</b>);
379
<b>this</b>.updateComplete(response);
384
updateComplete : <b>function</b>(response){
385
<b>this</b>.fireEvent("update", <b>this</b>.el, response);
386
<b>if</b>(typeof response.argument.callback == "<b>function</b>"){
387
response.argument.callback.call(response.argument.scope, <b>this</b>.el, true, response, response.argument.options);
392
processFailure : <b>function</b>(response){
393
<b>this</b>.transaction = null;
394
<b>this</b>.fireEvent("failure", <b>this</b>.el, response);
395
<b>if</b>(typeof response.argument.callback == "<b>function</b>"){
396
response.argument.callback.call(response.argument.scope, <b>this</b>.el, false, response, response.argument.options);
401
* Sets the content renderer <b>for</b> this Updater. See {@link Ext.Updater.BasicRenderer#render} <b>for</b> more details.
402
* @param {Object} renderer The object implementing the render() method
404
setRenderer : <b>function</b>(renderer){
405
<b>this</b>.renderer = renderer;
409
* Returns the content renderer <b>for</b> this Updater. See {@link Ext.Updater.BasicRenderer#render} <b>for</b> more details.
410
* @<b>return</b> {Object}
412
getRenderer : <b>function</b>(){
413
<b>return</b> this.renderer;
417
* Sets the <b>default</b> URL used <b>for</b> updates.
418
* @param {String/Function} defaultUrl The url or a <b>function</b> to call to get the url
420
setDefaultUrl : <b>function</b>(defaultUrl){
421
<b>this</b>.defaultUrl = defaultUrl;
425
* Aborts the currently executing transaction, <b>if</b> any.
427
abort : <b>function</b>(){
428
<b>if</b>(this.transaction){
429
Ext.Ajax.abort(<b>this</b>.transaction);
434
* Returns true <b>if</b> an update is <b>in</b> progress, otherwise false.
435
* @<b>return</b> {Boolean}
437
isUpdating : <b>function</b>(){
438
<b>if</b>(this.transaction){
439
<b>return</b> Ext.Ajax.isLoading(<b>this</b>.transaction);
446
* @class Ext.Updater.defaults
447
* The defaults collection enables customizing the <b>default</b> properties of Updater
449
Ext.Updater.defaults = {
451
* Timeout <b>for</b> requests or form posts <b>in</b> seconds (defaults to 30 seconds).
456
* True to process scripts by <b>default</b> (defaults to false).
461
* Blank page URL to use <b>with</b> SSL file uploads (defaults to {@link Ext#SSL_SECURE_URL} <b>if</b> set, or "javascript:false").
464
sslBlankUrl : (Ext.SSL_SECURE_URL || "javascript:false"),
466
* True to append a unique parameter to GET requests to disable caching (defaults to false).
469
disableCaching : false,
471
* Whether or not to show {@link #indicatorText} during loading (defaults to true).
474
showLoadIndicator : true,
476
* Text <b>for</b> loading indicator (defaults to <em>'&lt;div class="loading-indicator"&gt;Loading...&lt;/div&gt;'</em>).
479
indicatorText : <em>'<div class="loading-indicator">Loading...</div>'</em>
483
* Static convenience method. <b>This method is deprecated <b>in</b> favor of el.load({url:<em>'foo.php'</em>, ...})</b>.
485
* <pre><code>Ext.Updater.updateElement("my-div", "stuff.php");</code></pre>
486
* @param {Mixed} el The element to update
487
* @param {String} url The url
488
* @param {String/Object} params (optional) Url encoded param string or an object of name/value pairs
489
* @param {Object} options (optional) A config object <b>with</b> any of the Updater properties you want to set - <b>for</b>
490
* example: {disableCaching:true, indicatorText: "Loading data..."}
493
* @member Ext.Updater
495
Ext.Updater.updateElement = <b>function</b>(el, url, params, options){
496
<b>var</b> um = Ext.get(el).getUpdater();
497
Ext.apply(um, options);
498
um.update(url, params, options ? options.callback : null);
501
* @class Ext.Updater.BasicRenderer
502
* Default Content renderer. Updates the elements innerHTML <b>with</b> the responseText.
504
Ext.Updater.BasicRenderer = <b>function</b>(){};
506
Ext.Updater.BasicRenderer.prototype = {
508
* This is called when the transaction is completed and it's time to update the element - The BasicRenderer
509
* updates the elements innerHTML <b>with</b> the responseText - To perform a custom render (i.e. XML or JSON processing),
510
* create an object <b>with</b> a "render(el, response)" method and pass it to setRenderer on the Updater.
511
* @param {Ext.Element} el The element being rendered
512
* @param {Object} response The XMLHttpRequest object
513
* @param {Updater} updateManager The calling update manager
514
* @param {Function} callback A callback that will need to be called <b>if</b> loadScripts is true on the Updater
516
render : <b>function</b>(el, response, updateManager, callback){
517
el.update(response.responseText, updateManager.loadScripts, callback);
521
Ext.UpdateManager = Ext.Updater;
522
</code></pre><hr><div style="font-size:10px;text-align:center;color:gray;">Ext - Copyright © 2006-2007 Ext JS, LLC<br />All rights reserved.</div>
b'\\ No newline at end of file'