Properties Methods Events Config Options Direct Link

    Observable
      Direct

# Class Ext.Direct

Package: | Ext
Defined In: | Direct.js
Class: | Direct
Extends: | Observable

Overview

Ext.Direct aims to streamline communication between the client and server by providing a single interface that reduces the amount of common code typically required to validate data and handle returned data packets (reading data, error conditions, etc).

The Ext.direct namespace includes several classes for a closer integration with the server-side. The Ext.data namespace also includes classes for working with Ext.data.Stores which are backed by data from an Ext.Direct method.

Specification

For additional information consult the Ext.Direct Specification.

Providers

Ext.Direct uses a provider architecture, where one or more providers are used to transport data to and from the server. There are several providers that exist in the core at the moment:

- JsonProvider for simple JSON operations
- PollingProvider for repeated requests
- RemotingProvider exposes server side on the client.

A provider does not need to be invoked directly, providers are added via Ext.Direct.add.

Router

Ext.Direct utilizes a "router" on the server to direct requests from the client to the appropriate server-side method. Because the Ext.Direct API is completely platform-agnostic, you could completely swap out a Java based server solution and replace it with one that uses C# without changing the client side JavaScript at all.

Server side events

Custom events from the server may be handled by the client by adding listeners, for example:

    {"type":"event","name":"message","data":"Successfully polled at: 11:19:30 am"}

    // add a handler for a 'message' event sent by the server

    Ext.Direct.on('message', function(e){
        out.append(String.format('<p><i>{0}</i></p>', e.data));
                out.el.scrollTo('t', 100000, true);
    });

This class is a singleton and cannot be created directly.

## 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 ... 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. DOM events from ExtJs Components While some ExtJs Component classes export selected DOM events (e.g. "click", "mouseover" etc), this is usually only done when extra value can be added. For example the DataView's `click` event passing the node clicked on. To access DOM events directly from a Component's HTMLElement, listeners must be added to the Element after the Component has been rendered. A plugin can simplify this step:
    // Plugin is configured with a listeners config object.
    // The Component is appended to the argument list of all handler functions.
    Ext.DomObserver = Ext.extend(Object, {
        constructor: function(config) {
            this.listeners = config.listeners ? config.listeners : config;
        },

        // Component passes itself into plugin's init method
        init: function(c) {
            var p, l = this.listeners;
            for (p in l) {
                if (Ext.isFunction(l[p])) {
                    l[p] = this.createHandler(l[p], c);
                } else {
                    l[p].fn = this.createHandler(l[p].fn, c);
                }
            }

            // Add the listeners to the Element immediately following the render call
            c.render = c.render.createSequence(function() {
                var e = c.getEl();
                if (e) {
                    e.on(l);
                }
            });
        },

        createHandler: function(fn, c) {
            return function(e) {
                fn.call(this, e, c);
            };
        }
    });

    var combo = new Ext.form.ComboBox({

        // Collapse combo when its element is clicked on
        plugins: [ new Ext.DomObserver({
            click: function(evt, comp) {
                comp.collapse();
            }
        })],
        store: myStore,
        typeAhead: true,
        mode: 'local',
        triggerAction: 'all'
    });
| Observable

## Public Properties

Property | Defined By
--- | ---
| eventTypes : Object Each event type implements a getData() method. The default event types are: <div class="mdetail-params"> event : Ex... Each event type implements a getData() method. The default event types are: `event` : Ext.Direct.Event `exception` : Ext.Direct.ExceptionEvent `rpc` : Ext.Direct.RemotingEvent | Direct
| exceptions : Object Four types of possible exceptions which can occur: <div class="mdetail-params"> Ext.Direct.exceptions.TRANSPORT : '... Four types of possible exceptions which can occur: `Ext.Direct.exceptions.TRANSPORT` : 'xhr' `Ext.Direct.exceptions.PARSE` : 'parse' `Ext.Direct.exceptions.LOGIN` : 'login' `Ext.Direct.exceptions.SERVER` : 'exception' | Direct

## Public Methods

Method | Defined By
--- | ---
| 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 object. Appends an event handler to this object. Parameters: `eventName` : String The name of the event to listen for. `handler` : Function The method the event invokes. `scope` : Object (optional) The scope (`this` reference) in which the handler function is executed. If omitted, defaults to the object which fired the event. `options` : Object (optional) An object containing handler configuration. properties. This may contain any of the following properties: scope : Object The scope (`this` reference) in which the handler function is executed. If omitted, defaults to the object which fired the event. 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. target : Observable Only call the handler if the event was fired on the target Observable, not if the event was bubbled up from a child Observable. Combining Options Using the options argument, it is possible to combine different types of listeners: A delayed, one-time listener.
      myDataView.on('click', this.onClick, this, {
          single: true,
          delay: 100
      });
  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.
      myGridPanel.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:
      myGridPanel.on({
          'click' : this.onClick,
          'mouseover' : this.onMouseOver,
          'mouseout' : this.onMouseOut,
           scope: this
      });
