Upgrade to ExtJS 3.0.0 - Released 07/06/2009
[extjs.git] / docs / source / DirectProxy.html
1 <html>\r
2 <head>\r
3   <title>The source code</title>\r
4     <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />\r
5     <script type="text/javascript" src="../resources/prettify/prettify.js"></script>\r
6 </head>\r
7 <body  onload="prettyPrint();">\r
8     <pre class="prettyprint lang-js"><div id="cls-Ext.data.DirectProxy"></div>/**\r
9  * @class Ext.data.DirectProxy\r
10  * @extends Ext.data.DataProxy\r
11  */\r
12 Ext.data.DirectProxy = function(config){\r
13     Ext.apply(this, config);\r
14     if(typeof this.paramOrder == 'string'){\r
15         this.paramOrder = this.paramOrder.split(/[\s,|]/);\r
16     }\r
17     Ext.data.DirectProxy.superclass.constructor.call(this, config);\r
18 };\r
19 \r
20 Ext.extend(Ext.data.DirectProxy, Ext.data.DataProxy, {\r
21     <div id="cfg-Ext.data.DirectProxy-paramOrder"></div>/**\r
22      * @cfg {Array/String} paramOrder Defaults to <tt>undefined</tt>. A list of params to be executed\r
23      * server side.  Specify the params in the order in which they must be executed on the server-side\r
24      * as either (1) an Array of String values, or (2) a String of params delimited by either whitespace,\r
25      * comma, or pipe. For example,\r
26      * any of the following would be acceptable:<pre><code>\r
27 paramOrder: ['param1','param2','param3']\r
28 paramOrder: 'param1 param2 param3'\r
29 paramOrder: 'param1,param2,param3'\r
30 paramOrder: 'param1|param2|param'\r
31      </code></pre>\r
32      */\r
33     paramOrder: undefined,\r
34 \r
35     <div id="cfg-Ext.data.DirectProxy-paramsAsHash"></div>/**\r
36      * @cfg {Boolean} paramsAsHash\r
37      * Send parameters as a collection of named arguments (defaults to <tt>true</tt>). Providing a\r
38      * <tt>{@link #paramOrder}</tt> nullifies this configuration.\r
39      */\r
40     paramsAsHash: true,\r
41 \r
42     <div id="cfg-Ext.data.DirectProxy-directFn"></div>/**\r
43      * @cfg {Function} directFn\r
44      * Function to call when executing a request.  directFn is a simple alternative to defining the api configuration-parameter\r
45      * for Store's which will not implement a full CRUD api.\r
46      */\r
47     directFn : undefined,\r
48 \r
49     // protected\r
50     doRequest : function(action, rs, params, reader, callback, scope, options) {\r
51         var args = [];\r
52         var directFn = this.api[action] || this.directFn;\r
53 \r
54         switch (action) {\r
55             case Ext.data.Api.actions.create:\r
56                 args.push(params[reader.meta.root]);            // <-- create(Hash)\r
57                 break;\r
58             case Ext.data.Api.actions.read:\r
59                 if(this.paramOrder){\r
60                     for(var i = 0, len = this.paramOrder.length; i < len; i++){\r
61                         args.push(params[this.paramOrder[i]]);\r
62                     }\r
63                 }else if(this.paramsAsHash){\r
64                     args.push(params);\r
65                 }\r
66                 break;\r
67             case Ext.data.Api.actions.update:\r
68                 args.push(params[reader.meta.idProperty]);  // <-- save(Integer/Integer[], Hash/Hash[])\r
69                 args.push(params[reader.meta.root]);\r
70                 break;\r
71             case Ext.data.Api.actions.destroy:\r
72                 args.push(params[reader.meta.root]);        // <-- destroy(Int/Int[])\r
73                 break;\r
74         }\r
75 \r
76         var trans = {\r
77             params : params || {},\r
78             request: {\r
79                 callback : callback,\r
80                 scope : scope,\r
81                 arg : options\r
82             },\r
83             reader: reader\r
84         };\r
85 \r
86         args.push(this.createCallback(action, rs, trans), this);\r
87         directFn.apply(window, args);\r
88     },\r
89 \r
90     // private\r
91     createCallback : function(action, rs, trans) {\r
92         return function(result, res) {\r
93             if (!res.status) {\r
94                 // @deprecated fire loadexception\r
95                 if (action === Ext.data.Api.actions.read) {\r
96                     this.fireEvent("loadexception", this, trans, res, null);\r
97                 }\r
98                 this.fireEvent('exception', this, 'remote', action, trans, res, null);\r
99                 trans.request.callback.call(trans.request.scope, null, trans.request.arg, false);\r
100                 return;\r
101             }\r
102             if (action === Ext.data.Api.actions.read) {\r
103                 this.onRead(action, trans, result, res);\r
104             } else {\r
105                 this.onWrite(action, trans, result, res, rs);\r
106             }\r
107         };\r
108     },\r
109     /**\r
110      * Callback for read actions\r
111      * @param {String} action [Ext.data.Api.actions.create|read|update|destroy]\r
112      * @param {Object} trans The request transaction object\r
113      * @param {Object} res The server response\r
114      * @private\r
115      */\r
116     onRead : function(action, trans, result, res) {\r
117         var records;\r
118         try {\r
119             records = trans.reader.readRecords(result);\r
120         }\r
121         catch (ex) {\r
122             // @deprecated: Fire old loadexception for backwards-compat.\r
123             this.fireEvent("loadexception", this, trans, res, ex);\r
124 \r
125             this.fireEvent('exception', this, 'response', action, trans, res, ex);\r
126             trans.request.callback.call(trans.request.scope, null, trans.request.arg, false);\r
127             return;\r
128         }\r
129         this.fireEvent("load", this, res, trans.request.arg);\r
130         trans.request.callback.call(trans.request.scope, records, trans.request.arg, true);\r
131     },\r
132     /**\r
133      * Callback for write actions\r
134      * @param {String} action [Ext.data.Api.actions.create|read|update|destroy]\r
135      * @param {Object} trans The request transaction object\r
136      * @param {Object} res The server response\r
137      * @private\r
138      */\r
139     onWrite : function(action, trans, result, res, rs) {\r
140         this.fireEvent("write", this, action, result, res, rs, trans.request.arg);\r
141         trans.request.callback.call(trans.request.scope, result, res, true);\r
142     }\r
143 });\r
144 \r
145 </pre>    \r
146 </body>\r
147 </html>