Action_wev8.js
12.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
/*
* Ext JS Library 2.0.2
* Copyright(c) 2006-2008, Ext JS, LLC.
* licensing@extjs.com
*
* http://extjs.com/license
*/
/**
* @class Ext.form.Action
* The subclasses of this class provide actions to perform upon {@link Ext.form.BasicForm Form}s.
* <br><br>
* Instances of this class are only created by a {@link Ext.form.BasicForm Form} when
* the Form needs to perform an action such as submit or load. The Configuration options
* listed for this class are set through the Form's action methods: {@link Ext.form.BasicForm#submit submit},
* {@link Ext.form.BasicForm#load load} and {@link Ext.form.BasicForm#doAction doAction}.
* <br><br>
* The instance of Action which performed the action is passed to the success
* and failure callbacks of the Form's action methods ({@link Ext.form.BasicForm#submit submit},
* {@link Ext.form.BasicForm#load load} and {@link Ext.form.BasicForm#doAction doAction}),
* and to the {@link Ext.form.BasicForm#actioncomplete actioncomplete} and
* {@link Ext.form.BasicForm#actionfailed actionfailed} event handlers.
*/
Ext.form.Action = function(form, options){
this.form = form;
this.options = options || {};
};
/**
* Failure type returned when client side validation of the Form fails
* thus aborting a submit action.
* @type {String}
* @static
*/
Ext.form.Action.CLIENT_INVALID = 'client';
/**
* Failure type returned when server side validation of the Form fails
* indicating that field-specific error messages have been returned in the
* response's <tt style="font-weight:bold">errors</tt> property.
* @type {String}
* @static
*/
Ext.form.Action.SERVER_INVALID = 'server';
/**
* Failure type returned when a communication error happens when attempting
* to send a request to the remote server.
* @type {String}
* @static
*/
Ext.form.Action.CONNECT_FAILURE = 'connect';
/**
* Failure type returned when no field values are returned in the response's
* <tt style="font-weight:bold">data</tt> property.
* @type {String}
* @static
*/
Ext.form.Action.LOAD_FAILURE = 'load';
Ext.form.Action.prototype = {
/**
* @cfg {String} url The URL that the Action is to invoke.
*/
/**
* @cfg {String} method The HTTP method to use to access the requested URL. Defaults to the
* {@link Ext.form.BasicForm}'s method, or if that is not specified, the underlying DOM form's method.
*/
/**
* @cfg {Mixed} params Extra parameter values to pass. These are added to the Form's
* {@link Ext.form.BasicForm#baseParams} and passed to the specified URL along with the Form's
* input fields.
*/
/**
* @cfg {Function} success The function to call when a valid success return packet is recieved.
* The function is passed the following parameters:<ul class="mdetail-params">
* <li><b>form</b> : Ext.form.BasicForm<div class="sub-desc">The form that requested the action</div></li>
* <li><b>action</b> : Ext.form.Action<div class="sub-desc">The Action class. The {@link #result}
* property of this object may be examined to perform custom postprocessing.</div></li>
* </ul>
*/
/**
* @cfg {Function} failure The function to call when a failure packet was recieved, or when an
* error ocurred in the Ajax communication.
* The function is passed the following parameters:<ul class="mdetail-params">
* <li><b>form</b> : Ext.form.BasicForm<div class="sub-desc">The form that requested the action</div></li>
* <li><b>action</b> : Ext.form.Action<div class="sub-desc">The Action class. If an Ajax
* error ocurred, the failure type will be in {@link #failureType}. The {@link #result}
* property of this object may be examined to perform custom postprocessing.</div></li>
* </ul>
*/
/**
* @cfg {Object} scope The scope in which to call the callback functions (The <tt>this</tt> reference
* for the callback functions).
*/
/**
* @cfg {String} waitMsg The message to be displayed by a call to {@link Ext.MessageBox#wait}
* during the time the action is being processed.
*/
/**
* @cfg {String} waitTitle The title to be displayed by a call to {@link Ext.MessageBox#wait}
* during the time the action is being processed.
*/
/**
* The type of action this Action instance performs.
* Currently only "submit" and "load" are supported.
* @type {String}
*/
type : 'default',
/**
* The type of failure detected. See {@link #Ext.form.Action.CLIENT_INVALID CLIENT_INVALID}, {@link #Ext.form.Action.SERVER_INVALID SERVER_INVALID},
* {@link #Ext.form.Action.CONNECT_FAILURE CONNECT_FAILURE}, {@link #Ext.form.Action.LOAD_FAILURE LOAD_FAILURE}
* @property failureType
* @type {String}
*//**
* The XMLHttpRequest object used to perform the action.
* @property response
* @type {Object}
*//**
* The decoded response object containing a boolean <tt style="font-weight:bold">success</tt> property and
* other, action-specific properties.
* @property result
* @type {Object}
*/
// interface method
run : function(options){
},
// interface method
success : function(response){
},
// interface method
handleResponse : function(response){
},
// default connection failure
failure : function(response){
this.response = response;
this.failureType = Ext.form.Action.CONNECT_FAILURE;
this.form.afterAction(this, false);
},
// private
processResponse : function(response){
this.response = response;
if(!response.responseText){
return true;
}
this.result = this.handleResponse(response);
return this.result;
},
// utility functions used internally
getUrl : function(appendParams){
var url = this.options.url || this.form.url || this.form.el.dom.action;
if(appendParams){
var p = this.getParams();
if(p){
url += (url.indexOf('?') != -1 ? '&' : '?') + p;
}
}
return url;
},
// private
getMethod : function(){
return (this.options.method || this.form.method || this.form.el.dom.method || 'POST').toUpperCase();
},
// private
getParams : function(){
var bp = this.form.baseParams;
var p = this.options.params;
if(p){
if(typeof p == "object"){
p = Ext.urlEncode(Ext.applyIf(p, bp));
}else if(typeof p == 'string' && bp){
p += '&' + Ext.urlEncode(bp);
}
}else if(bp){
p = Ext.urlEncode(bp);
}
return p;
},
// private
createCallback : function(opts){
var opts = opts || {};
return {
success: this.success,
failure: this.failure,
scope: this,
timeout: (opts.timeout*1000) || (this.form.timeout*1000),
upload: this.form.fileUpload ? this.success : undefined
};
}
};
/**
* @class Ext.form.Action.Submit
* @extends Ext.form.Action
* A class which handles submission of data from {@link Ext.form.BasicForm Form}s
* and processes the returned response.
* <br><br>
* Instances of this class are only created by a {@link Ext.form.BasicForm Form} when
* submitting.
* <br><br>
* A response packet must contain a boolean <tt style="font-weight:bold">success</tt> property, and, optionally
* an <tt style="font-weight:bold">errors</tt> property. The <tt style="font-weight:bold">errors</tt> property contains error
* messages for invalid fields.
* <br><br>
* By default, response packets are assumed to be JSON, so a typical response
* packet may look like this:
* <br><br><pre><code>
{
success: false,
errors: {
clientCode: "Client not found",
portOfLoading: "This field must not be null"
}
}</code></pre>
* <br><br>
* Other data may be placed into the response for processing the the {@link Ext.form.BasicForm}'s callback
* or event handler methods. The object decoded from this JSON is available in the {@link #result} property.
*/
Ext.form.Action.Submit = function(form, options){
Ext.form.Action.Submit.superclass.constructor.call(this, form, options);
};
Ext.extend(Ext.form.Action.Submit, Ext.form.Action, {
/**
* @cfg {boolean} clientValidation Determines whether a Form's fields are validated
* in a final call to {@link Ext.form.BasicForm#isValid isValid} prior to submission.
* Pass <tt>false</tt> in the Form's submit options to prevent this. If not defined, pre-submission field validation
* is performed.
*/
type : 'submit',
// private
run : function(){
var o = this.options;
var method = this.getMethod();
var isPost = method == 'POST';
if(o.clientValidation === false || this.form.isValid()){
Ext.Ajax.request(Ext.apply(this.createCallback(o), {
form:this.form.el.dom,
url:this.getUrl(!isPost),
method: method,
params:isPost ? this.getParams() : null,
isUpload: this.form.fileUpload
}));
}else if (o.clientValidation !== false){ // client validation failed
this.failureType = Ext.form.Action.CLIENT_INVALID;
this.form.afterAction(this, false);
}
},
// private
success : function(response){
var result = this.processResponse(response);
if(result === true || result.success){
this.form.afterAction(this, true);
return;
}
if(result.errors){
this.form.markInvalid(result.errors);
this.failureType = Ext.form.Action.SERVER_INVALID;
}
this.form.afterAction(this, false);
},
// private
handleResponse : function(response){
if(this.form.errorReader){
var rs = this.form.errorReader.read(response);
var errors = [];
if(rs.records){
for(var i = 0, len = rs.records.length; i < len; i++) {
var r = rs.records[i];
errors[i] = r.data;
}
}
if(errors.length < 1){
errors = null;
}
return {
success : rs.success,
errors : errors
};
}
return Ext.decode(response.responseText);
}
});
/**
* @class Ext.form.Action.Load
* @extends Ext.form.Action
* A class which handles loading of data from a server into the Fields of
* an {@link Ext.form.BasicForm}.
* <br><br>
* Instances of this class are only created by a {@link Ext.form.BasicForm Form} when
* submitting.
* <br><br>
* A response packet <b>must</b> contain a boolean <tt style="font-weight:bold">success</tt> property, and
* a <tt style="font-weight:bold">data</tt> property. The <tt style="font-weight:bold">data</tt> property contains the
* values of Fields to load. The individual value object for each Field
* is passed to the Field's {@link Ext.form.Field#setValue setValue} method.
* <br><br>
* By default, response packets are assumed to be JSON, so a typical response
* packet may look like this:
* <br><br><pre><code>
{
success: true,
data: {
clientName: "Fred. Olsen Lines",
portOfLoading: "FXT",
portOfDischarge: "OSL"
}
}</code></pre>
* <br><br>
* Other data may be placed into the response for processing the the {@link Ext.form.BasicForm Form}'s callback
* or event handler methods. The object decoded from this JSON is available in the {@link #result} property.
*/
Ext.form.Action.Load = function(form, options){
Ext.form.Action.Load.superclass.constructor.call(this, form, options);
this.reader = this.form.reader;
};
Ext.extend(Ext.form.Action.Load, Ext.form.Action, {
// private
type : 'load',
// private
run : function(){
Ext.Ajax.request(Ext.apply(
this.createCallback(this.options), {
method:this.getMethod(),
url:this.getUrl(false),
params:this.getParams()
}));
},
// private
success : function(response){
var result = this.processResponse(response);
if(result === true || !result.success || !result.data){
this.failureType = Ext.form.Action.LOAD_FAILURE;
this.form.afterAction(this, false);
return;
}
this.form.clearInvalid();
this.form.setValues(result.data);
this.form.afterAction(this, true);
},
// private
handleResponse : function(response){
if(this.form.reader){
var rs = this.form.reader.read(response);
var data = rs.records && rs.records[0] ? rs.records[0].data : null;
return {
success : rs.success,
data : data
};
}
return Ext.decode(response.responseText);
}
});
Ext.form.Action.ACTION_TYPES = {
'load' : Ext.form.Action.Load,
'submit' : Ext.form.Action.Submit
};