1 <!DOCTYPE html><html><head><title>Sencha Documentation Project</title><link rel="stylesheet" href="../reset.css" type="text/css"><link rel="stylesheet" href="../prettify.css" type="text/css"><link rel="stylesheet" href="../prettify_sa.css" type="text/css"><script type="text/javascript" src="../prettify.js"></script></head><body onload="prettyPrint()"><pre class="prettyprint"><pre><span id='Ext-data.proxy.Direct'>/**
2 </span> * @class Ext.data.proxy.Direct
3 * @extends Ext.data.proxy.Server
5 * This class is used to send requests to the server using {@link Ext.direct}. When a request is made,
6 * the transport mechanism is handed off to the appropriate {@link Ext.direct.RemotingProvider Provider}
7 * to complete the call.
9 * ## Specifying the function
10 * This proxy expects a Direct remoting method to be passed in order to be able to complete requests.
11 * This can be done by specifying the {@link #directFn} configuration. This will use the same direct
12 * method for all requests. Alternatively, you can provide an {@link #api} configuration. This
13 * allows you to specify a different remoting method for each CRUD action.
16 * This proxy provides options to help configure which parameters will be sent to the server.
17 * By specifying the {@link #paramsAsHash} option, it will send an object literal containing each
18 * of the passed parameters. The {@link #paramOrder} option can be used to specify the order in which
19 * the remoting method parameters are passed.
23 * Ext.define('User', {
24 * extend: 'Ext.data.Model',
25 * fields: ['firstName', 'lastName'],
28 * directFn: MyApp.getUsers,
29 * paramOrder: 'id' // Tells the proxy to pass the id as the first parameter to the remoting method.
34 Ext.define('Ext.data.proxy.Direct', {
35 /* Begin Definitions */
37 extend: 'Ext.data.proxy.Server',
38 alternateClassName: 'Ext.data.DirectProxy',
40 alias: 'proxy.direct',
42 requires: ['Ext.direct.Manager'],
46 <span id='Ext-data.proxy.Direct-cfg-paramOrder'> /**
47 </span> * @cfg {Array/String} paramOrder Defaults to <tt>undefined</tt>. A list of params to be executed
48 * server side. Specify the params in the order in which they must be executed on the server-side
49 * as either (1) an Array of String values, or (2) a String of params delimited by either whitespace,
50 * comma, or pipe. For example,
51 * any of the following would be acceptable:<pre><code>
52 paramOrder: ['param1','param2','param3']
53 paramOrder: 'param1 param2 param3'
54 paramOrder: 'param1,param2,param3'
55 paramOrder: 'param1|param2|param'
56 </code></pre>
58 paramOrder: undefined,
60 <span id='Ext-data.proxy.Direct-cfg-paramsAsHash'> /**
61 </span> * @cfg {Boolean} paramsAsHash
62 * Send parameters as a collection of named arguments (defaults to <tt>true</tt>). Providing a
63 * <tt>{@link #paramOrder}</tt> nullifies this configuration.
67 <span id='Ext-data.proxy.Direct-cfg-directFn'> /**
68 </span> * @cfg {Function} directFn
69 * Function to call when executing a request. directFn is a simple alternative to defining the api configuration-parameter
70 * for Store's which will not implement a full CRUD api.
74 <span id='Ext-data.proxy.Direct-cfg-api'> /**
75 </span> * @cfg {Object} api The same as {@link Ext.data.proxy.Server#api}, however instead of providing urls, you should provide a direct
79 <span id='Ext-data.proxy.Direct-cfg-extraParams'> /**
80 </span> * @cfg {Object} extraParams Extra parameters that will be included on every read request. Individual requests with params
81 * of the same name will override these params when they are in conflict.
85 paramOrderRe: /[\s,|]/,
87 constructor: function(config){
90 Ext.apply(me, config);
91 if (Ext.isString(me.paramOrder)) {
92 me.paramOrder = me.paramOrder.split(me.paramOrderRe);
94 me.callParent(arguments);
97 doRequest: function(operation, callback, scope) {
99 writer = me.getWriter(),
100 request = me.buildRequest(operation, callback, scope),
101 fn = me.api[request.action] || me.directFn,
103 params = request.params,
104 paramOrder = me.paramOrder,
111 Ext.Error.raise('No direct function specified for this proxy');
115 if (operation.allowWrite()) {
116 request = writer.write(request);
119 if (operation.action == 'read') {
120 // We need to pass params
121 method = fn.directCfg.method;
123 if (method.ordered) {
124 if (method.len > 0) {
126 for (len = paramOrder.length; i < len; ++i) {
127 args.push(params[paramOrder[i]]);
129 } else if (me.paramsAsHash) {
137 args.push(request.jsonData);
144 args.push(me.createRequestCallback(request, operation, callback, scope), me);
145 fn.apply(window, args);
149 * Inherit docs. We don't apply any encoding here because
150 * all of the direct requests go out as jsonData
152 applyEncoding: function(value){
156 createRequestCallback: function(request, operation, callback, scope){
159 return function(data, event){
160 me.processResponse(event.status, operation, request, event, callback, scope);
165 extractResponseData: function(response){
166 return Ext.isDefined(response.result) ? response.result : response.data;
170 setException: function(operation, response) {
171 operation.setException(response.message);
175 buildUrl: function(){
179 </pre></pre></body></html>