3 * Copyright(c) 2006-2009 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 doRequest : function(action, rs, params, reader, callback, scope, options) {
\r
51 var directFn = this.api[action] || this.directFn;
\r
54 case Ext.data.Api.actions.create:
\r
55 args.push(params.jsonData[reader.meta.root]); // <-- create(Hash)
\r
57 case Ext.data.Api.actions.read:
\r
58 // If the method has no parameters, ignore the paramOrder/paramsAsHash.
\r
59 if(directFn.directCfg.method.len > 0){
\r
60 if(this.paramOrder){
\r
61 for(var i = 0, len = this.paramOrder.length; i < len; i++){
\r
62 args.push(params[this.paramOrder[i]]);
\r
64 }else if(this.paramsAsHash){
\r
69 case Ext.data.Api.actions.update:
\r
70 args.push(params.jsonData[reader.meta.root]); // <-- update(Hash/Hash[])
\r
72 case Ext.data.Api.actions.destroy:
\r
73 args.push(params.jsonData[reader.meta.root]); // <-- destroy(Int/Int[])
\r
78 params : params || {},
\r
80 callback : callback,
\r
87 args.push(this.createCallback(action, rs, trans), this);
\r
88 directFn.apply(window, args);
\r
92 createCallback : function(action, rs, trans) {
\r
93 return function(result, res) {
\r
95 // @deprecated fire loadexception
\r
96 if (action === Ext.data.Api.actions.read) {
\r
97 this.fireEvent("loadexception", this, trans, res, null);
\r
99 this.fireEvent('exception', this, 'remote', action, trans, res, null);
\r
100 trans.request.callback.call(trans.request.scope, null, trans.request.arg, false);
\r
103 if (action === Ext.data.Api.actions.read) {
\r
104 this.onRead(action, trans, result, res);
\r
106 this.onWrite(action, trans, result, res, rs);
\r
111 * Callback for read actions
\r
112 * @param {String} action [Ext.data.Api.actions.create|read|update|destroy]
\r
113 * @param {Object} trans The request transaction object
\r
114 * @param {Object} res The server response
\r
117 onRead : function(action, trans, result, res) {
\r
120 records = trans.reader.readRecords(result);
\r
123 // @deprecated: Fire old loadexception for backwards-compat.
\r
124 this.fireEvent("loadexception", this, trans, res, ex);
\r
126 this.fireEvent('exception', this, 'response', action, trans, res, ex);
\r
127 trans.request.callback.call(trans.request.scope, null, trans.request.arg, false);
\r
130 this.fireEvent("load", this, res, trans.request.arg);
\r
131 trans.request.callback.call(trans.request.scope, records, trans.request.arg, true);
\r
134 * Callback for write actions
\r
135 * @param {String} action [Ext.data.Api.actions.create|read|update|destroy]
\r
136 * @param {Object} trans The request transaction object
\r
137 * @param {Object} res The server response
\r
140 onWrite : function(action, trans, result, res, rs) {
\r
141 var data = trans.reader.extractData(result);
\r
142 this.fireEvent("write", this, action, data, res, rs, trans.request.arg);
\r
143 trans.request.callback.call(trans.request.scope, data, res, true);
\r