4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
5 <title>The source code</title>
6 <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
7 <script type="text/javascript" src="../resources/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> * This class is used to send requests to the server using {@link Ext.direct.Manager Ext.Direct}. When a
20 * request is made, the transport mechanism is handed off to the appropriate
21 * {@link Ext.direct.RemotingProvider Provider} to complete the call.
23 * # Specifying the function
25 * This proxy expects a Direct remoting method to be passed in order to be able to complete requests.
26 * This can be done by specifying the {@link #directFn} configuration. This will use the same direct
27 * method for all requests. Alternatively, you can provide an {@link #api} configuration. This
28 * allows you to specify a different remoting method for each CRUD action.
32 * This proxy provides options to help configure which parameters will be sent to the server.
33 * By specifying the {@link #paramsAsHash} option, it will send an object literal containing each
34 * of the passed parameters. The {@link #paramOrder} option can be used to specify the order in which
35 * the remoting method parameters are passed.
39 * Ext.define('User', {
40 * extend: 'Ext.data.Model',
41 * fields: ['firstName', 'lastName'],
44 * directFn: MyApp.getUsers,
45 * paramOrder: 'id' // Tells the proxy to pass the id as the first parameter to the remoting method.
50 Ext.define('Ext.data.proxy.Direct', {
51 /* Begin Definitions */
53 extend: 'Ext.data.proxy.Server',
54 alternateClassName: 'Ext.data.DirectProxy',
56 alias: 'proxy.direct',
58 requires: ['Ext.direct.Manager'],
62 <span id='Ext-data-proxy-Direct-cfg-paramOrder'> /**
63 </span> * @cfg {String/String[]} paramOrder
64 * Defaults to undefined. A list of params to be executed server side. Specify the params in the order in
65 * which they must be executed on the server-side as either (1) an Array of String values, or (2) a String
66 * of params delimited by either whitespace, comma, or pipe. For example, any of the following would be
69 * paramOrder: ['param1','param2','param3']
70 * paramOrder: 'param1 param2 param3'
71 * paramOrder: 'param1,param2,param3'
72 * paramOrder: 'param1|param2|param'
74 paramOrder: undefined,
76 <span id='Ext-data-proxy-Direct-cfg-paramsAsHash'> /**
77 </span> * @cfg {Boolean} paramsAsHash
78 * Send parameters as a collection of named arguments.
79 * Providing a {@link #paramOrder} nullifies this configuration.
83 <span id='Ext-data-proxy-Direct-cfg-directFn'> /**
84 </span> * @cfg {Function} directFn
85 * Function to call when executing a request. directFn is a simple alternative to defining the api configuration-parameter
86 * for Store's which will not implement a full CRUD api.
90 <span id='Ext-data-proxy-Direct-cfg-api'> /**
91 </span> * @cfg {Object} api
92 * 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
98 * Extra parameters that will be included on every read request. Individual requests with params
99 * of the same name will override these params when they are in conflict.
103 paramOrderRe: /[\s,|]/,
105 constructor: function(config){
108 Ext.apply(me, config);
109 if (Ext.isString(me.paramOrder)) {
110 me.paramOrder = me.paramOrder.split(me.paramOrderRe);
112 me.callParent(arguments);
115 doRequest: function(operation, callback, scope) {
117 writer = me.getWriter(),
118 request = me.buildRequest(operation, callback, scope),
119 fn = me.api[request.action] || me.directFn,
121 params = request.params,
122 paramOrder = me.paramOrder,
129 Ext.Error.raise('No direct function specified for this proxy');
133 if (operation.allowWrite()) {
134 request = writer.write(request);
137 if (operation.action == 'read') {
138 // We need to pass params
139 method = fn.directCfg.method;
141 if (method.ordered) {
142 if (method.len > 0) {
144 for (len = paramOrder.length; i < len; ++i) {
145 args.push(params[paramOrder[i]]);
147 } else if (me.paramsAsHash) {
155 args.push(request.jsonData);
162 args.push(me.createRequestCallback(request, operation, callback, scope), me);
163 fn.apply(window, args);
167 * Inherit docs. We don't apply any encoding here because
168 * all of the direct requests go out as jsonData
170 applyEncoding: function(value){
174 createRequestCallback: function(request, operation, callback, scope){
177 return function(data, event){
178 me.processResponse(event.status, operation, request, event, callback, scope);
183 extractResponseData: function(response){
184 return Ext.isDefined(response.result) ? response.result : response.data;
188 setException: function(operation, response) {
189 operation.setException(response.message);
193 buildUrl: function(){