3 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
4 <title>The source code</title>
5 <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
6 <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
8 <body onload="prettyPrint();">
9 <pre class="prettyprint lang-js">/*!
10 * Ext JS Library 3.3.1
11 * Copyright(c) 2006-2010 Sencha Inc.
12 * licensing@sencha.com
13 * http://www.sencha.com/license
15 <div id="cls-Ext.data.DirectProxy"></div>/**
16 * @class Ext.data.DirectProxy
17 * @extends Ext.data.DataProxy
19 Ext.data.DirectProxy = function(config){
20 Ext.apply(this, config);
21 if(typeof this.paramOrder == 'string'){
22 this.paramOrder = this.paramOrder.split(/[\s,|]/);
24 Ext.data.DirectProxy.superclass.constructor.call(this, config);
27 Ext.extend(Ext.data.DirectProxy, Ext.data.DataProxy, {
28 <div id="cfg-Ext.data.DirectProxy-paramOrder"></div>/**
29 * @cfg {Array/String} paramOrder Defaults to <tt>undefined</tt>. A list of params to be executed
30 * server side. Specify the params in the order in which they must be executed on the server-side
31 * as either (1) an Array of String values, or (2) a String of params delimited by either whitespace,
32 * comma, or pipe. For example,
33 * any of the following would be acceptable:<pre><code>
34 paramOrder: ['param1','param2','param3']
35 paramOrder: 'param1 param2 param3'
36 paramOrder: 'param1,param2,param3'
37 paramOrder: 'param1|param2|param'
40 paramOrder: undefined,
42 <div id="cfg-Ext.data.DirectProxy-paramsAsHash"></div>/**
43 * @cfg {Boolean} paramsAsHash
44 * Send parameters as a collection of named arguments (defaults to <tt>true</tt>). Providing a
45 * <tt>{@link #paramOrder}</tt> nullifies this configuration.
49 <div id="cfg-Ext.data.DirectProxy-directFn"></div>/**
50 * @cfg {Function} directFn
51 * Function to call when executing a request. directFn is a simple alternative to defining the api configuration-parameter
52 * for Store's which will not implement a full CRUD api.
56 <div id="method-Ext.data.DirectProxy-doRequest"></div>/**
57 * DirectProxy implementation of {@link Ext.data.DataProxy#doRequest}
58 * @param {String} action The crud action type (create, read, update, destroy)
59 * @param {Ext.data.Record/Ext.data.Record[]} rs If action is load, rs will be null
60 * @param {Object} params An object containing properties which are to be used as HTTP parameters
61 * for the request to the remote server.
62 * @param {Ext.data.DataReader} reader The Reader object which converts the data
63 * object into a block of Ext.data.Records.
64 * @param {Function} callback
65 * <div class="sub-desc"><p>A function to be called after the request.
66 * The <tt>callback</tt> is passed the following arguments:<ul>
67 * <li><tt>r</tt> : Ext.data.Record[] The block of Ext.data.Records.</li>
68 * <li><tt>options</tt>: Options object from the action request</li>
69 * <li><tt>success</tt>: Boolean success indicator</li></ul></p></div>
70 * @param {Object} scope The scope (<code>this</code> reference) in which the callback function is executed. Defaults to the browser window.
71 * @param {Object} arg An optional argument which is passed to the callback as its second parameter.
74 doRequest : function(action, rs, params, reader, callback, scope, options) {
76 directFn = this.api[action] || this.directFn;
79 case Ext.data.Api.actions.create:
80 args.push(params.jsonData); // <-- create(Hash)
82 case Ext.data.Api.actions.read:
83 // If the method has no parameters, ignore the paramOrder/paramsAsHash.
84 if(directFn.directCfg.method.len > 0){
86 for(var i = 0, len = this.paramOrder.length; i < len; i++){
87 args.push(params[this.paramOrder[i]]);
89 }else if(this.paramsAsHash){
94 case Ext.data.Api.actions.update:
95 args.push(params.jsonData); // <-- update(Hash/Hash[])
97 case Ext.data.Api.actions.destroy:
98 args.push(params.jsonData); // <-- destroy(Int/Int[])
103 params : params || {},
112 args.push(this.createCallback(action, rs, trans), this);
113 directFn.apply(window, args);
117 createCallback : function(action, rs, trans) {
119 return function(result, res) {
121 // @deprecated fire loadexception
122 if (action === Ext.data.Api.actions.read) {
123 me.fireEvent("loadexception", me, trans, res, null);
125 me.fireEvent('exception', me, 'remote', action, trans, res, null);
126 trans.request.callback.call(trans.request.scope, null, trans.request.arg, false);
129 if (action === Ext.data.Api.actions.read) {
130 me.onRead(action, trans, result, res);
132 me.onWrite(action, trans, result, res, rs);
137 <div id="method-Ext.data.DirectProxy-onRead"></div>/**
138 * Callback for read actions
139 * @param {String} action [Ext.data.Api.actions.create|read|update|destroy]
140 * @param {Object} trans The request transaction object
141 * @param {Object} result Data object picked out of the server-response.
142 * @param {Object} res The server response
145 onRead : function(action, trans, result, res) {
148 records = trans.reader.readRecords(result);
151 // @deprecated: Fire old loadexception for backwards-compat.
152 this.fireEvent("loadexception", this, trans, res, ex);
154 this.fireEvent('exception', this, 'response', action, trans, res, ex);
155 trans.request.callback.call(trans.request.scope, null, trans.request.arg, false);
158 this.fireEvent("load", this, res, trans.request.arg);
159 trans.request.callback.call(trans.request.scope, records, trans.request.arg, true);
161 <div id="method-Ext.data.DirectProxy-onWrite"></div>/**
162 * Callback for write actions
163 * @param {String} action [{@link Ext.data.Api#actions create|read|update|destroy}]
164 * @param {Object} trans The request transaction object
165 * @param {Object} result Data object picked out of the server-response.
166 * @param {Object} res The server response
167 * @param {Ext.data.Record/[Ext.data.Record]} rs The Store resultset associated with the action.
170 onWrite : function(action, trans, result, res, rs) {
171 var data = trans.reader.extractData(trans.reader.getRoot(result), false);
172 var success = trans.reader.getSuccess(result);
173 success = (success !== false);
175 this.fireEvent("write", this, action, data, res, rs, trans.request.arg);
177 this.fireEvent('exception', this, 'remote', action, trans, result, rs);
179 trans.request.callback.call(trans.request.scope, data, res, success);