4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
5 <title>The source code</title>
6 <link href="../prettify/prettify.css" type="text/css" rel="stylesheet" />
7 <script type="text/javascript" src="../prettify/prettify.js"></script>
8 <style type="text/css">
9 .highlight { display: block; background-color: #ddd; }
11 <script type="text/javascript">
12 function highlight() {
13 document.getElementById(location.hash.replace(/#/, "")).className = "highlight";
17 <body onload="prettyPrint(); highlight();">
18 <pre class="prettyprint lang-js"><span id='Ext-data-proxy-Direct'>/**
19 </span> * @class Ext.data.proxy.Direct
20 * @extends Ext.data.proxy.Server
22 * This class is used to send requests to the server using {@link Ext.direct}. When a request is made,
23 * the transport mechanism is handed off to the appropriate {@link Ext.direct.RemotingProvider Provider}
24 * to complete the call.
26 * ## Specifying the function
27 * This proxy expects a Direct remoting method to be passed in order to be able to complete requests.
28 * This can be done by specifying the {@link #directFn} configuration. This will use the same direct
29 * method for all requests. Alternatively, you can provide an {@link #api} configuration. This
30 * allows you to specify a different remoting method for each CRUD action.
33 * This proxy provides options to help configure which parameters will be sent to the server.
34 * By specifying the {@link #paramsAsHash} option, it will send an object literal containing each
35 * of the passed parameters. The {@link #paramOrder} option can be used to specify the order in which
36 * the remoting method parameters are passed.
40 * Ext.define('User', {
41 * extend: 'Ext.data.Model',
42 * fields: ['firstName', 'lastName'],
45 * directFn: MyApp.getUsers,
46 * paramOrder: 'id' // Tells the proxy to pass the id as the first parameter to the remoting method.
51 Ext.define('Ext.data.proxy.Direct', {
52 /* Begin Definitions */
54 extend: 'Ext.data.proxy.Server',
55 alternateClassName: 'Ext.data.DirectProxy',
57 alias: 'proxy.direct',
59 requires: ['Ext.direct.Manager'],
63 <span id='Ext-data-proxy-Direct-cfg-paramOrder'> /**
64 </span> * @cfg {Array/String} paramOrder Defaults to <tt>undefined</tt>. A list of params to be executed
65 * server side. Specify the params in the order in which they must be executed on the server-side
66 * as either (1) an Array of String values, or (2) a String of params delimited by either whitespace,
67 * comma, or pipe. For example,
68 * any of the following would be acceptable:<pre><code>
69 paramOrder: ['param1','param2','param3']
70 paramOrder: 'param1 param2 param3'
71 paramOrder: 'param1,param2,param3'
72 paramOrder: 'param1|param2|param'
73 </code></pre>
75 paramOrder: undefined,
77 <span id='Ext-data-proxy-Direct-cfg-paramsAsHash'> /**
78 </span> * @cfg {Boolean} paramsAsHash
79 * Send parameters as a collection of named arguments (defaults to <tt>true</tt>). Providing a
80 * <tt>{@link #paramOrder}</tt> nullifies this configuration.
84 <span id='Ext-data-proxy-Direct-cfg-directFn'> /**
85 </span> * @cfg {Function} directFn
86 * Function to call when executing a request. directFn is a simple alternative to defining the api configuration-parameter
87 * for Store's which will not implement a full CRUD api.
91 <span id='Ext-data-proxy-Direct-cfg-api'> /**
92 </span> * @cfg {Object} api The same as {@link Ext.data.proxy.Server#api}, however instead of providing urls, you should provide a direct
96 <span id='Ext-data-proxy-Direct-cfg-extraParams'> /**
97 </span> * @cfg {Object} extraParams Extra parameters that will be included on every read request. Individual requests with params
98 * of the same name will override these params when they are in conflict.
102 paramOrderRe: /[\s,|]/,
104 constructor: function(config){
107 Ext.apply(me, config);
108 if (Ext.isString(me.paramOrder)) {
109 me.paramOrder = me.paramOrder.split(me.paramOrderRe);
111 me.callParent(arguments);
114 doRequest: function(operation, callback, scope) {
116 writer = me.getWriter(),
117 request = me.buildRequest(operation, callback, scope),
118 fn = me.api[request.action] || me.directFn,
120 params = request.params,
121 paramOrder = me.paramOrder,
128 Ext.Error.raise('No direct function specified for this proxy');
132 if (operation.allowWrite()) {
133 request = writer.write(request);
136 if (operation.action == 'read') {
137 // We need to pass params
138 method = fn.directCfg.method;
140 if (method.ordered) {
141 if (method.len > 0) {
143 for (len = paramOrder.length; i < len; ++i) {
144 args.push(params[paramOrder[i]]);
146 } else if (me.paramsAsHash) {
154 args.push(request.jsonData);
161 args.push(me.createRequestCallback(request, operation, callback, scope), me);
162 fn.apply(window, args);
166 * Inherit docs. We don't apply any encoding here because
167 * all of the direct requests go out as jsonData
169 applyEncoding: function(value){
173 createRequestCallback: function(request, operation, callback, scope){
176 return function(data, event){
177 me.processResponse(event.status, operation, request, event, callback, scope);
182 extractResponseData: function(response){
183 return Ext.isDefined(response.result) ? response.result : response.data;
187 setException: function(operation, response) {
188 operation.setException(response.message);
192 buildUrl: function(){