3 * Copyright(c) 2006-2010 Ext JS, LLC
5 * http://www.extjs.com/license
8 * @class Ext.data.DirectProxy
\r
9 * @extends Ext.data.DataProxy
\r
11 Ext.data.DirectProxy = function(config){
\r
12 Ext.apply(this, config);
\r
13 if(typeof this.paramOrder == 'string'){
\r
14 this.paramOrder = this.paramOrder.split(/[\s,|]/);
\r
16 Ext.data.DirectProxy.superclass.constructor.call(this, config);
\r
19 Ext.extend(Ext.data.DirectProxy, Ext.data.DataProxy, {
\r
21 * @cfg {Array/String} paramOrder Defaults to <tt>undefined</tt>. A list of params to be executed
\r
22 * server side. Specify the params in the order in which they must be executed on the server-side
\r
23 * as either (1) an Array of String values, or (2) a String of params delimited by either whitespace,
\r
24 * comma, or pipe. For example,
\r
25 * any of the following would be acceptable:<pre><code>
\r
26 paramOrder: ['param1','param2','param3']
\r
27 paramOrder: 'param1 param2 param3'
\r
28 paramOrder: 'param1,param2,param3'
\r
29 paramOrder: 'param1|param2|param'
\r
32 paramOrder: undefined,
\r
35 * @cfg {Boolean} paramsAsHash
\r
36 * Send parameters as a collection of named arguments (defaults to <tt>true</tt>). Providing a
\r
37 * <tt>{@link #paramOrder}</tt> nullifies this configuration.
\r
42 * @cfg {Function} directFn
\r
43 * Function to call when executing a request. directFn is a simple alternative to defining the api configuration-parameter
\r
44 * for Store's which will not implement a full CRUD api.
\r
46 directFn : undefined,
\r
49 * DirectProxy implementation of {@link Ext.data.DataProxy#doRequest}
\r
50 * @param {String} action The crud action type (create, read, update, destroy)
\r
51 * @param {Ext.data.Record/Ext.data.Record[]} rs If action is load, rs will be null
\r
52 * @param {Object} params An object containing properties which are to be used as HTTP parameters
\r
53 * for the request to the remote server.
\r
54 * @param {Ext.data.DataReader} reader The Reader object which converts the data
\r
55 * object into a block of Ext.data.Records.
\r
56 * @param {Function} callback
\r
57 * <div class="sub-desc"><p>A function to be called after the request.
\r
58 * The <tt>callback</tt> is passed the following arguments:<ul>
\r
59 * <li><tt>r</tt> : Ext.data.Record[] The block of Ext.data.Records.</li>
\r
60 * <li><tt>options</tt>: Options object from the action request</li>
\r
61 * <li><tt>success</tt>: Boolean success indicator</li></ul></p></div>
\r
62 * @param {Object} scope The scope (<code>this</code> reference) in which the callback function is executed. Defaults to the browser window.
\r
63 * @param {Object} arg An optional argument which is passed to the callback as its second parameter.
\r
66 doRequest : function(action, rs, params, reader, callback, scope, options) {
\r
68 directFn = this.api[action] || this.directFn;
\r
71 case Ext.data.Api.actions.create:
\r
72 args.push(params.jsonData); // <-- create(Hash)
\r
74 case Ext.data.Api.actions.read:
\r
75 // If the method has no parameters, ignore the paramOrder/paramsAsHash.
\r
76 if(directFn.directCfg.method.len > 0){
\r
77 if(this.paramOrder){
\r
78 for(var i = 0, len = this.paramOrder.length; i < len; i++){
\r
79 args.push(params[this.paramOrder[i]]);
\r
81 }else if(this.paramsAsHash){
\r
86 case Ext.data.Api.actions.update:
\r
87 args.push(params.jsonData); // <-- update(Hash/Hash[])
\r
89 case Ext.data.Api.actions.destroy:
\r
90 args.push(params.jsonData); // <-- destroy(Int/Int[])
\r
95 params : params || {},
\r
97 callback : callback,
\r
104 args.push(this.createCallback(action, rs, trans), this);
\r
105 directFn.apply(window, args);
\r
109 createCallback : function(action, rs, trans) {
\r
110 return function(result, res) {
\r
112 // @deprecated fire loadexception
\r
113 if (action === Ext.data.Api.actions.read) {
\r
114 this.fireEvent("loadexception", this, trans, res, null);
\r
116 this.fireEvent('exception', this, 'remote', action, trans, res, null);
\r
117 trans.request.callback.call(trans.request.scope, null, trans.request.arg, false);
\r
120 if (action === Ext.data.Api.actions.read) {
\r
121 this.onRead(action, trans, result, res);
\r
123 this.onWrite(action, trans, result, res, rs);
\r
128 * Callback for read actions
\r
129 * @param {String} action [Ext.data.Api.actions.create|read|update|destroy]
\r
130 * @param {Object} trans The request transaction object
\r
131 * @param {Object} result Data object picked out of the server-response.
\r
132 * @param {Object} res The server response
\r
135 onRead : function(action, trans, result, res) {
\r
138 records = trans.reader.readRecords(result);
\r
141 // @deprecated: Fire old loadexception for backwards-compat.
\r
142 this.fireEvent("loadexception", this, trans, res, ex);
\r
144 this.fireEvent('exception', this, 'response', action, trans, res, ex);
\r
145 trans.request.callback.call(trans.request.scope, null, trans.request.arg, false);
\r
148 this.fireEvent("load", this, res, trans.request.arg);
\r
149 trans.request.callback.call(trans.request.scope, records, trans.request.arg, true);
\r
152 * Callback for write actions
\r
153 * @param {String} action [{@link Ext.data.Api#actions create|read|update|destroy}]
\r
154 * @param {Object} trans The request transaction object
\r
155 * @param {Object} result Data object picked out of the server-response.
\r
156 * @param {Object} res The server response
\r
157 * @param {Ext.data.Record/[Ext.data.Record]} rs The Store resultset associated with the action.
\r
160 onWrite : function(action, trans, result, res, rs) {
\r
161 var data = trans.reader.extractData(result, false);
\r
162 this.fireEvent("write", this, action, data, res, rs, trans.request.arg);
\r
163 trans.request.callback.call(trans.request.scope, data, res, true);
\r