Properties Methods Events Config Options Direct Link

    Observable
      Updater

# Class Ext.Updater

Package: | Ext
Defined In: | UpdateManager.js
Class: | Updater
Extends: | Observable

Provides AJAX-style update for Element object.
Usage:

    // Get it from a Ext.Element object
    var el = Ext.get("foo");
    var mgr = el.getUpdater();
    mgr.update({
    url: "http://myserver.com/index.php",
    params: {
    param1: "foo",
    param2: "bar"
    }
    });
    ...
    mgr.formUpdate("myFormId", "http://myserver.com/index.php");

    // or directly (returns the same Updater instance)
    var mgr = new Ext.Updater("myElementId");
    mgr.startAutoRefresh(60, "http://myserver.com/index.php");
    mgr.on("update", myFcnNeedsToKnow);

       // short handed call directly from the element object
       Ext.get("foo").load({
            url: "bar.php",
            scripts: true,
            params: "param1=foo&param2=bar",
            text: "Loading Foo..."
       });

## Config Options

Config Options | Defined By
--- | ---
| listeners : Object A config object containing one or more event handlers to be added to this object during initialization. This should b... A config object containing one or more event handlers to be added to this object during initialization. This should be a valid listeners config object as specified in the addListener example for attaching multiple handlers at once. | Observable

## Public Properties

