Upgrade to ExtJS 4.0.7 - Released 10/19/2011
[extjs.git] / src / direct / Manager.js
index 5c814c5..19c8679 100644 (file)
@@ -13,73 +13,62 @@ If you are unsure which license is appropriate for your use, please contact the
 
 */
 /**
- * @class Ext.direct.Manager
- * <p><b><u>Overview</u></b></p>
+ * 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).
  *
- * <p>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).</p>
+ * 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.
  *
- * <p>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.</p>
+ * # Specification
  *
- * <p><b><u>Specification</u></b></p>
+ * For additional information consult the [Ext.Direct Specification][1].
  *
- * <p>For additional information consult the
- * <a href="http://sencha.com/products/extjs/extdirect">Ext.Direct Specification</a>.</p>
+ * # Providers
  *
- * <p><b><u>Providers</u></b></p>
+ * 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:
  *
- * <p>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:</p><div class="mdetail-params"><ul>
+ * - {@link Ext.direct.JsonProvider JsonProvider} for simple JSON operations
+ * - {@link Ext.direct.PollingProvider PollingProvider} for repeated requests
+ * - {@link Ext.direct.RemotingProvider RemotingProvider} exposes server side on the client.
  *
- * <li>{@link Ext.direct.JsonProvider JsonProvider} for simple JSON operations</li>
- * <li>{@link Ext.direct.PollingProvider PollingProvider} for repeated requests</li>
- * <li>{@link Ext.direct.RemotingProvider RemotingProvider} exposes server side
- * on the client.</li>
- * </ul></div>
+ * A provider does not need to be invoked directly, providers are added via {@link Ext.direct.Manager}.{@link #addProvider}.
  *
- * <p>A provider does not need to be invoked directly, providers are added via
- * {@link Ext.direct.Manager}.{@link Ext.direct.Manager#addProvider addProvider}.</p>
+ * # Router
  *
- * <p><b><u>Router</u></b></p>
+ * 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.
  *
- * <p>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.</p>
+ * # Server side events
  *
- * <p><b><u>Server side events</u></b></p>
+ * 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.Manager.on('message', function(e){
+ *         out.append(String.format('<p><i>{0}</i></p>', e.data));
+ *         out.el.scrollTo('t', 100000, true);
+ *     });
+ *
+ *    [1]: http://sencha.com/products/extjs/extdirect
  *
- * <p>Custom events from the server may be handled by the client by adding
- * listeners, for example:</p>
- * <pre><code>
-{"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.Manager.on('message', function(e){
-    out.append(String.format('&lt;p>&lt;i>{0}&lt;/i>&lt;/p>', e.data));
-            out.el.scrollTo('t', 100000, true);
-});
- * </code></pre>
  * @singleton
+ * @alternateClassName Ext.Direct
  */
