]>
git.proxmox.com Git - extjs.git/blob - extjs/packages/core/src/direct/RemotingMethod.js
3 * Small utility class used internally to represent a Direct method.
5 Ext
.define('Ext.direct.RemotingMethod', {
7 constructor: function(config
) {
9 params
= config
.params
,
11 metadataCfg
= config
.metadata
,
15 me
.name
= config
.name
;
16 me
.disableBatching
= config
.batched
!= null ? !config
.batched
: false;
18 if (config
.formHandler
) {
19 me
.formHandler
= config
.formHandler
;
21 else if (Ext
.isNumeric(len
)) {
22 // given only the number of parameters
28 * Given an array of either
30 * b) Objects with a name property. We may want to encode extra info in here later
31 * c) Empty array signifies no mandatory parameters
34 me
.strict
= config
.strict
!== undefined ? config
.strict
: true;
37 // params may not be defined for a formHandler, or named method
38 // with no strict checking
39 pLen
= params
&& params
.length
;
41 for (p
= 0; p
< pLen
; p
++) {
43 name
= Ext
.isObject(param
) ? param
.name
: param
;
44 me
.params
[name
] = true;
49 params
= metadataCfg
.params
;
50 len
= metadataCfg
.len
;
52 if (Ext
.isNumeric(len
)) {
55 Ext
.raise('metadata.len cannot be 0 ' +
56 'for Ext Direct method ' + me
.name
);
60 metadata
.ordered
= true;
63 else if (Ext
.isArray(params
)) {
64 metadata
.named
= true;
67 for (p
= 0, pLen
= params
.length
; p
< pLen
; p
++) {
69 metadata
.params
[param
] = true;
72 metadata
.strict
= metadataCfg
.strict
!== undefined ? metadataCfg
.strict
: true;
76 Ext
.raise('metadata is neither named nor ordered ' +
77 'for Ext Direct method ' + me
.name
);
81 me
.metadata
= metadata
;
86 * Prepare Direct function arguments that can be used with getCallData().
88 getArgs: function(config
) {
90 params
= config
.params
,
91 paramOrder
= config
.paramOrder
,
92 paramsAsHash
= config
.paramsAsHash
,
93 metadata
= config
.metadata
,
94 options
= config
.options
,
100 // If a paramOrder was specified, add the params into the argument list in that order.
102 for (i
= 0, len
= paramOrder
.length
; i
< len
; i
++) {
103 args
.push(params
[paramOrder
[i
]]);
106 else if (paramsAsHash
) {
107 // If paramsAsHash was specified, add all the params as a single object argument.
116 args
.push(config
.callback
, config
.scope
|| window
);
118 if (options
|| metadata
) {
119 options
= Ext
.apply({}, options
);
122 // Could be either an object of named arguments,
123 // or an array of ordered arguments
124 options
.metadata
= metadata
;
134 * Takes the arguments for a Direct function and splits the arguments
135 * from the scope and the callback.
137 * @param {Array} args The arguments passed to the direct call
139 * @return {Object} An object with 4 properties: args, callback, scope, and options object.
141 getCallData: function(args
) {
147 form
, callback
, scope
, name
, options
, metadata
;
149 // Historically, the presence of required arguments was not checked;
150 // another idiosyncrasy is that null is sent to the server side
151 // instead of empty array when len === 0
153 callback
= args
[len
];
154 scope
= args
[len
+ 1];
155 options
= args
[len
+ 2];
158 data
= args
.slice(0, len
);
161 else if (me
.formHandler
) {
168 data
= Ext
.apply({}, args
[0]);
173 // filter out any non-existent properties unless !strict
176 if (data
.hasOwnProperty(name
) && !params
[name
]) {
183 if (me
.metadata
&& options
&& options
.metadata
) {
184 if (me
.metadata
.ordered
) {
186 if (!Ext
.isArray(options
.metadata
)) {
187 Ext
.raise('options.metadata is not an Array ' +
188 'for Ext Direct method ' + me
.name
);
190 else if (options
.metadata
.length
< me
.metadata
.len
) {
191 Ext
.raise('Not enough parameters in options.metadata ' +
192 'for Ext Direct method ' + me
.name
);
196 metadata
= options
.metadata
.slice(0, me
.metadata
.len
);
200 if (!Ext
.isObject(options
.metadata
)) {
201 Ext
.raise('options.metadata is not an Object ' +
202 'for Ext Direct method ' + me
.name
);
206 metadata
= Ext
.apply({}, options
.metadata
);
208 if (me
.metadata
.strict
) {
209 for (name
in metadata
) {
210 if (metadata
.hasOwnProperty(name
) && !me
.metadata
.params
[name
]) {
211 delete metadata
[name
];
217 for (name
in me
.metadata
.params
) {
218 if (!metadata
.hasOwnProperty(name
)) {
219 Ext
.raise('Named parameter ' + name
+ ' is missing ' +
220 'in options.metadata for Ext Direct method ' +
227 delete options
.metadata
;