1 <!DOCTYPE html><html><head><title>Sencha Documentation Project</title><link rel="stylesheet" href="../reset.css" type="text/css"><link rel="stylesheet" href="../prettify.css" type="text/css"><link rel="stylesheet" href="../prettify_sa.css" type="text/css"><script type="text/javascript" src="../prettify.js"></script></head><body onload="prettyPrint()"><pre class="prettyprint"><pre><span id='Ext-direct.Manager'>/**
2 </span> * @class Ext.direct.Manager
3 * <p><b><u>Overview</u></b></p>
5 * <p>Ext.Direct aims to streamline communication between the client and server
6 * by providing a single interface that reduces the amount of common code
7 * typically required to validate data and handle returned data packets
8 * (reading data, error conditions, etc).</p>
10 * <p>The Ext.direct namespace includes several classes for a closer integration
11 * with the server-side. The Ext.data namespace also includes classes for working
12 * with Ext.data.Stores which are backed by data from an Ext.Direct method.</p>
14 * <p><b><u>Specification</u></b></p>
16 * <p>For additional information consult the
17 * <a href="http://sencha.com/products/extjs/extdirect">Ext.Direct Specification</a>.</p>
19 * <p><b><u>Providers</u></b></p>
21 * <p>Ext.Direct uses a provider architecture, where one or more providers are
22 * used to transport data to and from the server. There are several providers
23 * that exist in the core at the moment:</p><div class="mdetail-params"><ul>
25 * <li>{@link Ext.direct.JsonProvider JsonProvider} for simple JSON operations</li>
26 * <li>{@link Ext.direct.PollingProvider PollingProvider} for repeated requests</li>
27 * <li>{@link Ext.direct.RemotingProvider RemotingProvider} exposes server side
28 * on the client.</li>
29 * </ul></div>
31 * <p>A provider does not need to be invoked directly, providers are added via
32 * {@link Ext.direct.Manager}.{@link Ext.direct.Manager#add add}.</p>
34 * <p><b><u>Router</u></b></p>
36 * <p>Ext.Direct utilizes a "router" on the server to direct requests from the client
37 * to the appropriate server-side method. Because the Ext.Direct API is completely
38 * platform-agnostic, you could completely swap out a Java based server solution
39 * and replace it with one that uses C# without changing the client side JavaScript
42 * <p><b><u>Server side events</u></b></p>
44 * <p>Custom events from the server may be handled by the client by adding
45 * listeners, for example:</p>
46 * <pre><code>
47 {"type":"event","name":"message","data":"Successfully polled at: 11:19:30 am"}
49 // add a handler for a 'message' event sent by the server
50 Ext.direct.Manager.on('message', function(e){
51 out.append(String.format('&lt;p>&lt;i>{0}&lt;/i>&lt;/p>', e.data));
52 out.el.scrollTo('t', 100000, true);
54 * </code></pre>
58 Ext.define('Ext.direct.Manager', {
60 /* Begin Definitions */
64 observable: 'Ext.util.Observable'
67 requires: ['Ext.util.MixedCollection'],
80 constructor: function(){
84 <span id='Ext-direct.Manager-event-event'> /**
85 </span> * @event event
86 * Fires after an event.
87 * @param {event} e The Ext.direct.Event type that occurred.
88 * @param {Ext.direct.Provider} provider The {@link Ext.direct.Provider Provider}.
91 <span id='Ext-direct.Manager-event-exception'> /**
92 </span> * @event exception
93 * Fires after an event exception.
94 * @param {event} e The Ext.direct.Event type that occurred.
98 me.transactions = Ext.create('Ext.util.MixedCollection');
99 me.providers = Ext.create('Ext.util.MixedCollection');
101 me.mixins.observable.constructor.call(me);
104 <span id='Ext-direct.Manager-method-addProvider'> /**
105 </span> * Adds an Ext.Direct Provider and creates the proxy or stub methods to execute server-side methods.
106 * If the provider is not already connected, it will auto-connect.
107 * <pre><code>
108 var pollProv = new Ext.direct.PollingProvider({
112 Ext.direct.Manager.addProvider({
113 "type":"remoting", // create a {@link Ext.direct.RemotingProvider}
114 "url":"php\/router.php", // url to connect to the Ext.Direct server-side router.
115 "actions":{ // each property within the actions object represents a Class
116 "TestAction":[ // array of methods within each server side Class
118 "name":"doEcho", // name of method
121 "name":"multiply",
124 "name":"doForm",
125 "formHandler":true, // handle form on server with Ext.Direct.Transaction
129 "namespace":"myApplication",// namespace to create the Remoting Provider in
131 type: 'polling', // create a {@link Ext.direct.PollingProvider}
133 }, pollProv); // reference to previously created instance
134 * </code></pre>
135 * @param {Object/Array} provider Accepts either an Array of Provider descriptions (an instance
136 * or config object for a Provider) or any number of Provider descriptions as arguments. Each
137 * Provider description instructs Ext.Direct how to create client-side stub methods.
139 addProvider : function(provider){
145 if (args.length > 1) {
146 for (len = args.length; i < len; ++i) {
147 me.addProvider(args[i]);
152 // if provider has not already been instantiated
153 if (!provider.isProvider) {
154 provider = Ext.create('direct.' + provider.type + 'provider', provider);
156 me.providers.add(provider);
157 provider.on('data', me.onProviderData, me);
160 if (!provider.isConnected()) {
167 <span id='Ext-direct.Manager-method-getProvider'> /**
168 </span> * Retrieve a {@link Ext.direct.Provider provider} by the
169 * <b><tt>{@link Ext.direct.Provider#id id}</tt></b> specified when the provider is
170 * {@link #addProvider added}.
171 * @param {String/Ext.data.Provider} id The id of the provider, or the provider instance.
173 getProvider : function(id){
174 return id.isProvider ? id : this.providers.get(id);
177 <span id='Ext-direct.Manager-method-removeProvider'> /**
178 </span> * Removes the provider.
179 * @param {String/Ext.direct.Provider} provider The provider instance or the id of the provider.
180 * @return {Ext.direct.Provider} The provider, null if not found.
182 removeProvider : function(provider){
184 providers = me.providers,
185 provider = provider.isProvider ? provider : providers.get(provider);
188 provider.un('data', me.onProviderData, me);
189 providers.remove(provider);
195 <span id='Ext-direct.Manager-method-addTransaction'> /**
196 </span> * Add a transaction to the manager.
198 * @param {Ext.direct.Transaction} transaction The transaction to add
199 * @return {Ext.direct.Transaction} transaction
201 addTransaction: function(transaction){
202 this.transactions.add(transaction);
206 <span id='Ext-direct.Manager-method-removeTransaction'> /**
207 </span> * Remove a transaction from the manager.
209 * @param {String/Ext.direct.Transaction} transaction The transaction/id of transaction to remove
210 * @return {Ext.direct.Transaction} transaction
212 removeTransaction: function(transaction){
213 transaction = this.getTransaction(transaction);
214 this.transactions.remove(transaction);
218 <span id='Ext-direct.Manager-method-getTransaction'> /**
219 </span> * Gets a transaction
221 * @param {String/Ext.direct.Transaction} transaction The transaction/id of transaction to get
222 * @return {Ext.direct.Transaction}
224 getTransaction: function(transaction){
225 return transaction.isTransaction ? transaction : this.transactions.get(transaction);
228 onProviderData : function(provider, event){
233 if (Ext.isArray(event)) {
234 for (len = event.length; i < len; ++i) {
235 me.onProviderData(provider, event[i]);
239 if (event.name && event.name != 'event' && event.name != 'exception') {
240 me.fireEvent(event.name, event);
241 } else if (event.type == 'exception') {
242 me.fireEvent('exception', event);
244 me.fireEvent('event', event, provider);
247 // Backwards compatibility
248 Ext.Direct = Ext.direct.Manager;
250 </pre></pre></body></html>