-/**\r
- * @class Ext.Direct\r
- * @extends Ext.util.Observable\r
- * <p><b><u>Overview</u></b></p>\r
- * \r
- * <p>Ext.Direct aims to streamline communication between the client and server\r
- * by providing a single interface that reduces the amount of common code\r
- * typically required to validate data and handle returned data packets\r
- * (reading data, error conditions, etc).</p>\r
- * \r
- * <p>The Ext.direct namespace includes several classes for a closer integration\r
- * with the server-side. The Ext.data namespace also includes classes for working\r
- * with Ext.data.Stores which are backed by data from an Ext.Direct method.</p>\r
- * \r
- * <p><b><u>Specification</u></b></p>\r
- * \r
- * <p>For additional information consult the \r
- * <a href="http://extjs.com/products/extjs/direct.php">Ext.Direct Specification</a>.</p>\r
- * \r
- * <p><b><u>Providers</u></b></p>\r
- * \r
- * <p>Ext.Direct uses a provider architecture, where one or more providers are\r
- * used to transport data to and from the server. There are several providers\r
- * that exist in the core at the moment:</p><div class="mdetail-params"><ul>\r
- * \r
- * <li>{@link Ext.direct.JsonProvider JsonProvider} for simple JSON operations</li>\r
- * <li>{@link Ext.direct.PollingProvider PollingProvider} for repeated requests</li>\r
- * <li>{@link Ext.direct.RemotingProvider RemotingProvider} exposes server side\r
- * on the client.</li>\r
- * </ul></div>\r
- * \r
- * <p>A provider does not need to be invoked directly, providers are added via\r
- * {@link Ext.Direct}.{@link Ext.Direct#add add}.</p>\r
- * \r
- * <p><b><u>Router</u></b></p>\r
- * \r
- * <p>Ext.Direct utilizes a "router" on the server to direct requests from the client\r
- * to the appropriate server-side method. Because the Ext.Direct API is completely\r
- * platform-agnostic, you could completely swap out a Java based server solution\r
- * and replace it with one that uses C# without changing the client side JavaScript\r
- * at all.</p>\r
- * \r
- * <p><b><u>Server side events</u></b></p>\r
- * \r
- * <p>Custom events from the server may be handled by the client by adding\r
- * listeners, for example:</p>\r
- * <pre><code>\r
-{"type":"event","name":"message","data":"Successfully polled at: 11:19:30 am"}\r
-\r
-// add a handler for a 'message' event sent by the server \r
-Ext.Direct.on('message', function(e){\r
- out.append(String.format('<p><i>{0}</i></p>', e.data));\r
- out.el.scrollTo('t', 100000, true);\r
-});\r
- * </code></pre>\r
- * @singleton\r
- */\r
-Ext.Direct = Ext.extend(Ext.util.Observable, {\r
- /**\r
- * Each event type implements a getData() method. The default event types are:\r
- * <div class="mdetail-params"><ul>\r
- * <li><b><tt>event</tt></b> : Ext.Direct.Event</li>\r
- * <li><b><tt>exception</tt></b> : Ext.Direct.ExceptionEvent</li>\r
- * <li><b><tt>rpc</tt></b> : Ext.Direct.RemotingEvent</li>\r
- * </ul></div>\r
- * @property eventTypes\r
- * @type Object\r
- */\r
-\r
- /**\r
- * Four types of possible exceptions which can occur:\r
- * <div class="mdetail-params"><ul>\r
- * <li><b><tt>Ext.Direct.exceptions.TRANSPORT</tt></b> : 'xhr'</li>\r
- * <li><b><tt>Ext.Direct.exceptions.PARSE</tt></b> : 'parse'</li>\r
- * <li><b><tt>Ext.Direct.exceptions.LOGIN</tt></b> : 'login'</li>\r
- * <li><b><tt>Ext.Direct.exceptions.SERVER</tt></b> : 'exception'</li>\r
- * </ul></div>\r
- * @property exceptions\r
- * @type Object\r
- */\r
- exceptions: {\r
- TRANSPORT: 'xhr',\r
- PARSE: 'parse',\r
- LOGIN: 'login',\r
- SERVER: 'exception'\r
- },\r
- \r
- // private\r
- constructor: function(){\r
- this.addEvents(\r
- /**\r
- * @event event\r
- * Fires after an event.\r
- * @param {event} e The {@link Ext.Direct#eventTypes Ext.Direct.Event type} that occurred.\r
- * @param {Ext.direct.Provider} provider The {@link Ext.direct.Provider Provider}.\r
- */\r
- 'event',\r
- /**\r
- * @event exception\r
- * Fires after an event exception.\r
- * @param {event} e The {@link Ext.Direct#eventTypes Ext.Direct.Event type} that occurred.\r
- */\r
- 'exception'\r
- );\r
- this.transactions = {};\r
- this.providers = {};\r
- },\r
-\r
- /**\r
- * Adds an Ext.Direct Provider and creates the proxy or stub methods to execute server-side methods.\r
- * If the provider is not already connected, it will auto-connect.\r
- * <pre><code>\r
-var pollProv = new Ext.direct.PollingProvider({\r
- url: 'php/poll2.php'\r
-}); \r
-\r
-Ext.Direct.addProvider(\r
- {\r
- "type":"remoting", // create a {@link Ext.direct.RemotingProvider} \r
- "url":"php\/router.php", // url to connect to the Ext.Direct server-side router.\r
- "actions":{ // each property within the actions object represents a Class \r
- "TestAction":[ // array of methods within each server side Class \r
- {\r
- "name":"doEcho", // name of method\r
- "len":1\r
- },{\r
- "name":"multiply",\r
- "len":1\r
- },{\r
- "name":"doForm",\r
- "formHandler":true, // handle form on server with Ext.Direct.Transaction \r
- "len":1\r
- }]\r
- },\r
- "namespace":"myApplication",// namespace to create the Remoting Provider in\r
- },{\r
- type: 'polling', // create a {@link Ext.direct.PollingProvider} \r
- url: 'php/poll.php'\r
- },\r
- pollProv // reference to previously created instance\r
-);\r
- * </code></pre>\r
- * @param {Object/Array} provider Accepts either an Array of Provider descriptions (an instance\r
- * or config object for a Provider) or any number of Provider descriptions as arguments. Each\r
- * Provider description instructs Ext.Direct how to create client-side stub methods.\r
- */\r
- addProvider : function(provider){ \r
- var a = arguments;\r
- if(a.length > 1){\r
- for(var i = 0, len = a.length; i < len; i++){\r
- this.addProvider(a[i]);\r
- }\r
- return;\r
- }\r
- \r
- // if provider has not already been instantiated\r
- if(!provider.events){\r
- provider = new Ext.Direct.PROVIDERS[provider.type](provider);\r
- }\r
- provider.id = provider.id || Ext.id();\r
- this.providers[provider.id] = provider;\r
-\r
- provider.on('data', this.onProviderData, this);\r
- provider.on('exception', this.onProviderException, this);\r
-\r
-\r
- if(!provider.isConnected()){\r
- provider.connect();\r
- }\r
-\r
- return provider;\r
- },\r
-\r
- /**\r
- * Retrieve a {@link Ext.direct.Provider provider} by the\r
- * <b><tt>{@link Ext.direct.Provider#id id}</tt></b> specified when the provider is\r
- * {@link #addProvider added}.\r
- * @param {String} id Unique identifier assigned to the provider when calling {@link #addProvider} \r
- */\r
- getProvider : function(id){\r
- return this.providers[id];\r
- },\r
-\r
- removeProvider : function(id){\r
- var provider = id.id ? id : this.providers[id.id];\r
- provider.un('data', this.onProviderData, this);\r
- provider.un('exception', this.onProviderException, this);\r
- delete this.providers[provider.id];\r
- return provider;\r
- },\r
-\r
- addTransaction: function(t){\r
- this.transactions[t.tid] = t;\r
- return t;\r
- },\r
-\r
- removeTransaction: function(t){\r
- delete this.transactions[t.tid || t];\r
- return t;\r
- },\r
-\r
- getTransaction: function(tid){\r
- return this.transactions[tid.tid || tid];\r
- },\r
-\r
- onProviderData : function(provider, e){\r
- if(Ext.isArray(e)){\r
- for(var i = 0, len = e.length; i < len; i++){\r
- this.onProviderData(provider, e[i]);\r
- }\r
- return;\r
- }\r
- if(e.name && e.name != 'event' && e.name != 'exception'){\r
- this.fireEvent(e.name, e);\r
- }else if(e.type == 'exception'){\r
- this.fireEvent('exception', e);\r
- }\r
- this.fireEvent('event', e, provider);\r
- },\r
-\r
- createEvent : function(response, extraProps){\r
- return new Ext.Direct.eventTypes[response.type](Ext.apply(response, extraProps));\r
- }\r
-});\r
-// overwrite impl. with static instance\r
-Ext.Direct = new Ext.Direct();\r
-\r
-Ext.Direct.TID = 1;\r
-Ext.Direct.PROVIDERS = {};/**\r
- * @class Ext.Direct.Transaction\r
- * @extends Object\r
- * <p>Supporting Class for Ext.Direct (not intended to be used directly).</p>\r
- * @constructor\r
- * @param {Object} config\r
- */\r
-Ext.Direct.Transaction = function(config){\r
- Ext.apply(this, config);\r
- this.tid = ++Ext.Direct.TID;\r
- this.retryCount = 0;\r
-};\r
-Ext.Direct.Transaction.prototype = {\r
- send: function(){\r
- this.provider.queueTransaction(this);\r
- },\r
-\r
- retry: function(){\r
- this.retryCount++;\r
- this.send();\r
- },\r
-\r
- getProvider: function(){\r
- return this.provider;\r
- }\r
-};Ext.Direct.Event = function(config){\r
- Ext.apply(this, config);\r
-}\r
-Ext.Direct.Event.prototype = {\r
- status: true,\r
- getData: function(){\r
- return this.data;\r
- }\r
-};\r
-\r
-Ext.Direct.RemotingEvent = Ext.extend(Ext.Direct.Event, {\r
- type: 'rpc',\r
- getTransaction: function(){\r
- return this.transaction || Ext.Direct.getTransaction(this.tid);\r
- }\r
-});\r
-\r
-Ext.Direct.ExceptionEvent = Ext.extend(Ext.Direct.RemotingEvent, {\r
- status: false,\r
- type: 'exception'\r
-});\r
-\r
-Ext.Direct.eventTypes = {\r
- 'rpc': Ext.Direct.RemotingEvent,\r
- 'event': Ext.Direct.Event,\r
- 'exception': Ext.Direct.ExceptionEvent\r
-};\r
-\r
-/**\r
- * @class Ext.direct.Provider\r
- * @extends Ext.util.Observable\r
- * <p>Ext.direct.Provider is an abstract class meant to be extended.</p>\r
- * \r
- * <p>For example ExtJs implements the following subclasses:</p>\r
- * <pre><code>\r
-Provider\r
-|\r
-+---{@link Ext.direct.JsonProvider JsonProvider} \r
- |\r
- +---{@link Ext.direct.PollingProvider PollingProvider} \r
- |\r
- +---{@link Ext.direct.RemotingProvider RemotingProvider} \r
- * </code></pre>\r
- * @abstract\r
- */\r
-Ext.direct.Provider = Ext.extend(Ext.util.Observable, { \r
- /**\r
- * @cfg {String} id\r
- * The unique id of the provider (defaults to an {@link Ext#id auto-assigned id}).\r
- * You should assign an id if you need to be able to access the provider later and you do\r
- * not have an object reference available, for example:\r
- * <pre><code>\r
-Ext.Direct.addProvider(\r
- {\r
- type: 'polling',\r
- url: 'php/poll.php',\r
- id: 'poll-provider'\r
- }\r
-);\r
- \r
-var p = {@link Ext.Direct Ext.Direct}.{@link Ext.Direct#getProvider getProvider}('poll-provider');\r
-p.disconnect();\r
- * </code></pre>\r
- */\r
- \r
- /**\r
- * @cfg {Number} priority\r
- * Priority of the request. Lower is higher priority, <tt>0</tt> means "duplex" (always on).\r
- * All Providers default to <tt>1</tt> except for PollingProvider which defaults to <tt>3</tt>.\r
- */ \r
- priority: 1,\r
-\r
- /**\r
- * @cfg {String} type\r
- * <b>Required</b>, <tt>undefined</tt> by default. The <tt>type</tt> of provider specified\r
- * to {@link Ext.Direct Ext.Direct}.{@link Ext.Direct#addProvider addProvider} to create a\r
- * new Provider. Acceptable values by default are:<div class="mdetail-params"><ul>\r
- * <li><b><tt>polling</tt></b> : {@link Ext.direct.PollingProvider PollingProvider}</li>\r
- * <li><b><tt>remoting</tt></b> : {@link Ext.direct.RemotingProvider RemotingProvider}</li>\r
- * </ul></div>\r
- */ \r
- \r
- // private\r
- constructor : function(config){\r
- Ext.apply(this, config);\r
- this.addEvents(\r
- /**\r
- * @event connect\r
- * Fires when the Provider connects to the server-side\r
- * @param {Ext.direct.Provider} provider The {@link Ext.direct.Provider Provider}.\r
- */ \r
- 'connect',\r
- /**\r
- * @event disconnect\r
- * Fires when the Provider disconnects from the server-side\r
- * @param {Ext.direct.Provider} provider The {@link Ext.direct.Provider Provider}.\r
- */ \r
- 'disconnect',\r
- /**\r
- * @event data\r
- * Fires when the Provider receives data from the server-side\r
- * @param {Ext.direct.Provider} provider The {@link Ext.direct.Provider Provider}.\r
- * @param {event} e The {@link Ext.Direct#eventTypes Ext.Direct.Event type} that occurred.\r
- */ \r
- 'data',\r
- /**\r
- * @event exception\r
- * Fires when the Provider receives an exception from the server-side\r
- */ \r
- 'exception'\r
- );\r
- Ext.direct.Provider.superclass.constructor.call(this, config);\r
- },\r
-\r
- /**\r
- * Returns whether or not the server-side is currently connected.\r
- * Abstract method for subclasses to implement.\r
- */\r
- isConnected: function(){\r
- return false;\r
- },\r
-\r
- /**\r
- * Abstract methods for subclasses to implement.\r
- */\r
- connect: Ext.emptyFn,\r
- \r
- /**\r
- * Abstract methods for subclasses to implement.\r
- */\r
- disconnect: Ext.emptyFn\r
-});\r
-/**\r
- * @class Ext.direct.JsonProvider\r
- * @extends Ext.direct.Provider\r
- */\r
-Ext.direct.JsonProvider = Ext.extend(Ext.direct.Provider, {\r
- parseResponse: function(xhr){\r
- if(!Ext.isEmpty(xhr.responseText)){\r
- if(typeof xhr.responseText == 'object'){\r
- return xhr.responseText;\r
- }\r
- return Ext.decode(xhr.responseText);\r
- }\r
- return null;\r
- },\r
-\r
- getEvents: function(xhr){\r
- var data = null;\r
- try{\r
- data = this.parseResponse(xhr);\r
- }catch(e){\r
- var event = new Ext.Direct.ExceptionEvent({\r
- data: e,\r
- xhr: xhr,\r
- code: Ext.Direct.exceptions.PARSE,\r
- message: 'Error parsing json response: \n\n ' + data\r
- })\r
- return [event];\r
- }\r
- var events = [];\r
- if(Ext.isArray(data)){\r
- for(var i = 0, len = data.length; i < len; i++){\r
- events.push(Ext.Direct.createEvent(data[i]));\r
- }\r
- }else{\r
- events.push(Ext.Direct.createEvent(data));\r
- }\r
- return events;\r
- }\r
-});/**\r
- * @class Ext.direct.PollingProvider\r
- * @extends Ext.direct.JsonProvider\r
- *\r
- * <p>Provides for repetitive polling of the server at distinct {@link #interval intervals}.\r
- * The initial request for data originates from the client, and then is responded to by the\r
- * server.</p>\r
- * \r
- * <p>All configurations for the PollingProvider should be generated by the server-side\r
- * API portion of the Ext.Direct stack.</p>\r
- *\r
- * <p>An instance of PollingProvider may be created directly via the new keyword or by simply\r
- * specifying <tt>type = 'polling'</tt>. For example:</p>\r
- * <pre><code>\r
-var pollA = new Ext.direct.PollingProvider({\r
- type:'polling',\r
- url: 'php/pollA.php',\r
-});\r
-Ext.Direct.addProvider(pollA);\r
-pollA.disconnect();\r
-\r
-Ext.Direct.addProvider(\r
- {\r
- type:'polling',\r
- url: 'php/pollB.php',\r
- id: 'pollB-provider'\r
- }\r
-);\r
-var pollB = Ext.Direct.getProvider('pollB-provider');\r
- * </code></pre>\r
- */\r
-Ext.direct.PollingProvider = Ext.extend(Ext.direct.JsonProvider, {\r
- /**\r
- * @cfg {Number} priority\r
- * Priority of the request (defaults to <tt>3</tt>). See {@link Ext.direct.Provider#priority}.\r
- */\r
- // override default priority\r
- priority: 3,\r
- \r
- /**\r
- * @cfg {Number} interval\r
- * How often to poll the server-side in milliseconds (defaults to <tt>3000</tt> - every\r
- * 3 seconds).\r
- */\r
- interval: 3000,\r
-\r
- /**\r
- * @cfg {Object} baseParams An object containing properties which are to be sent as parameters\r
- * on every polling request\r
- */\r
- \r
- /**\r
- * @cfg {String/Function} url\r
- * The url which the PollingProvider should contact with each request. This can also be\r
- * an imported Ext.Direct method which will accept the baseParams as its only argument.\r
- */\r
-\r
- // private\r
- constructor : function(config){\r
- Ext.direct.PollingProvider.superclass.constructor.call(this, config);\r
- this.addEvents(\r
- /**\r
- * @event beforepoll\r
- * Fired immediately before a poll takes place, an event handler can return false\r
- * in order to cancel the poll.\r
- * @param {Ext.direct.PollingProvider}\r
- */\r
- 'beforepoll', \r
- /**\r
- * @event poll\r
- * This event has not yet been implemented.\r
- * @param {Ext.direct.PollingProvider}\r
- */\r
- 'poll'\r
- );\r
- },\r
-\r
- // inherited\r
- isConnected: function(){\r
- return !!this.pollTask;\r
- },\r
-\r
- /**\r
- * Connect to the server-side and begin the polling process. To handle each\r
- * response subscribe to the data event.\r
- */\r
- connect: function(){\r
- if(this.url && !this.pollTask){\r
- this.pollTask = Ext.TaskMgr.start({\r
- run: function(){\r
- if(this.fireEvent('beforepoll', this) !== false){\r
- if(typeof this.url == 'function'){\r
- this.url(this.baseParams);\r
- }else{\r
- Ext.Ajax.request({\r
- url: this.url,\r
- callback: this.onData,\r
- scope: this,\r
- params: this.baseParams\r
- });\r
- }\r
- }\r
- },\r
- interval: this.interval,\r
- scope: this\r
- });\r
- this.fireEvent('connect', this);\r
- }else if(!this.url){\r
- throw 'Error initializing PollingProvider, no url configured.';\r
- }\r
- },\r
-\r
- /**\r
- * Disconnect from the server-side and stop the polling process. The disconnect\r
- * event will be fired on a successful disconnect.\r
- */\r
- disconnect: function(){\r
- if(this.pollTask){\r
- Ext.TaskMgr.stop(this.pollTask);\r
- delete this.pollTask;\r
- this.fireEvent('disconnect', this);\r
- }\r
- },\r
-\r
- // private\r
- onData: function(opt, success, xhr){\r
- if(success){\r
- var events = this.getEvents(xhr);\r
- for(var i = 0, len = events.length; i < len; i++){\r
- var e = events[i];\r
- this.fireEvent('data', this, e);\r
- }\r
- }else{\r
- var e = new Ext.Direct.ExceptionEvent({\r
- data: e,\r
- code: Ext.Direct.exceptions.TRANSPORT,\r
- message: 'Unable to connect to the server.',\r
- xhr: xhr\r
- });\r
- this.fireEvent('data', this, e);\r
- }\r
- }\r
-});\r
-\r
-Ext.Direct.PROVIDERS['polling'] = Ext.direct.PollingProvider;/**\r
- * @class Ext.direct.RemotingProvider\r
- * @extends Ext.direct.JsonProvider\r
- * \r
- * <p>The {@link Ext.direct.RemotingProvider RemotingProvider} exposes access to\r
- * server side methods on the client (a remote procedure call (RPC) type of\r
- * connection where the client can initiate a procedure on the server).</p>\r
- * \r
- * <p>This allows for code to be organized in a fashion that is maintainable,\r
- * while providing a clear path between client and server, something that is\r
- * not always apparent when using URLs.</p>\r
- * \r
- * <p>To accomplish this the server-side needs to describe what classes and methods\r
- * are available on the client-side. This configuration will typically be\r
- * outputted by the server-side Ext.Direct stack when the API description is built.</p>\r
- */\r
-Ext.direct.RemotingProvider = Ext.extend(Ext.direct.JsonProvider, { \r
- /**\r
- * @cfg {Object} actions\r
- * Object literal defining the server side actions and methods. For example, if\r
- * the Provider is configured with:\r
- * <pre><code>\r
-"actions":{ // each property within the 'actions' object represents a server side Class \r
- "TestAction":[ // array of methods within each server side Class to be \r
- { // stubbed out on client\r
- "name":"doEcho", \r
- "len":1 \r
- },{\r
- "name":"multiply",// name of method\r
- "len":2 // The number of parameters that will be used to create an\r
- // array of data to send to the server side function.\r
- // Ensure the server sends back a Number, not a String. \r
- },{\r
- "name":"doForm",\r
- "formHandler":true, // direct the client to use specialized form handling method \r
- "len":1\r
- }]\r
-}\r
- * </code></pre>\r
- * <p>Note that a Store is not required, a server method can be called at any time.\r
- * In the following example a <b>client side</b> handler is used to call the\r
- * server side method "multiply" in the server-side "TestAction" Class:</p>\r
- * <pre><code>\r
-TestAction.multiply(\r
- 2, 4, // pass two arguments to server, so specify len=2\r
- // callback function after the server is called\r
- // result: the result returned by the server\r
- // e: Ext.Direct.RemotingEvent object\r
- function(result, e){\r
- var t = e.getTransaction();\r
- var action = t.action; // server side Class called\r
- var method = t.method; // server side method called\r
- if(e.status){\r
- var answer = Ext.encode(result); // 8\r
- \r
- }else{\r
- var msg = e.message; // failure message\r
- }\r
- }\r
-);\r
- * </code></pre>\r
- * In the example above, the server side "multiply" function will be passed two\r
- * arguments (2 and 4). The "multiply" method should return the value 8 which will be\r
- * available as the <tt>result</tt> in the example above. \r
- */\r
- \r
- /**\r
- * @cfg {String/Object} namespace\r
- * Namespace for the Remoting Provider (defaults to the browser global scope of <i>window</i>).\r
- * Explicitly specify the namespace Object, or specify a String to have a\r
- * {@link Ext#namespace namespace created} implicitly.\r
- */\r
- \r
- /**\r
- * @cfg {String} url\r
- * <b>Required<b>. The url to connect to the {@link Ext.Direct} server-side router. \r
- */\r
- \r
- /**\r
- * @cfg {String} enableUrlEncode\r
- * Specify which param will hold the arguments for the method.\r
- * Defaults to <tt>'data'</tt>.\r
- */\r
- \r
- /**\r
- * @cfg {Number/Boolean} enableBuffer\r
- * <p><tt>true</tt> or <tt>false</tt> to enable or disable combining of method\r
- * calls. If a number is specified this is the amount of time in milliseconds\r
- * to wait before sending a batched request (defaults to <tt>10</tt>).</p>\r
- * <br><p>Calls which are received within the specified timeframe will be\r
- * concatenated together and sent in a single request, optimizing the\r
- * application by reducing the amount of round trips that have to be made\r
- * to the server.</p>\r
- */\r
- enableBuffer: 10,\r
- \r
- /**\r
- * @cfg {Number} maxRetries\r
- * Number of times to re-attempt delivery on failure of a call. Defaults to <tt>1</tt>.\r
- */\r
- maxRetries: 1,\r
- \r
- /**\r
- * @cfg {Number} timeout\r
- * The timeout to use for each request. Defaults to <tt>undefined</tt>.\r
- */\r
- timeout: undefined,\r
-\r
- constructor : function(config){\r
- Ext.direct.RemotingProvider.superclass.constructor.call(this, config);\r
- this.addEvents(\r
- /**\r
- * @event beforecall\r
- * Fires immediately before the client-side sends off the RPC call.\r
- * By returning false from an event handler you can prevent the call from\r
- * executing.\r
- * @param {Ext.direct.RemotingProvider} provider\r
- * @param {Ext.Direct.Transaction} transaction\r
- */ \r
- 'beforecall', \r
- /**\r
- * @event call\r
- * Fires immediately after the request to the server-side is sent. This does\r
- * NOT fire after the response has come back from the call.\r
- * @param {Ext.direct.RemotingProvider} provider\r
- * @param {Ext.Direct.Transaction} transaction\r
- */ \r
- 'call'\r
- );\r
- this.namespace = (Ext.isString(this.namespace)) ? Ext.ns(this.namespace) : this.namespace || window;\r
- this.transactions = {};\r
- this.callBuffer = [];\r
- },\r
-\r
- // private\r
- initAPI : function(){\r
- var o = this.actions;\r
- for(var c in o){\r
- var cls = this.namespace[c] || (this.namespace[c] = {}),\r
- ms = o[c];\r
- for(var i = 0, len = ms.length; i < len; i++){\r
- var m = ms[i];\r
- cls[m.name] = this.createMethod(c, m);\r
- }\r
- }\r
- },\r
-\r
- // inherited\r
- isConnected: function(){\r
- return !!this.connected;\r
- },\r
-\r
- connect: function(){\r
- if(this.url){\r
- this.initAPI();\r
- this.connected = true;\r
- this.fireEvent('connect', this);\r
- }else if(!this.url){\r
- throw 'Error initializing RemotingProvider, no url configured.';\r
- }\r
- },\r
-\r
- disconnect: function(){\r
- if(this.connected){\r
- this.connected = false;\r
- this.fireEvent('disconnect', this);\r
- }\r
- },\r
-\r
- onData: function(opt, success, xhr){\r
- if(success){\r
- var events = this.getEvents(xhr);\r
- for(var i = 0, len = events.length; i < len; i++){\r
- var e = events[i],\r
- t = this.getTransaction(e);\r
- this.fireEvent('data', this, e);\r
- if(t){\r
- this.doCallback(t, e, true);\r
- Ext.Direct.removeTransaction(t);\r
- }\r
- }\r
- }else{\r
- var ts = [].concat(opt.ts);\r
- for(var i = 0, len = ts.length; i < len; i++){\r
- var t = this.getTransaction(ts[i]);\r
- if(t && t.retryCount < this.maxRetries){\r
- t.retry();\r
- }else{\r
- var e = new Ext.Direct.ExceptionEvent({\r
- data: e,\r
- transaction: t,\r
- code: Ext.Direct.exceptions.TRANSPORT,\r
- message: 'Unable to connect to the server.',\r
- xhr: xhr\r
- });\r
- this.fireEvent('data', this, e);\r
- if(t){\r
- this.doCallback(t, e, false);\r
- Ext.Direct.removeTransaction(t);\r
- }\r
- }\r
- }\r
- }\r
- },\r
-\r
- getCallData: function(t){\r
- return {\r
- action: t.action,\r
- method: t.method,\r
- data: t.data,\r
- type: 'rpc',\r
- tid: t.tid\r
- };\r
- },\r
-\r
- doSend : function(data){\r
- var o = {\r
- url: this.url,\r
- callback: this.onData,\r
- scope: this,\r
- ts: data,\r
- timeout: this.timeout\r
- }, callData;\r
-\r
- if(Ext.isArray(data)){\r
- callData = [];\r
- for(var i = 0, len = data.length; i < len; i++){\r
- callData.push(this.getCallData(data[i]));\r
- }\r
- }else{\r
- callData = this.getCallData(data);\r
- }\r
-\r
- if(this.enableUrlEncode){\r
- var params = {};\r
- params[Ext.isString(this.enableUrlEncode) ? this.enableUrlEncode : 'data'] = Ext.encode(callData);\r
- o.params = params;\r
- }else{\r
- o.jsonData = callData;\r
- }\r
- Ext.Ajax.request(o);\r
- },\r
-\r
- combineAndSend : function(){\r
- var len = this.callBuffer.length;\r
- if(len > 0){\r
- this.doSend(len == 1 ? this.callBuffer[0] : this.callBuffer);\r
- this.callBuffer = [];\r
- }\r
- },\r
-\r
- queueTransaction: function(t){\r
- if(t.form){\r
- this.processForm(t);\r
- return;\r
- }\r
- this.callBuffer.push(t);\r
- if(this.enableBuffer){\r
- if(!this.callTask){\r
- this.callTask = new Ext.util.DelayedTask(this.combineAndSend, this);\r
- }\r
- this.callTask.delay(Ext.isNumber(this.enableBuffer) ? this.enableBuffer : 10);\r
- }else{\r
- this.combineAndSend();\r
- }\r
- },\r
-\r
- doCall : function(c, m, args){\r
- var data = null, hs = args[m.len], scope = args[m.len+1];\r
-\r
- if(m.len !== 0){\r
- data = args.slice(0, m.len);\r
- }\r
-\r
- var t = new Ext.Direct.Transaction({\r
- provider: this,\r
- args: args,\r
- action: c,\r
- method: m.name,\r
- data: data,\r
- cb: scope && Ext.isFunction(hs) ? hs.createDelegate(scope) : hs\r
- });\r
-\r
- if(this.fireEvent('beforecall', this, t) !== false){\r
- Ext.Direct.addTransaction(t);\r
- this.queueTransaction(t);\r
- this.fireEvent('call', this, t);\r
- }\r
- },\r
-\r
- doForm : function(c, m, form, callback, scope){\r
- var t = new Ext.Direct.Transaction({\r
- provider: this,\r
- action: c,\r
- method: m.name,\r
- args:[form, callback, scope],\r
- cb: scope && Ext.isFunction(callback) ? callback.createDelegate(scope) : callback,\r
- isForm: true\r
- });\r
-\r
- if(this.fireEvent('beforecall', this, t) !== false){\r
- Ext.Direct.addTransaction(t);\r
- var isUpload = String(form.getAttribute("enctype")).toLowerCase() == 'multipart/form-data',\r
- params = {\r
- extTID: t.tid,\r
- extAction: c,\r
- extMethod: m.name,\r
- extType: 'rpc',\r
- extUpload: String(isUpload)\r
- };\r
- \r
- // change made from typeof callback check to callback.params\r
- // to support addl param passing in DirectSubmit EAC 6/2\r
- Ext.apply(t, {\r
- form: Ext.getDom(form),\r
- isUpload: isUpload,\r
- params: callback && Ext.isObject(callback.params) ? Ext.apply(params, callback.params) : params\r
- });\r
- this.fireEvent('call', this, t);\r
- this.processForm(t);\r
- }\r
- },\r
- \r
- processForm: function(t){\r
- Ext.Ajax.request({\r
- url: this.url,\r
- params: t.params,\r
- callback: this.onData,\r
- scope: this,\r
- form: t.form,\r
- isUpload: t.isUpload,\r
- ts: t\r
- });\r
- },\r
-\r
- createMethod : function(c, m){\r
- var f;\r
- if(!m.formHandler){\r
- f = function(){\r
- this.doCall(c, m, Array.prototype.slice.call(arguments, 0));\r
- }.createDelegate(this);\r
- }else{\r
- f = function(form, callback, scope){\r
- this.doForm(c, m, form, callback, scope);\r
- }.createDelegate(this);\r
- }\r
- f.directCfg = {\r
- action: c,\r
- method: m\r
- };\r
- return f;\r
- },\r
-\r
- getTransaction: function(opt){\r
- return opt && opt.tid ? Ext.Direct.getTransaction(opt.tid) : null;\r
- },\r
-\r
- doCallback: function(t, e){\r
- var fn = e.status ? 'success' : 'failure';\r
- if(t && t.cb){\r
- var hs = t.cb,\r
- result = Ext.isDefined(e.result) ? e.result : e.data;\r
- if(Ext.isFunction(hs)){\r
- hs(result, e);\r
- } else{\r
- Ext.callback(hs[fn], hs.scope, [result, e]);\r
- Ext.callback(hs.callback, hs.scope, [result, e]);\r
- }\r
- }\r
- }\r
-});\r
+/**
+ * @class Ext.Direct
+ * @extends Ext.util.Observable
+ * <p><b><u>Overview</u></b></p>
+ *
+ * <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>
+ *
+ * <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>
+ *
+ * <p><b><u>Specification</u></b></p>
+ *
+ * <p>For additional information consult the
+ * <a href="http://extjs.com/products/extjs/direct.php">Ext.Direct Specification</a>.</p>
+ *
+ * <p><b><u>Providers</u></b></p>
+ *
+ * <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>
+ *
+ * <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>
+ *
+ * <p>A provider does not need to be invoked directly, providers are added via
+ * {@link Ext.Direct}.{@link Ext.Direct#add add}.</p>
+ *
+ * <p><b><u>Router</u></b></p>
+ *
+ * <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>
+ *
+ * <p><b><u>Server side events</u></b></p>
+ *
+ * <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.on('message', function(e){
+ out.append(String.format('<p><i>{0}</i></p>', e.data));
+ out.el.scrollTo('t', 100000, true);
+});
+ * </code></pre>
+ * @singleton
+ */
+Ext.Direct = Ext.extend(Ext.util.Observable, {
+ /**
+ * Each event type implements a getData() method. The default event types are:
+ * <div class="mdetail-params"><ul>
+ * <li><b><tt>event</tt></b> : Ext.Direct.Event</li>
+ * <li><b><tt>exception</tt></b> : Ext.Direct.ExceptionEvent</li>
+ * <li><b><tt>rpc</tt></b> : Ext.Direct.RemotingEvent</li>
+ * </ul></div>
+ * @property eventTypes
+ * @type Object
+ */
+
+ /**
+ * Four types of possible exceptions which can occur:
+ * <div class="mdetail-params"><ul>
+ * <li><b><tt>Ext.Direct.exceptions.TRANSPORT</tt></b> : 'xhr'</li>
+ * <li><b><tt>Ext.Direct.exceptions.PARSE</tt></b> : 'parse'</li>
+ * <li><b><tt>Ext.Direct.exceptions.LOGIN</tt></b> : 'login'</li>
+ * <li><b><tt>Ext.Direct.exceptions.SERVER</tt></b> : 'exception'</li>
+ * </ul></div>
+ * @property exceptions
+ * @type Object
+ */
+ exceptions: {
+ TRANSPORT: 'xhr',
+ PARSE: 'parse',
+ LOGIN: 'login',
+ SERVER: 'exception'
+ },
+
+ // private
+ constructor: function(){
+ this.addEvents(
+ /**
+ * @event event
+ * Fires after an event.
+ * @param {event} e The {@link Ext.Direct#eventTypes 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 {@link Ext.Direct#eventTypes Ext.Direct.Event type} that occurred.
+ */
+ 'exception'
+ );
+ this.transactions = {};
+ this.providers = {};
+ },
+
+ /**
+ * 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.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.
+ */
+ addProvider : function(provider){
+ var a = arguments;
+ if(a.length > 1){
+ for(var i = 0, len = a.length; i < len; i++){
+ this.addProvider(a[i]);
+ }
+ return;
+ }
+
+ // if provider has not already been instantiated
+ if(!provider.events){
+ provider = new Ext.Direct.PROVIDERS[provider.type](provider);
+ }
+ provider.id = provider.id || Ext.id();
+ this.providers[provider.id] = provider;
+
+ provider.on('data', this.onProviderData, this);
+ provider.on('exception', this.onProviderException, this);
+
+
+ if(!provider.isConnected()){
+ provider.connect();
+ }
+
+ 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} id Unique identifier assigned to the provider when calling {@link #addProvider}
+ */
+ getProvider : function(id){
+ return this.providers[id];
+ },
+
+ removeProvider : function(id){
+ var provider = id.id ? id : this.providers[id];
+ provider.un('data', this.onProviderData, this);
+ provider.un('exception', this.onProviderException, this);
+ delete this.providers[provider.id];
+ return provider;
+ },
+
+ addTransaction: function(t){
+ this.transactions[t.tid] = t;
+ return t;
+ },
+
+ removeTransaction: function(t){
+ delete this.transactions[t.tid || t];
+ return t;
+ },
+
+ getTransaction: function(tid){
+ return this.transactions[tid.tid || tid];
+ },
+
+ onProviderData : function(provider, e){
+ if(Ext.isArray(e)){
+ for(var i = 0, len = e.length; i < len; i++){
+ this.onProviderData(provider, e[i]);
+ }
+ return;
+ }
+ if(e.name && e.name != 'event' && e.name != 'exception'){
+ this.fireEvent(e.name, e);
+ }else if(e.type == 'exception'){
+ this.fireEvent('exception', e);
+ }
+ this.fireEvent('event', e, provider);
+ },
+
+ createEvent : function(response, extraProps){
+ return new Ext.Direct.eventTypes[response.type](Ext.apply(response, extraProps));
+ }
+});
+// overwrite impl. with static instance
+Ext.Direct = new Ext.Direct();
+
+Ext.Direct.TID = 1;
+Ext.Direct.PROVIDERS = {};/**
+ * @class Ext.Direct.Transaction
+ * @extends Object
+ * <p>Supporting Class for Ext.Direct (not intended to be used directly).</p>
+ * @constructor
+ * @param {Object} config
+ */
+Ext.Direct.Transaction = function(config){
+ Ext.apply(this, config);
+ this.tid = ++Ext.Direct.TID;
+ this.retryCount = 0;
+};
+Ext.Direct.Transaction.prototype = {
+ send: function(){
+ this.provider.queueTransaction(this);
+ },
+
+ retry: function(){
+ this.retryCount++;
+ this.send();
+ },
+
+ getProvider: function(){
+ return this.provider;
+ }
+};Ext.Direct.Event = function(config){
+ Ext.apply(this, config);
+};
+
+Ext.Direct.Event.prototype = {
+ status: true,
+ getData: function(){
+ return this.data;
+ }
+};
+
+Ext.Direct.RemotingEvent = Ext.extend(Ext.Direct.Event, {
+ type: 'rpc',
+ getTransaction: function(){
+ return this.transaction || Ext.Direct.getTransaction(this.tid);
+ }
+});
+
+Ext.Direct.ExceptionEvent = Ext.extend(Ext.Direct.RemotingEvent, {
+ status: false,
+ type: 'exception'
+});
+
+Ext.Direct.eventTypes = {
+ 'rpc': Ext.Direct.RemotingEvent,
+ 'event': Ext.Direct.Event,
+ 'exception': Ext.Direct.ExceptionEvent
+};
+/**
+ * @class Ext.direct.Provider
+ * @extends Ext.util.Observable
+ * <p>Ext.direct.Provider is an abstract class meant to be extended.</p>
+ *
+ * <p>For example ExtJs implements the following subclasses:</p>
+ * <pre><code>
+Provider
+|
++---{@link Ext.direct.JsonProvider JsonProvider}
+ |
+ +---{@link Ext.direct.PollingProvider PollingProvider}
+ |
+ +---{@link Ext.direct.RemotingProvider RemotingProvider}
+ * </code></pre>
+ * @abstract
+ */
+Ext.direct.Provider = Ext.extend(Ext.util.Observable, {
+ /**
+ * @cfg {String} id
+ * The unique id of the provider (defaults to an {@link Ext#id auto-assigned id}).
+ * You should assign an id if you need to be able to access the provider later and you do
+ * not have an object reference available, for example:
+ * <pre><code>
+Ext.Direct.addProvider(
+ {
+ type: 'polling',
+ url: 'php/poll.php',
+ id: 'poll-provider'
+ }
+);
+
+var p = {@link Ext.Direct Ext.Direct}.{@link Ext.Direct#getProvider getProvider}('poll-provider');
+p.disconnect();
+ * </code></pre>
+ */
+
+ /**
+ * @cfg {Number} priority
+ * Priority of the request. Lower is higher priority, <tt>0</tt> means "duplex" (always on).
+ * All Providers default to <tt>1</tt> except for PollingProvider which defaults to <tt>3</tt>.
+ */
+ priority: 1,
+
+ /**
+ * @cfg {String} type
+ * <b>Required</b>, <tt>undefined</tt> by default. The <tt>type</tt> of provider specified
+ * to {@link Ext.Direct Ext.Direct}.{@link Ext.Direct#addProvider addProvider} to create a
+ * new Provider. Acceptable values by default are:<div class="mdetail-params"><ul>
+ * <li><b><tt>polling</tt></b> : {@link Ext.direct.PollingProvider PollingProvider}</li>
+ * <li><b><tt>remoting</tt></b> : {@link Ext.direct.RemotingProvider RemotingProvider}</li>
+ * </ul></div>
+ */
+
+ // private
+ constructor : function(config){
+ Ext.apply(this, config);
+ this.addEvents(
+ /**
+ * @event connect
+ * Fires when the Provider connects to the server-side
+ * @param {Ext.direct.Provider} provider The {@link Ext.direct.Provider Provider}.
+ */
+ 'connect',
+ /**
+ * @event disconnect
+ * Fires when the Provider disconnects from the server-side
+ * @param {Ext.direct.Provider} provider The {@link Ext.direct.Provider Provider}.
+ */
+ 'disconnect',
+ /**
+ * @event data
+ * Fires when the Provider receives data from the server-side
+ * @param {Ext.direct.Provider} provider The {@link Ext.direct.Provider Provider}.
+ * @param {event} e The {@link Ext.Direct#eventTypes Ext.Direct.Event type} that occurred.
+ */
+ 'data',
+ /**
+ * @event exception
+ * Fires when the Provider receives an exception from the server-side
+ */
+ 'exception'
+ );
+ Ext.direct.Provider.superclass.constructor.call(this, config);
+ },
+
+ /**
+ * Returns whether or not the server-side is currently connected.
+ * Abstract method for subclasses to implement.
+ */
+ isConnected: function(){
+ return false;
+ },
+
+ /**
+ * Abstract methods for subclasses to implement.
+ */
+ connect: Ext.emptyFn,
+
+ /**
+ * Abstract methods for subclasses to implement.
+ */
+ disconnect: Ext.emptyFn
+});
+/**
+ * @class Ext.direct.JsonProvider
+ * @extends Ext.direct.Provider
+ */
+Ext.direct.JsonProvider = Ext.extend(Ext.direct.Provider, {
+ parseResponse: function(xhr){
+ if(!Ext.isEmpty(xhr.responseText)){
+ if(typeof xhr.responseText == 'object'){
+ return xhr.responseText;
+ }
+ return Ext.decode(xhr.responseText);
+ }
+ return null;
+ },
+
+ getEvents: function(xhr){
+ var data = null;
+ try{
+ data = this.parseResponse(xhr);
+ }catch(e){
+ var event = new Ext.Direct.ExceptionEvent({
+ data: e,
+ xhr: xhr,
+ code: Ext.Direct.exceptions.PARSE,
+ message: 'Error parsing json response: \n\n ' + data
+ });
+ return [event];
+ }
+ var events = [];
+ if(Ext.isArray(data)){
+ for(var i = 0, len = data.length; i < len; i++){
+ events.push(Ext.Direct.createEvent(data[i]));
+ }
+ }else{
+ events.push(Ext.Direct.createEvent(data));
+ }
+ return events;
+ }
+});/**
+ * @class Ext.direct.PollingProvider
+ * @extends Ext.direct.JsonProvider
+ *
+ * <p>Provides for repetitive polling of the server at distinct {@link #interval intervals}.
+ * The initial request for data originates from the client, and then is responded to by the
+ * server.</p>
+ *
+ * <p>All configurations for the PollingProvider should be generated by the server-side
+ * API portion of the Ext.Direct stack.</p>
+ *
+ * <p>An instance of PollingProvider may be created directly via the new keyword or by simply
+ * specifying <tt>type = 'polling'</tt>. For example:</p>
+ * <pre><code>
+var pollA = new Ext.direct.PollingProvider({
+ type:'polling',
+ url: 'php/pollA.php',
+});
+Ext.Direct.addProvider(pollA);
+pollA.disconnect();
+
+Ext.Direct.addProvider(
+ {
+ type:'polling',
+ url: 'php/pollB.php',
+ id: 'pollB-provider'
+ }
+);
+var pollB = Ext.Direct.getProvider('pollB-provider');
+ * </code></pre>
+ */
+Ext.direct.PollingProvider = Ext.extend(Ext.direct.JsonProvider, {
+ /**
+ * @cfg {Number} priority
+ * Priority of the request (defaults to <tt>3</tt>). See {@link Ext.direct.Provider#priority}.
+ */
+ // override default priority
+ priority: 3,
+
+ /**
+ * @cfg {Number} interval
+ * How often to poll the server-side in milliseconds (defaults to <tt>3000</tt> - every
+ * 3 seconds).
+ */
+ interval: 3000,
+
+ /**
+ * @cfg {Object} baseParams An object containing properties which are to be sent as parameters
+ * on every polling request
+ */
+
+ /**
+ * @cfg {String/Function} url
+ * The url which the PollingProvider should contact with each request. This can also be
+ * an imported Ext.Direct method which will accept the baseParams as its only argument.
+ */
+
+ // private
+ constructor : function(config){
+ Ext.direct.PollingProvider.superclass.constructor.call(this, config);
+ this.addEvents(
+ /**
+ * @event beforepoll
+ * Fired immediately before a poll takes place, an event handler can return false
+ * in order to cancel the poll.
+ * @param {Ext.direct.PollingProvider}
+ */
+ 'beforepoll',
+ /**
+ * @event poll
+ * This event has not yet been implemented.
+ * @param {Ext.direct.PollingProvider}
+ */
+ 'poll'
+ );
+ },
+
+ // inherited
+ isConnected: function(){
+ return !!this.pollTask;
+ },
+
+ /**
+ * Connect to the server-side and begin the polling process. To handle each
+ * response subscribe to the data event.
+ */
+ connect: function(){
+ if(this.url && !this.pollTask){
+ this.pollTask = Ext.TaskMgr.start({
+ run: function(){
+ if(this.fireEvent('beforepoll', this) !== false){
+ if(typeof this.url == 'function'){
+ this.url(this.baseParams);
+ }else{
+ Ext.Ajax.request({
+ url: this.url,
+ callback: this.onData,
+ scope: this,
+ params: this.baseParams
+ });
+ }
+ }
+ },
+ interval: this.interval,
+ scope: this
+ });
+ this.fireEvent('connect', this);
+ }else if(!this.url){
+ throw 'Error initializing PollingProvider, no url configured.';
+ }
+ },
+
+ /**
+ * Disconnect from the server-side and stop the polling process. The disconnect
+ * event will be fired on a successful disconnect.
+ */
+ disconnect: function(){
+ if(this.pollTask){
+ Ext.TaskMgr.stop(this.pollTask);
+ delete this.pollTask;
+ this.fireEvent('disconnect', this);
+ }
+ },
+
+ // private
+ onData: function(opt, success, xhr){
+ if(success){
+ var events = this.getEvents(xhr);
+ for(var i = 0, len = events.length; i < len; i++){
+ var e = events[i];
+ this.fireEvent('data', this, e);
+ }
+ }else{
+ var e = new Ext.Direct.ExceptionEvent({
+ data: e,
+ code: Ext.Direct.exceptions.TRANSPORT,
+ message: 'Unable to connect to the server.',
+ xhr: xhr
+ });
+ this.fireEvent('data', this, e);
+ }
+ }
+});
+
+Ext.Direct.PROVIDERS['polling'] = Ext.direct.PollingProvider;/**
+ * @class Ext.direct.RemotingProvider
+ * @extends Ext.direct.JsonProvider
+ *
+ * <p>The {@link Ext.direct.RemotingProvider RemotingProvider} exposes access to
+ * server side methods on the client (a remote procedure call (RPC) type of
+ * connection where the client can initiate a procedure on the server).</p>
+ *
+ * <p>This allows for code to be organized in a fashion that is maintainable,
+ * while providing a clear path between client and server, something that is
+ * not always apparent when using URLs.</p>
+ *
+ * <p>To accomplish this the server-side needs to describe what classes and methods
+ * are available on the client-side. This configuration will typically be
+ * outputted by the server-side Ext.Direct stack when the API description is built.</p>
+ */
+Ext.direct.RemotingProvider = Ext.extend(Ext.direct.JsonProvider, {
+ /**
+ * @cfg {Object} actions
+ * Object literal defining the server side actions and methods. For example, if
+ * the Provider is configured with:
+ * <pre><code>
+"actions":{ // each property within the 'actions' object represents a server side Class
+ "TestAction":[ // array of methods within each server side Class to be
+ { // stubbed out on client
+ "name":"doEcho",
+ "len":1
+ },{
+ "name":"multiply",// name of method
+ "len":2 // The number of parameters that will be used to create an
+ // array of data to send to the server side function.
+ // Ensure the server sends back a Number, not a String.
+ },{
+ "name":"doForm",
+ "formHandler":true, // direct the client to use specialized form handling method
+ "len":1
+ }]
+}
+ * </code></pre>
+ * <p>Note that a Store is not required, a server method can be called at any time.
+ * In the following example a <b>client side</b> handler is used to call the
+ * server side method "multiply" in the server-side "TestAction" Class:</p>
+ * <pre><code>
+TestAction.multiply(
+ 2, 4, // pass two arguments to server, so specify len=2
+ // callback function after the server is called
+ // result: the result returned by the server
+ // e: Ext.Direct.RemotingEvent object
+ function(result, e){
+ var t = e.getTransaction();
+ var action = t.action; // server side Class called
+ var method = t.method; // server side method called
+ if(e.status){
+ var answer = Ext.encode(result); // 8
+
+ }else{
+ var msg = e.message; // failure message
+ }
+ }
+);
+ * </code></pre>
+ * In the example above, the server side "multiply" function will be passed two
+ * arguments (2 and 4). The "multiply" method should return the value 8 which will be
+ * available as the <tt>result</tt> in the example above.
+ */
+
+ /**
+ * @cfg {String/Object} namespace
+ * Namespace for the Remoting Provider (defaults to the browser global scope of <i>window</i>).
+ * Explicitly specify the namespace Object, or specify a String to have a
+ * {@link Ext#namespace namespace created} implicitly.
+ */
+
+ /**
+ * @cfg {String} url
+ * <b>Required<b>. The url to connect to the {@link Ext.Direct} server-side router.
+ */
+
+ /**
+ * @cfg {String} enableUrlEncode
+ * Specify which param will hold the arguments for the method.
+ * Defaults to <tt>'data'</tt>.
+ */
+
+ /**
+ * @cfg {Number/Boolean} enableBuffer
+ * <p><tt>true</tt> or <tt>false</tt> to enable or disable combining of method
+ * calls. If a number is specified this is the amount of time in milliseconds
+ * to wait before sending a batched request (defaults to <tt>10</tt>).</p>
+ * <br><p>Calls which are received within the specified timeframe will be
+ * concatenated together and sent in a single request, optimizing the
+ * application by reducing the amount of round trips that have to be made
+ * to the server.</p>
+ */
+ enableBuffer: 10,
+
+ /**
+ * @cfg {Number} maxRetries
+ * Number of times to re-attempt delivery on failure of a call. Defaults to <tt>1</tt>.
+ */
+ maxRetries: 1,
+
+ /**
+ * @cfg {Number} timeout
+ * The timeout to use for each request. Defaults to <tt>undefined</tt>.
+ */
+ timeout: undefined,
+
+ constructor : function(config){
+ Ext.direct.RemotingProvider.superclass.constructor.call(this, config);
+ this.addEvents(
+ /**
+ * @event beforecall
+ * Fires immediately before the client-side sends off the RPC call.
+ * By returning false from an event handler you can prevent the call from
+ * executing.
+ * @param {Ext.direct.RemotingProvider} provider
+ * @param {Ext.Direct.Transaction} transaction
+ * @param {Object} meta The meta data
+ */
+ 'beforecall',
+ /**
+ * @event call
+ * Fires immediately after the request to the server-side is sent. This does
+ * NOT fire after the response has come back from the call.
+ * @param {Ext.direct.RemotingProvider} provider
+ * @param {Ext.Direct.Transaction} transaction
+ * @param {Object} meta The meta data
+ */
+ 'call'
+ );
+ this.namespace = (Ext.isString(this.namespace)) ? Ext.ns(this.namespace) : this.namespace || window;
+ this.transactions = {};
+ this.callBuffer = [];
+ },
+
+ // private
+ initAPI : function(){
+ var o = this.actions;
+ for(var c in o){
+ var cls = this.namespace[c] || (this.namespace[c] = {}),
+ ms = o[c];
+ for(var i = 0, len = ms.length; i < len; i++){
+ var m = ms[i];
+ cls[m.name] = this.createMethod(c, m);
+ }
+ }
+ },
+
+ // inherited
+ isConnected: function(){
+ return !!this.connected;
+ },
+
+ connect: function(){
+ if(this.url){
+ this.initAPI();
+ this.connected = true;
+ this.fireEvent('connect', this);
+ }else if(!this.url){
+ throw 'Error initializing RemotingProvider, no url configured.';
+ }
+ },
+
+ disconnect: function(){
+ if(this.connected){
+ this.connected = false;
+ this.fireEvent('disconnect', this);
+ }
+ },
+
+ onData: function(opt, success, xhr){
+ if(success){
+ var events = this.getEvents(xhr);
+ for(var i = 0, len = events.length; i < len; i++){
+ var e = events[i],
+ t = this.getTransaction(e);
+ this.fireEvent('data', this, e);
+ if(t){
+ this.doCallback(t, e, true);
+ Ext.Direct.removeTransaction(t);
+ }
+ }
+ }else{
+ var ts = [].concat(opt.ts);
+ for(var i = 0, len = ts.length; i < len; i++){
+ var t = this.getTransaction(ts[i]);
+ if(t && t.retryCount < this.maxRetries){
+ t.retry();
+ }else{
+ var e = new Ext.Direct.ExceptionEvent({
+ data: e,
+ transaction: t,
+ code: Ext.Direct.exceptions.TRANSPORT,
+ message: 'Unable to connect to the server.',
+ xhr: xhr
+ });
+ this.fireEvent('data', this, e);
+ if(t){
+ this.doCallback(t, e, false);
+ Ext.Direct.removeTransaction(t);
+ }
+ }
+ }
+ }
+ },
+
+ getCallData: function(t){
+ return {
+ action: t.action,
+ method: t.method,
+ data: t.data,
+ type: 'rpc',
+ tid: t.tid
+ };
+ },
+
+ doSend : function(data){
+ var o = {
+ url: this.url,
+ callback: this.onData,
+ scope: this,
+ ts: data,
+ timeout: this.timeout
+ }, callData;
+
+ if(Ext.isArray(data)){
+ callData = [];
+ for(var i = 0, len = data.length; i < len; i++){
+ callData.push(this.getCallData(data[i]));
+ }
+ }else{
+ callData = this.getCallData(data);
+ }
+
+ if(this.enableUrlEncode){
+ var params = {};
+ params[Ext.isString(this.enableUrlEncode) ? this.enableUrlEncode : 'data'] = Ext.encode(callData);
+ o.params = params;
+ }else{
+ o.jsonData = callData;
+ }
+ Ext.Ajax.request(o);
+ },
+
+ combineAndSend : function(){
+ var len = this.callBuffer.length;
+ if(len > 0){
+ this.doSend(len == 1 ? this.callBuffer[0] : this.callBuffer);
+ this.callBuffer = [];
+ }
+ },
+
+ queueTransaction: function(t){
+ if(t.form){
+ this.processForm(t);
+ return;
+ }
+ this.callBuffer.push(t);
+ if(this.enableBuffer){
+ if(!this.callTask){
+ this.callTask = new Ext.util.DelayedTask(this.combineAndSend, this);
+ }
+ this.callTask.delay(Ext.isNumber(this.enableBuffer) ? this.enableBuffer : 10);
+ }else{
+ this.combineAndSend();
+ }
+ },
+
+ doCall : function(c, m, args){
+ var data = null, hs = args[m.len], scope = args[m.len+1];
+
+ if(m.len !== 0){
+ data = args.slice(0, m.len);
+ }
+
+ var t = new Ext.Direct.Transaction({
+ provider: this,
+ args: args,
+ action: c,
+ method: m.name,
+ data: data,
+ cb: scope && Ext.isFunction(hs) ? hs.createDelegate(scope) : hs
+ });
+
+ if(this.fireEvent('beforecall', this, t, m) !== false){
+ Ext.Direct.addTransaction(t);
+ this.queueTransaction(t);
+ this.fireEvent('call', this, t, m);
+ }
+ },
+
+ doForm : function(c, m, form, callback, scope){
+ var t = new Ext.Direct.Transaction({
+ provider: this,
+ action: c,
+ method: m.name,
+ args:[form, callback, scope],
+ cb: scope && Ext.isFunction(callback) ? callback.createDelegate(scope) : callback,
+ isForm: true
+ });
+
+ if(this.fireEvent('beforecall', this, t, m) !== false){
+ Ext.Direct.addTransaction(t);
+ var isUpload = String(form.getAttribute("enctype")).toLowerCase() == 'multipart/form-data',
+ params = {
+ extTID: t.tid,
+ extAction: c,
+ extMethod: m.name,
+ extType: 'rpc',
+ extUpload: String(isUpload)
+ };
+
+ // change made from typeof callback check to callback.params
+ // to support addl param passing in DirectSubmit EAC 6/2
+ Ext.apply(t, {
+ form: Ext.getDom(form),
+ isUpload: isUpload,
+ params: callback && Ext.isObject(callback.params) ? Ext.apply(params, callback.params) : params
+ });
+ this.fireEvent('call', this, t, m);
+ this.processForm(t);
+ }
+ },
+
+ processForm: function(t){
+ Ext.Ajax.request({
+ url: this.url,
+ params: t.params,
+ callback: this.onData,
+ scope: this,
+ form: t.form,
+ isUpload: t.isUpload,
+ ts: t
+ });
+ },
+
+ createMethod : function(c, m){
+ var f;
+ if(!m.formHandler){
+ f = function(){
+ this.doCall(c, m, Array.prototype.slice.call(arguments, 0));
+ }.createDelegate(this);
+ }else{
+ f = function(form, callback, scope){
+ this.doForm(c, m, form, callback, scope);
+ }.createDelegate(this);
+ }
+ f.directCfg = {
+ action: c,
+ method: m
+ };
+ return f;
+ },
+
+ getTransaction: function(opt){
+ return opt && opt.tid ? Ext.Direct.getTransaction(opt.tid) : null;
+ },
+
+ doCallback: function(t, e){
+ var fn = e.status ? 'success' : 'failure';
+ if(t && t.cb){
+ var hs = t.cb,
+ result = Ext.isDefined(e.result) ? e.result : e.data;
+ if(Ext.isFunction(hs)){
+ hs(result, e);
+ } else{
+ Ext.callback(hs[fn], hs.scope, [result, e]);
+ Ext.callback(hs.callback, hs.scope, [result, e]);
+ }
+ }
+ }
+});