3 This file is part of Ext JS 4
5 Copyright (c) 2011 Sencha Inc
7 Contact: http://www.sencha.com/contact
9 GNU General Public License Usage
10 This file may be used under the terms of the GNU General Public License version 3.0 as published by the Free Software Foundation and appearing in the file LICENSE included in the packaging of this file. Please review the following information to ensure the GNU General Public License version 3.0 requirements will be met: http://www.gnu.org/copyleft/gpl.html.
12 If you are unsure which license is appropriate for your use, please contact the sales department at http://www.sencha.com/contact.
16 * This class is used to send requests to the server using {@link Ext.direct.Manager Ext.Direct}. When a
17 * request is made, the transport mechanism is handed off to the appropriate
18 * {@link Ext.direct.RemotingProvider Provider} to complete the call.
20 * # Specifying the function
22 * This proxy expects a Direct remoting method to be passed in order to be able to complete requests.
23 * This can be done by specifying the {@link #directFn} configuration. This will use the same direct
24 * method for all requests. Alternatively, you can provide an {@link #api} configuration. This
25 * allows you to specify a different remoting method for each CRUD action.
29 * This proxy provides options to help configure which parameters will be sent to the server.
30 * By specifying the {@link #paramsAsHash} option, it will send an object literal containing each
31 * of the passed parameters. The {@link #paramOrder} option can be used to specify the order in which
32 * the remoting method parameters are passed.
36 * Ext.define('User', {
37 * extend: 'Ext.data.Model',
38 * fields: ['firstName', 'lastName'],
41 * directFn: MyApp.getUsers,
42 * paramOrder: 'id' // Tells the proxy to pass the id as the first parameter to the remoting method.
47 Ext.define('Ext.data.proxy.Direct', {
48 /* Begin Definitions */
50 extend: 'Ext.data.proxy.Server',
51 alternateClassName: 'Ext.data.DirectProxy',
53 alias: 'proxy.direct',
55 requires: ['Ext.direct.Manager'],
60 * @cfg {String/String[]} paramOrder
61 * Defaults to undefined. A list of params to be executed server side. Specify the params in the order in
62 * which they must be executed on the server-side as either (1) an Array of String values, or (2) a String
63 * of params delimited by either whitespace, comma, or pipe. For example, any of the following would be
66 * paramOrder: ['param1','param2','param3']
67 * paramOrder: 'param1 param2 param3'
68 * paramOrder: 'param1,param2,param3'
69 * paramOrder: 'param1|param2|param'
71 paramOrder: undefined,
74 * @cfg {Boolean} paramsAsHash
75 * Send parameters as a collection of named arguments.
76 * Providing a {@link #paramOrder} nullifies this configuration.
81 * @cfg {Function} directFn
82 * Function to call when executing a request. directFn is a simple alternative to defining the api configuration-parameter
83 * for Store's which will not implement a full CRUD api.
89 * The same as {@link Ext.data.proxy.Server#api}, however instead of providing urls, you should provide a direct
94 * @cfg {Object} extraParams
95 * Extra parameters that will be included on every read request. Individual requests with params
96 * of the same name will override these params when they are in conflict.
100 paramOrderRe: /[\s,|]/,
102 constructor: function(config){
105 Ext.apply(me, config);
106 if (Ext.isString(me.paramOrder)) {
107 me.paramOrder = me.paramOrder.split(me.paramOrderRe);
109 me.callParent(arguments);
112 doRequest: function(operation, callback, scope) {
114 writer = me.getWriter(),
115 request = me.buildRequest(operation, callback, scope),
116 fn = me.api[request.action] || me.directFn,
118 params = request.params,
119 paramOrder = me.paramOrder,
126 Ext.Error.raise('No direct function specified for this proxy');
130 if (operation.allowWrite()) {
131 request = writer.write(request);
134 if (operation.action == 'read') {
135 // We need to pass params
136 method = fn.directCfg.method;
138 if (method.ordered) {
139 if (method.len > 0) {
141 for (len = paramOrder.length; i < len; ++i) {
142 args.push(params[paramOrder[i]]);
144 } else if (me.paramsAsHash) {
152 args.push(request.jsonData);
159 args.push(me.createRequestCallback(request, operation, callback, scope), me);
160 fn.apply(window, args);
164 * Inherit docs. We don't apply any encoding here because
165 * all of the direct requests go out as jsonData
167 applyEncoding: function(value){
171 createRequestCallback: function(request, operation, callback, scope){
174 return function(data, event){
175 me.processResponse(event.status, operation, request, event, callback, scope);
180 extractResponseData: function(response){
181 return Ext.isDefined(response.result) ? response.result : response.data;
185 setException: function(operation, response) {
186 operation.setException(response.message);
190 buildUrl: function(){