/*!
- * Ext JS Library 3.0.0
+ * Ext JS Library 3.1.0
* Copyright(c) 2006-2009 Ext JS, LLC
* licensing@extjs.com
* http://www.extjs.com/license
*/\r
directFn : undefined,\r
\r
- // protected\r
+ /**\r
+ * DirectProxy implementation of {@link Ext.data.DataProxy#doRequest}\r
+ * @param {String} action The crud action type (create, read, update, destroy)\r
+ * @param {Ext.data.Record/Ext.data.Record[]} rs If action is load, rs will be null\r
+ * @param {Object} params An object containing properties which are to be used as HTTP parameters\r
+ * for the request to the remote server.\r
+ * @param {Ext.data.DataReader} reader The Reader object which converts the data\r
+ * object into a block of Ext.data.Records.\r
+ * @param {Function} callback\r
+ * <div class="sub-desc"><p>A function to be called after the request.\r
+ * The <tt>callback</tt> is passed the following arguments:<ul>\r
+ * <li><tt>r</tt> : Ext.data.Record[] The block of Ext.data.Records.</li>\r
+ * <li><tt>options</tt>: Options object from the action request</li>\r
+ * <li><tt>success</tt>: Boolean success indicator</li></ul></p></div>\r
+ * @param {Object} scope The scope (<code>this</code> reference) in which the callback function is executed. Defaults to the browser window.\r
+ * @param {Object} arg An optional argument which is passed to the callback as its second parameter.\r
+ * @protected\r
+ */\r
doRequest : function(action, rs, params, reader, callback, scope, options) {\r
- var args = [];\r
- var directFn = this.api[action] || this.directFn;\r
+ var args = [],\r
+ directFn = this.api[action] || this.directFn;\r
\r
switch (action) {\r
case Ext.data.Api.actions.create:\r
- args.push(params[reader.meta.root]); // <-- create(Hash)\r
+ args.push(params.jsonData); // <-- create(Hash)\r
break;\r
case Ext.data.Api.actions.read:\r
- if(this.paramOrder){\r
- for(var i = 0, len = this.paramOrder.length; i < len; i++){\r
- args.push(params[this.paramOrder[i]]);\r
+ // If the method has no parameters, ignore the paramOrder/paramsAsHash.\r
+ if(directFn.directCfg.method.len > 0){\r
+ if(this.paramOrder){\r
+ for(var i = 0, len = this.paramOrder.length; i < len; i++){\r
+ args.push(params[this.paramOrder[i]]);\r
+ }\r
+ }else if(this.paramsAsHash){\r
+ args.push(params);\r
}\r
- }else if(this.paramsAsHash){\r
- args.push(params);\r
}\r
break;\r
case Ext.data.Api.actions.update:\r
- args.push(params[reader.meta.idProperty]); // <-- save(Integer/Integer[], Hash/Hash[])\r
- args.push(params[reader.meta.root]);\r
+ args.push(params.jsonData); // <-- update(Hash/Hash[])\r
break;\r
case Ext.data.Api.actions.destroy:\r
- args.push(params[reader.meta.root]); // <-- destroy(Int/Int[])\r
+ args.push(params.jsonData); // <-- destroy(Int/Int[])\r
break;\r
}\r
\r
var trans = {\r
params : params || {},\r
- callback : callback,\r
- scope : scope,\r
- arg : options,\r
+ request: {\r
+ callback : callback,\r
+ scope : scope,\r
+ arg : options\r
+ },\r
reader: reader\r
};\r
\r
this.fireEvent("loadexception", this, trans, res, null);\r
}\r
this.fireEvent('exception', this, 'remote', action, trans, res, null);\r
- trans.callback.call(trans.scope, null, trans.arg, false);\r
+ trans.request.callback.call(trans.request.scope, null, trans.request.arg, false);\r
return;\r
}\r
if (action === Ext.data.Api.actions.read) {\r
* Callback for read actions\r
* @param {String} action [Ext.data.Api.actions.create|read|update|destroy]\r
* @param {Object} trans The request transaction object\r
+ * @param {Object} result Data object picked out of the server-response.\r
* @param {Object} res The server response\r
- * @private\r
+ * @protected\r
*/\r
onRead : function(action, trans, result, res) {\r
var records;\r
this.fireEvent("loadexception", this, trans, res, ex);\r
\r
this.fireEvent('exception', this, 'response', action, trans, res, ex);\r
- trans.callback.call(trans.scope, null, trans.arg, false);\r
+ trans.request.callback.call(trans.request.scope, null, trans.request.arg, false);\r
return;\r
}\r
- this.fireEvent("load", this, res, trans.arg);\r
- trans.callback.call(trans.scope, records, trans.arg, true);\r
+ this.fireEvent("load", this, res, trans.request.arg);\r
+ trans.request.callback.call(trans.request.scope, records, trans.request.arg, true);\r
},\r
/**\r
* Callback for write actions\r
- * @param {String} action [Ext.data.Api.actions.create|read|update|destroy]\r
+ * @param {String} action [{@link Ext.data.Api#actions create|read|update|destroy}]\r
* @param {Object} trans The request transaction object\r
+ * @param {Object} result Data object picked out of the server-response.\r
* @param {Object} res The server response\r
- * @private\r
+ * @param {Ext.data.Record/[Ext.data.Record]} rs The Store resultset associated with the action.\r
+ * @protected\r
*/\r
onWrite : function(action, trans, result, res, rs) {\r
- this.fireEvent("write", this, action, result, res, rs, trans.arg);\r
- trans.callback.call(trans.scope, result, res, true);\r
+ var data = trans.reader.extractData(result, false);\r
+ this.fireEvent("write", this, action, data, res, rs, trans.request.arg);\r
+ trans.request.callback.call(trans.request.scope, data, res, true);\r
}\r
});\r
\r
\r
/**\r
* @cfg {Number} maxRetries\r
- * Number of times to re-attempt delivery on failure of a call.\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
* @param {Ext.direct.RemotingProvider} provider\r
* @param {Ext.Direct.Transaction} transaction\r
*/ \r
- 'beforecall',\r
+ 'beforecall', \r
/**\r
* @event call\r
* Fires immediately after the request to the server-side is sent. This does\r
*/ \r
'call'\r
);\r
- this.namespace = (typeof this.namespace === 'string') ? Ext.ns(this.namespace) : this.namespace || window;\r
+ this.namespace = (Ext.isString(this.namespace)) ? Ext.ns(this.namespace) : this.namespace || window;\r
this.transactions = {};\r
this.callBuffer = [];\r
},\r
initAPI : function(){\r
var o = this.actions;\r
for(var c in o){\r
- var cls = this.namespace[c] || (this.namespace[c] = {});\r
- var ms = o[c];\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
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
- var t = this.getTransaction(e);\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
url: this.url,\r
callback: this.onData,\r
scope: this,\r
- ts: data\r
- };\r
+ ts: data,\r
+ timeout: this.timeout\r
+ }, callData;\r
\r
- // send only needed data\r
- var callData;\r
if(Ext.isArray(data)){\r
callData = [];\r
for(var i = 0, len = data.length; i < len; i++){\r
\r
if(this.enableUrlEncode){\r
var params = {};\r
- params[typeof this.enableUrlEncode == 'string' ? this.enableUrlEncode : 'data'] = Ext.encode(callData);\r
+ params[Ext.isString(this.enableUrlEncode) ? this.enableUrlEncode : 'data'] = Ext.encode(callData);\r
o.params = params;\r
}else{\r
o.jsonData = callData;\r
if(!this.callTask){\r
this.callTask = new Ext.util.DelayedTask(this.combineAndSend, this);\r
}\r
- this.callTask.delay(typeof this.enableBuffer == 'number' ? this.enableBuffer : 10);\r
+ this.callTask.delay(Ext.isNumber(this.enableBuffer) ? this.enableBuffer : 10);\r
}else{\r
this.combineAndSend();\r
}\r
doCallback: function(t, e){\r
var fn = e.status ? 'success' : 'failure';\r
if(t && t.cb){\r
- var hs = t.cb;\r
- var result = e.result || e.data;\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