-
 Ext.define('Ext.direct.Manager', {
-    
+
     /* Begin Definitions */
     singleton: true,
-   
+
     mixins: {
         observable: 'Ext.util.Observable'
     },
-    
+
     requires: ['Ext.util.MixedCollection'],
-    
+
     statics: {
         exceptions: {
             TRANSPORT: 'xhr',
@@ -88,74 +77,75 @@ Ext.define('Ext.direct.Manager', {
             SERVER: 'exception'
         }
     },
-    
+
     /* End Definitions */
-   
+
     constructor: function(){
         var me = this;
-       
+
         me.addEvents(
             /**
              * @event event
              * Fires after an event.
-             * @param {event} e The Ext.direct.Event type that occurred.
+             * @param {Ext.direct.Event} e The Ext.direct.Event type that occurred.
              * @param {Ext.direct.Provider} provider The {@link Ext.direct.Provider Provider}.
              */
             'event',
             /**
              * @event exception
              * Fires after an event exception.
-             * @param {event} e The Ext.direct.Event type that occurred.
+             * @param {Ext.direct.Event} e The event type that occurred.
              */
             'exception'
         );
         me.transactions = Ext.create('Ext.util.MixedCollection');
         me.providers = Ext.create('Ext.util.MixedCollection');
-        
+
         me.mixins.observable.constructor.call(me);
     },
-    
-    /**
-     * 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.
-     * <pre><code>
-var pollProv = new Ext.direct.PollingProvider({
-    url: 'php/poll2.php'
-});
 
-Ext.direct.Manager.addProvider({
-    "type":"remoting",       // create a {@link 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 {@link Ext.direct.PollingProvider}
-    url:  'php/poll.php'
-}, pollProv); // reference to previously created instance
-     * </code></pre>
-     * @param {Object/Array} provider 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.
+    /**
+     * 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.Manager.addProvider({
+     *         "type":"remoting",       // create a {@link 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 {@link Ext.direct.PollingProvider}
+     *         url:  'php/poll.php'
+     *     }, pollProv); // reference to previously created instance
+     *
+     * @param {Ext.direct.Provider/Object...} provider
+     * Accepts any number of Provider descriptions (an instance or config object for
+     * a Provider). Each Provider description instructs Ext.Directhow to create
+     * client-side stub methods.
      */
     addProvider : function(provider){
         var me = this,
             args = arguments,
             i = 0,
             len;
-            
+
         if (args.length > 1) {
             for (len = args.length; i < len; ++i) {
                 me.addProvider(args[i]);
@@ -177,17 +167,16 @@ Ext.direct.Manager.addProvider({
 
         return provider;
     },
-    
+
     /**
-     * Retrieve a {@link Ext.direct.Provider provider} by the
-     * <b><tt>{@link Ext.direct.Provider#id id}</tt></b> specified when the provider is
-     * {@link #addProvider added}.
-     * @param {String/Ext.data.Provider} id The id of the provider, or the provider instance.
+     * Retrieves a {@link Ext.direct.Provider provider} by the **{@link Ext.direct.Provider#id id}** specified when the
+     * provider is {@link #addProvider added}.
+     * @param {String/Ext.direct.Provider} id The id of the provider, or the provider instance.
      */
     getProvider : function(id){
         return id.isProvider ? id : this.providers.get(id);
     },
-    
+
     /**
      * Removes the provider.
      * @param {String/Ext.direct.Provider} provider The provider instance or the id of the provider.
@@ -195,9 +184,10 @@ Ext.direct.Manager.addProvider({
      */
     removeProvider : function(provider){
         var me = this,
-            providers = me.providers,
-            provider = provider.isProvider ? provider : providers.get(provider);
-            
+            providers = me.providers;
+
+        provider = provider.isProvider ? provider : providers.get(provider);
+
         if (provider) {
             provider.un('data', me.onProviderData, me);
             providers.remove(provider);
@@ -205,9 +195,9 @@ Ext.direct.Manager.addProvider({
         }
         return null;
     },
-    
+
     /**
-     * Add a transaction to the manager.
+     * Adds a transaction to the manager.
      * @private
      * @param {Ext.direct.Transaction} transaction The transaction to add
      * @return {Ext.direct.Transaction} transaction
@@ -218,7 +208,7 @@ Ext.direct.Manager.addProvider({
     },
 
     /**
-     * Remove a transaction from the manager.
+     * Removes a transaction from the manager.
      * @private
      * @param {String/Ext.direct.Transaction} transaction The transaction/id of transaction to remove
      * @return {Ext.direct.Transaction} transaction
@@ -238,12 +228,12 @@ Ext.direct.Manager.addProvider({
     getTransaction: function(transaction){
         return transaction.isTransaction ? transaction : this.transactions.get(transaction);
     },
-    
+
     onProviderData : function(provider, event){
         var me = this,
             i = 0,
             len;
-            
+
         if (Ext.isArray(event)) {
             for (len = event.length; i < len; ++i) {
                 me.onProviderData(provider, event[i]);
@@ -252,7 +242,7 @@ Ext.direct.Manager.addProvider({
         }
         if (event.name && event.name != 'event' && event.name != 'exception') {
             me.fireEvent(event.name, event);
-        } else if (event.type == 'exception') {
+        } else if (event.status === false) {
             me.fireEvent('exception', event);
         }
         me.fireEvent('event', event, provider);