Property | Defined By
--- | ---
| defaultUrl : String Cached url to use for refreshes. Overwritten every time update() is called unless "discardUrl" param is set to true. | Updater
| disableCaching : Boolean Whether to append unique parameter on get request to disable caching (Defaults to Ext.Updater.defaults.disableCaching... Whether to append unique parameter on get request to disable caching (Defaults to Ext.Updater.defaults.disableCaching or false). | Updater
| el : Ext.Element The Element object | Updater
| formUpdateDelegate : Function Delegate for formUpdate() prebound to "this", use myUpdater.formUpdateDelegate.createCallback(arg1, arg2) to bind arg... Delegate for formUpdate() prebound to "this", use myUpdater.formUpdateDelegate.createCallback(arg1, arg2) to bind arguments | Updater
| indicatorText : String Text for loading indicator (Defaults to Ext.Updater.defaults.indicatorText or '<div class="loading-indicator">L... Text for loading indicator (Defaults to Ext.Updater.defaults.indicatorText or '<div class="loading-indicator">Loading...</div>'). | Updater
| loadScripts : Boolean True to process scripts in the output (Defaults to Ext.Updater.defaults.loadScripts (false)). | Updater
| refreshDelegate : Function Delegate for refresh() prebound to "this", use myUpdater.refreshDelegate.createCallback(arg1, arg2) to bind arguments | Updater
| renderer : Object The renderer for this Updater. Defaults to Ext.Updater.BasicRenderer. | Updater
| showLoadIndicator : String Whether to show indicatorText when loading (Defaults to Ext.Updater.defaults.showLoadIndicator or true). | Updater
| sslBlankUrl : String Blank page URL to use with SSL file uploads (Defaults to Ext.Updater.defaults.sslBlankUrl or "about:blank"). | Updater
| timeout : Number Timeout for requests or form posts in seconds (Defaults to Ext.Updater.defaults.timeout or 30 seconds). | Updater
| transaction : Object Transaction object of current executing transaction | Updater
| updateDelegate : Function Delegate for update() prebound to "this", use myUpdater.updateDelegate.createCallback(arg1, arg2) to bind arguments | Updater

## Public Methods

Method | Defined By
--- | ---
| Updater( `Mixed el`, [`Boolean forceNew`] ) Create new Updater directly. Create new Updater directly. Parameters: `el` : Mixed The element to update `forceNew` : Boolean (optional) By default the constructor checks to see if the passed element already has an Updater and if it does it returns the same instance. This will skip that check (useful for extending this class). Returns: `` | Updater
| Updater.updateElement( `Mixed el`, `String url`, [`String/Object params`], [`Object options`] ) : void Deprecated. <static> Static convenience method. This method is deprecated in favor of el.load({url:'foo.php', .... Deprecated. <static> Static convenience method. This method is deprecated in favor of el.load({url:'foo.php', ...}). Usage:
    Ext.Updater.updateElement("my-div", "stuff.php");
Parameters: `el` : Mixed The element to update `url` : String The url `params` : String/Object (optional) Url encoded param string or an object of name/value pairs `options` : Object (optional) A config object with any of the Updater properties you want to set - for example: {disableCaching:true, indicatorText: "Loading data..."} Returns: `void` | Updater
| abort() : void Aborts the executing transaction Aborts the executing transaction Parameters: None. Returns: `void` | Updater
| addEvents( `Object object` ) : void Used to define events on this Observable Used to define events on this Observable Parameters: `object` : Object The object with the events defined Returns: `void` | Observable
- | addListener( `String eventName`, `Function handler`, [`Object scope`], [`Object options`] ) : void Appends an event handler to this component Appends an event handler to this component Parameters: `eventName` : String The type of event to listen for `handler` : Function The method the event invokes `scope` : Object (optional) The scope in which to execute the handler function. The handler function's "this" context. `options` : Object (optional) An object containing handler configuration properties. This may contain any of the following properties: scope : Object The scope in which to execute the handler function. The handler function's "this" context. delay : Number The number of milliseconds to delay the invocation of the handler after the event fires. single : Boolean True to add a handler to handle just the next firing of the event, and then remove itself. buffer {Number} Causes the handler to be scheduled to run in an Ext.util.DelayedTask delayed by the specified number of milliseconds. If the event fires again within that time, the original handler is not invoked, but the new handler is scheduled in its place. Combining Options Using the options argument, it is possible to combine different types of listeners: A normalized, delayed, one-time listener that auto stops the event and passes a custom argument (forumId)
      el.on('click', this.onClick, this, {
          single: true,
          delay: 100,
          forumId: 4
      });
  Attaching multiple handlers in 1 call The method also allows for a single argument to be passed which is a config object containing properties which specify multiple handlers.
      foo.on({
          'click' : {
              fn: this.onClick,
              scope: this,
              delay: 100
          },
          'mouseover' : {
              fn: this.onMouseOver,
              scope: this
          },
          'mouseout' : {
              fn: this.onMouseOut,
              scope: this
          }
      });
  Or a shorthand syntax:
      foo.on({
          'click' : this.onClick,
          'mouseover' : this.onMouseOver,
          'mouseout' : this.onMouseOut,
           scope: this
      });
Returns: `void` | Observable
| fireEvent( `String eventName`, `Object... args` ) : Boolean Fires the specified event with the passed parameters (minus the event name). Fires the specified event with the passed parameters (minus the event name). Parameters: `eventName` : String `args` : Object... Variable number of parameters are passed to handlers Returns: `Boolean` returns false if any of the handlers return false otherwise it returns true | Observable
| formUpdate( `String/HTMLElement form`, [`String url`], [`Boolean reset`], [`Function callback`] ) : void Performs an async form post, updating this element with the response. If the form has the attribute enctype="multipar... Performs an async form post, updating this element with the response. If the form has the attribute enctype="multipart/form-data", it assumes it's a file upload. Uses this.sslBlankUrl for SSL file uploads to prevent IE security warning. Parameters: `form` : String/HTMLElement The form Id or form element `url` : String (optional) The url to pass the form to. If omitted the action attribute on the form will be used. `reset` : Boolean (optional) Whether to try to reset the form after the update `callback` : Function (optional) Callback when transaction is complete. The following parameters are passed: el : Ext.Element The Element being updated. success : Boolean True for success, false for failure. response : XMLHttpRequest The XMLHttpRequest which processed the update. Returns: `void` | Updater
| getEl() : Ext.Element Get the Element this Updater is bound to Get the Element this Updater is bound to Parameters: None. Returns: `Ext.Element` The element | Updater
| hasListener( `String eventName` ) : Boolean Checks to see if this object has any listeners for a specified event Checks to see if this object has any listeners for a specified event Parameters: `eventName` : String The name of the event to check for Returns: `Boolean` True if the event is being listened for, else false | Observable
| isUpdating() : Boolean Returns true if an update is in progress Returns true if an update is in progress Parameters: None. Returns: `Boolean` | Updater
| on( `String eventName`, `Function handler`, [`Object scope`], [`Object options`] ) : void Appends an event handler to this element (shorthand for addListener) Appends an event handler to this element (shorthand for addListener) Parameters: `eventName` : String The type of event to listen for `handler` : Function The method the event invokes `scope` : Object (optional) The scope in which to execute the handler function. The handler function's "this" context. `options` : Object (optional) Returns: `void` | Observable
| purgeListeners() : void Removes all listeners for this object Removes all listeners for this object Parameters: None. Returns: `void` | Observable
| refresh( [`Function callback`] ) : void Refresh the element with the last used url or defaultUrl. If there is no url, it returns immediately Refresh the element with the last used url or defaultUrl. If there is no url, it returns immediately Parameters: `callback` : Function (optional) Callback when transaction is complete - called with signature (oElement, bSuccess) Returns: `void` | Updater
| removeListener( `String eventName`, `Function handler`, [`Object scope`] ) : void Removes a listener Removes a listener Parameters: `eventName` : String The type of event to listen for `handler` : Function The handler to remove `scope` : Object (optional) The scope (this object) for the handler Returns: `void` | Observable
| resumeEvents() : void Resume firing events. (see suspendEvents) Resume firing events. (see suspendEvents) Parameters: None. Returns: `void` | Observable
| setDefaultUrl( `String/Function defaultUrl` ) : void Set the defaultUrl used for updates Set the defaultUrl used for updates Parameters: `defaultUrl` : String/Function The url or a function to call to get the url Returns: `void` | Updater
| setRenderer( `Object renderer` ) : void Set the content renderer for this Updater. See Ext.Updater.BasicRenderer.render for more details. Set the content renderer for this Updater. See Ext.Updater.BasicRenderer.render for more details. Parameters: `renderer` : Object The object implementing the render() method Returns: `void` | Updater
| showLoading() : void Called to update the element to "Loading" state. Override to perform custom action. Called to update the element to "Loading" state. Override to perform custom action. Parameters: None. Returns: `void` | Updater
| startAutoRefresh( `Number interval`, [`String/Function url`], [`String/Object params`], [`Function callback`], [`Boolean refreshNow`] ) : void Set this element to auto refresh. Set this element to auto refresh. Parameters: `interval` : Number How often to update (in seconds). `url` : String/Function (optional) The url for this request or a function to call to get the url (Defaults to the last used url) `params` : String/Object (optional) The parameters to pass as either a url encoded string "¶m1=1¶m2=2" or as an object {param1: 1, param2: 2} `callback` : Function (optional) Callback when transaction is complete - called with signature (oElement, bSuccess) `refreshNow` : Boolean (optional) Whether to execute the refresh now, or wait the interval Returns: `void` | Updater
| stopAutoRefresh() : void Stop auto refresh on this element. Stop auto refresh on this element. Parameters: None. Returns: `void` | Updater
| suspendEvents() : void Suspend the firing of all events. (see resumeEvents) Suspend the firing of all events. (see resumeEvents) Parameters: None. Returns: `void` | Observable
| un( `String eventName`, `Function handler`, [`Object scope`] ) : void Removes a listener (shorthand for removeListener) Removes a listener (shorthand for removeListener) Parameters: `eventName` : String The type of event to listen for `handler` : Function The handler to remove `scope` : Object (optional) The scope (this object) for the handler Returns: `void` | Observable
- | update( `Object options` ) : void Performs an asynchronous request, updating this element with the response. If params are specified it uses POST, othe... Performs an asynchronous request, updating this element with the response. If params are specified it uses POST, otherwise it uses GET. NB: Due to the asynchronous nature of remote server requests, the Element will not have been fully updated when the function returns. To postprocess the returned data, use the callback option, or an `update` event handler. Parameters: `options` : Object A config object containing any of the following options: url : String/Function The URL to request or a function which returns the URL. method : String The HTTP method to use. Defaults to POST if params are present, or GET if not. params : String/Object/Function The parameters to pass to the server. These may be specified as a urlencoded string, or as an object containing properties which represent parameters, or as a function, which returns an object. scripts : Boolean If `true` any <script> tags embedded in the response text will be extracted and executed. If this option is specified, the callback will be called after the execution of the scripts. callback : Function A function to be called when the response from the server arrives. The following parameters are passed: el : Ext.Element The Element being updated. success : Boolean True for success, false for failure. response : XMLHttpRequest The XMLHttpRequest which processed the update. options : Object The config object passed to the update call. scope : Object The scope in which to execute the callback (The callback's `this`reference.) If the `params` option is a function, this scope is used for that function also.`` discardUrl : Boolean If not passed as `false` the URL of this request becomes the default URL for this Updater object, and will be subsequently used in refresh calls. timeout : Number The timeout to use when waiting for a response. nocache : Boolean Only needed for GET requests, this option causes an extra, generated parameter to be passed to defeat caching. For example:
      um.update({
          url: "your-url.php",
          params: {param1: "foo", param2: "bar"}, // or a URL encoded string
          callback: yourFunction,
          scope: yourObject, //(optional scope)
          discardUrl: false,
          nocache: false,
          text: "Loading...",
          timeout: 30,
          scripts: false // Save time by avoiding RegExp execution.
      });
Returns: `void` | Updater

## Public Events

Event | Defined By
--- | ---
| beforeupdate : ( `Ext.Element el`, `String/Object/Function url`, `String/Object params` ) Fired before an update is made, return false from your handler and the update is cancelled. Fired before an update is made, return false from your handler and the update is cancelled. Listeners will be called with the following arguments: `el` : Ext.Element `url` : String/Object/Function `params` : String/Object | Updater
| failure : ( `Ext.Element el`, `Object oResponseObject` ) Fired on update failure. Fired on update failure. Listeners will be called with the following arguments: `el` : Ext.Element `oResponseObject` : Object The response Object | Updater
| update : ( `Ext.Element el`, `Object oResponseObject` ) Fired after successful update is made. Fired after successful update is made. Listeners will be called with the following arguments: `el` : Ext.Element `oResponseObject` : Object The response Object | Updater