3 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
\r
4 <title>The source code</title>
\r
5 <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
\r
6 <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
\r
8 <body onload="prettyPrint();">
\r
9 <pre class="prettyprint lang-js"><div id="cls-Ext.data.DirectProxy"></div>/**
\r
10 * @class Ext.data.DirectProxy
\r
11 * @extends Ext.data.DataProxy
\r
13 Ext.data.DirectProxy = function(config){
\r
14 Ext.apply(this, config);
\r
15 if(typeof this.paramOrder == 'string'){
\r
16 this.paramOrder = this.paramOrder.split(/[\s,|]/);
\r
18 Ext.data.DirectProxy.superclass.constructor.call(this, config);
\r
21 Ext.extend(Ext.data.DirectProxy, Ext.data.DataProxy, {
\r
22 <div id="cfg-Ext.data.DirectProxy-paramOrder"></div>/**
\r
23 * @cfg {Array/String} paramOrder Defaults to <tt>undefined</tt>. A list of params to be executed
\r
24 * server side. Specify the params in the order in which they must be executed on the server-side
\r
25 * as either (1) an Array of String values, or (2) a String of params delimited by either whitespace,
\r
26 * comma, or pipe. For example,
\r
27 * any of the following would be acceptable:<pre><code>
\r
28 paramOrder: ['param1','param2','param3']
\r
29 paramOrder: 'param1 param2 param3'
\r
30 paramOrder: 'param1,param2,param3'
\r
31 paramOrder: 'param1|param2|param'
\r
34 paramOrder: undefined,
\r
36 <div id="cfg-Ext.data.DirectProxy-paramsAsHash"></div>/**
\r
37 * @cfg {Boolean} paramsAsHash
\r
38 * Send parameters as a collection of named arguments (defaults to <tt>true</tt>). Providing a
\r
39 * <tt>{@link #paramOrder}</tt> nullifies this configuration.
\r
43 <div id="cfg-Ext.data.DirectProxy-directFn"></div>/**
\r
44 * @cfg {Function} directFn
\r
45 * Function to call when executing a request. directFn is a simple alternative to defining the api configuration-parameter
\r
46 * for Store's which will not implement a full CRUD api.
\r
48 directFn : undefined,
\r
50 <div id="method-Ext.data.DirectProxy-doRequest"></div>/**
\r
51 * DirectProxy implementation of {@link Ext.data.DataProxy#doRequest}
\r
52 * @param {String} action The crud action type (create, read, update, destroy)
\r
53 * @param {Ext.data.Record/Ext.data.Record[]} rs If action is load, rs will be null
\r
54 * @param {Object} params An object containing properties which are to be used as HTTP parameters
\r
55 * for the request to the remote server.
\r
56 * @param {Ext.data.DataReader} reader The Reader object which converts the data
\r
57 * object into a block of Ext.data.Records.
\r
58 * @param {Function} callback
\r
59 * <div class="sub-desc"><p>A function to be called after the request.
\r
60 * The <tt>callback</tt> is passed the following arguments:<ul>
\r
61 * <li><tt>r</tt> : Ext.data.Record[] The block of Ext.data.Records.</li>
\r
62 * <li><tt>options</tt>: Options object from the action request</li>
\r
63 * <li><tt>success</tt>: Boolean success indicator</li></ul></p></div>
\r
64 * @param {Object} scope The scope (<code>this</code> reference) in which the callback function is executed. Defaults to the browser window.
\r
65 * @param {Object} arg An optional argument which is passed to the callback as its second parameter.
\r
68 doRequest : function(action, rs, params, reader, callback, scope, options) {
\r
70 directFn = this.api[action] || this.directFn;
\r
73 case Ext.data.Api.actions.create:
\r
74 args.push(params.jsonData); // <-- create(Hash)
\r
76 case Ext.data.Api.actions.read:
\r
77 // If the method has no parameters, ignore the paramOrder/paramsAsHash.
\r
78 if(directFn.directCfg.method.len > 0){
\r
79 if(this.paramOrder){
\r
80 for(var i = 0, len = this.paramOrder.length; i < len; i++){
\r
81 args.push(params[this.paramOrder[i]]);
\r
83 }else if(this.paramsAsHash){
\r
88 case Ext.data.Api.actions.update:
\r
89 args.push(params.jsonData); // <-- update(Hash/Hash[])
\r
91 case Ext.data.Api.actions.destroy:
\r
92 args.push(params.jsonData); // <-- destroy(Int/Int[])
\r
97 params : params || {},
\r
99 callback : callback,
\r
106 args.push(this.createCallback(action, rs, trans), this);
\r
107 directFn.apply(window, args);
\r
111 createCallback : function(action, rs, trans) {
\r
112 return function(result, res) {
\r
114 // @deprecated fire loadexception
\r
115 if (action === Ext.data.Api.actions.read) {
\r
116 this.fireEvent("loadexception", this, trans, res, null);
\r
118 this.fireEvent('exception', this, 'remote', action, trans, res, null);
\r
119 trans.request.callback.call(trans.request.scope, null, trans.request.arg, false);
\r
122 if (action === Ext.data.Api.actions.read) {
\r
123 this.onRead(action, trans, result, res);
\r
125 this.onWrite(action, trans, result, res, rs);
\r
129 <div id="method-Ext.data.DirectProxy-onRead"></div>/**
\r
130 * Callback for read actions
\r
131 * @param {String} action [Ext.data.Api.actions.create|read|update|destroy]
\r
132 * @param {Object} trans The request transaction object
\r
133 * @param {Object} result Data object picked out of the server-response.
\r
134 * @param {Object} res The server response
\r
137 onRead : function(action, trans, result, res) {
\r
140 records = trans.reader.readRecords(result);
\r
143 // @deprecated: Fire old loadexception for backwards-compat.
\r
144 this.fireEvent("loadexception", this, trans, res, ex);
\r
146 this.fireEvent('exception', this, 'response', action, trans, res, ex);
\r
147 trans.request.callback.call(trans.request.scope, null, trans.request.arg, false);
\r
150 this.fireEvent("load", this, res, trans.request.arg);
\r
151 trans.request.callback.call(trans.request.scope, records, trans.request.arg, true);
\r
153 <div id="method-Ext.data.DirectProxy-onWrite"></div>/**
\r
154 * Callback for write actions
\r
155 * @param {String} action [{@link Ext.data.Api#actions create|read|update|destroy}]
\r
156 * @param {Object} trans The request transaction object
\r
157 * @param {Object} result Data object picked out of the server-response.
\r
158 * @param {Object} res The server response
\r
159 * @param {Ext.data.Record/[Ext.data.Record]} rs The Store resultset associated with the action.
\r
162 onWrite : function(action, trans, result, res, rs) {
\r
163 var data = trans.reader.extractData(result, false);
\r
164 this.fireEvent("write", this, action, data, res, rs, trans.request.arg);
\r
165 trans.request.callback.call(trans.request.scope, data, res, true);
\r