Returns: void | Observable
| addProvider( `Object/Array provider` ) : void Adds an Ext.Direct Provider and creates the proxy or stub methods to execute server-side methods. If the provider is... Adds an Ext.Direct Provider and creates the proxy or stub methods to execute server-side methods. If the provider is not already connected, it will auto-connect.
    var pollProv = new Ext.direct.PollingProvider({
        url: 'php/poll2.php'
    });

    Ext.Direct.addProvider(
        {
            "type":"remoting",       // create a Ext.direct.RemotingProvider

            "url":"php\/router.php", // url to connect to the Ext.Direct server-side router.

            "actions":{              // each property within the actions object represents a Class

                "TestAction":[       // array of methods within each server side Class

                {
                    "name":"doEcho", // name of method

                    "len":1
                },{
                    "name":"multiply",
                    "len":1
                },{
                    "name":"doForm",
                    "formHandler":true, // handle form on server with Ext.Direct.Transaction

                    "len":1
                }]
            },
            "namespace":"myApplication",// namespace to create the Remoting Provider in

        },{
            type: 'polling', // create a Ext.direct.PollingProvider

            url:  'php/poll.php'
        },
        pollProv // reference to previously created instance

    );
Parameters: `provider` : Object/Array Accepts either an Array of Provider descriptions (an instance or config object for a Provider) or any number of Provider descriptions as arguments. Each Provider description instructs Ext.Direct how to create client-side stub methods. Returns: void | Direct
| enableBubble( `Object events` ) : void Used to enable bubbling of events Used to enable bubbling of events Parameters: `events` : Object Returns: void | Observable
| fireEvent( `String eventName`, `Object... args` ) : Boolean Fires the specified event with the passed parameters (minus the event name). An event may be set to bubble up an Obse... Fires the specified event with the passed parameters (minus the event name). An event may be set to bubble up an Observable parent hierarchy (See Ext.Component.getBubbleTarget) by calling enableBubble. Parameters: `eventName` : String The name of the event to fire. `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
| getProvider( `String id` ) : void Retrieve a provider by the id specified when the provider is added. Retrieve a provider by the `id` specified when the provider is added. Parameters: `id` : String Unique identifier assigned to the provider when calling addProvider Returns: void | Direct
| 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
| on( `String eventName`, `Function handler`, [`Object scope`], [`Object options`] ) : void Appends an event handler to this object (shorthand for addListener.) Appends an event handler to this object (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 (`this` reference) in which the handler function is executed. If omitted, defaults to the object which fired the event. `options` : Object (optional) An object containing handler configuration. Returns: void | Observable
| purgeListeners() : void Removes all listeners for this object Removes all listeners for this object Parameters: None. Returns: void | Observable
| relayEvents( `Object o`, `Array events` ) : void Relays selected events from the specified Observable as if the events were fired by this. Relays selected events from the specified Observable as if the events were fired by `this`. Parameters: `o` : Object The Observable whose events this object is to relay. `events` : Array Array of event names to relay. Returns: void | Observable
| removeListener( `String eventName`, `Function handler`, [`Object scope`] ) : void Removes an event handler. Removes an event handler. Parameters: `eventName` : String The type of event the handler was associated with. `handler` : Function The handler to remove. This must be a reference to the function passed into the addListener call. `scope` : Object (optional) The scope originally specified for the handler. Returns: void | Observable
| resumeEvents() : void Resume firing events. (see suspendEvents) If events were suspended using the queueSuspended parameter, then all event... Resume firing events. (see suspendEvents) If events were suspended using the `queueSuspended` parameter, then all events fired during event suspension will be sent to any listeners now. Parameters: None. Returns: void | Observable
| suspendEvents( `Boolean queueSuspended` ) : void Suspend the firing of all events. (see resumeEvents) Suspend the firing of all events. (see resumeEvents) Parameters: `queueSuspended` : Boolean Pass as true to queue up suspended events to be fired after the resumeEvents call instead of discarding all suspended events; Returns: void | Observable
| un( `String eventName`, `Function handler`, [`Object scope`] ) : void Removes an event handler (shorthand for removeListener.) Removes an event handler (shorthand for removeListener.) Parameters: `eventName` : String The type of event the handler was associated with. `handler` : Function The handler to remove. This must be a reference to the function passed into the addListener call. `scope` : Object (optional) The scope originally specified for the handler. Returns: void | Observable

## Public Events

Event | Defined By
--- | ---
| event : ( `event e`, `Ext.direct.Provider provider` ) Fires after an event. Fires after an event. Listeners will be called with the following arguments: `e` : event The Ext.Direct.Event type that occurred. `provider` : Ext.direct.Provider The Provider. | Direct
| exception : ( `event e` ) Fires after an event exception. Fires after an event exception. Listeners will be called with the following arguments: `e` : event The Ext.Direct.Event type that occurred. | Direct