Action2.html
13.2 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
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>The source code</title>
<link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
<script type="text/javascript" src="../resources/prettify/prettify.js"></script>
<style type="text/css">
.highlight { display: block; background-color: #ddd; }
</style>
<script type="text/javascript">
function highlight() {
document.getElementById(location.hash.replace(/#/, "")).className = "highlight";
}
</script>
</head>
<body onload="prettyPrint(); highlight();">
<pre class="prettyprint lang-js"><span id='Ext-form-action-Action'>/**
</span> * The subclasses of this class provide actions to perform upon {@link Ext.form.Basic Form}s.
*
* Instances of this class are only created by a {@link Ext.form.Basic 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.Basic#submit submit}, {@link Ext.form.Basic#load load} and {@link Ext.form.Basic#doAction doAction}
*
* 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.Basic#submit submit}, {@link Ext.form.Basic#load load} and
* {@link Ext.form.Basic#doAction doAction}), and to the {@link Ext.form.Basic#actioncomplete actioncomplete} and
* {@link Ext.form.Basic#actionfailed actionfailed} event handlers.
*/
Ext.define('Ext.form.action.Action', {
alternateClassName: 'Ext.form.Action',
<span id='Ext-form-action-Action-cfg-form'> /**
</span> * @cfg {Ext.form.Basic} form
* The {@link Ext.form.Basic BasicForm} instance that is invoking this Action. Required.
*/
<span id='Ext-form-action-Action-cfg-url'> /**
</span> * @cfg {String} url
* The URL that the Action is to invoke. Will default to the {@link Ext.form.Basic#url url} configured on the
* {@link #form}.
*/
<span id='Ext-form-action-Action-cfg-reset'> /**
</span> * @cfg {Boolean} reset
* When set to **true**, causes the Form to be {@link Ext.form.Basic#reset reset} on Action success. If specified,
* this happens before the {@link #success} callback is called and before the Form's
* {@link Ext.form.Basic#actioncomplete actioncomplete} event fires.
*/
<span id='Ext-form-action-Action-cfg-method'> /**
</span> * @cfg {String} method
* The HTTP method to use to access the requested URL.
* Defaults to the {@link Ext.form.Basic#method BasicForm's method}, or 'POST' if not specified.
*/
<span id='Ext-form-action-Action-cfg-params'> /**
</span> * @cfg {Object/String} params
* Extra parameter values to pass. These are added to the Form's {@link Ext.form.Basic#baseParams} and passed to the
* specified URL along with the Form's input fields.
*
* Parameters are encoded as standard HTTP parameters using {@link Ext#urlEncode Ext.Object.toQueryString}.
*/
<span id='Ext-form-action-Action-cfg-headers'> /**
</span> * @cfg {Object} headers
* Extra headers to be sent in the AJAX request for submit and load actions.
* See {@link Ext.data.proxy.Ajax#headers}.
*/
<span id='Ext-form-action-Action-cfg-timeout'> /**
</span> * @cfg {Number} timeout
* The number of seconds to wait for a server response before failing with the {@link #failureType} as
* {@link Ext.form.action.Action#CONNECT_FAILURE}. If not specified, defaults to the configured
* {@link Ext.form.Basic#timeout timeout} of the {@link #form}.
*/
<span id='Ext-form-action-Action-cfg-success'> /**
</span> * @cfg {Function} success
* The function to call when a valid success return packet is received.
* @cfg {Ext.form.Basic} success.form The form that requested the action
* @cfg {Ext.form.action.Action} success.action The Action class. The {@link #result} property of this object may
* be examined to perform custom postprocessing.
*/
<span id='Ext-form-action-Action-cfg-failure'> /**
</span> * @cfg {Function} failure
* The function to call when a failure packet was received, or when an error ocurred in the Ajax communication.
* @cfg {Ext.form.Basic} failure.form The form that requested the action
* @cfg {Ext.form.action.Action} failure.action 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.
*/
<span id='Ext-form-action-Action-cfg-scope'> /**
</span> * @cfg {Object} scope
* The scope in which to call the configured #success and #failure callback functions
* (the `this` reference for the callback functions).
*/
<span id='Ext-form-action-Action-cfg-waitMsg'> /**
</span> * @cfg {String} waitMsg
* The message to be displayed by a call to {@link Ext.window.MessageBox#wait} during the time the action is being
* processed.
*/
<span id='Ext-form-action-Action-cfg-waitTitle'> /**
</span> * @cfg {String} waitTitle
* The title to be displayed by a call to {@link Ext.window.MessageBox#wait} during the time the action is being
* processed.
*/
<span id='Ext-form-action-Action-cfg-submitEmptyText'> /**
</span> * @cfg {Boolean} submitEmptyText
* If set to true, the emptyText value will be sent with the form when it is submitted.
*/
submitEmptyText : true,
<span id='Ext-form-action-Action-property-type'> /**
</span> * @property {String} type
* The type of action this Action instance performs. Currently only "submit" and "load" are supported.
*/
<span id='Ext-form-action-Action-property-failureType'> /**
</span> * @property {String} failureType
* The type of failure detected will be one of these:
* {@link #CLIENT_INVALID}, {@link #SERVER_INVALID}, {@link #CONNECT_FAILURE}, or {@link #LOAD_FAILURE}.
*
* Usage:
*
* var fp = new Ext.form.Panel({
* ...
* buttons: [{
* text: 'Save',
* formBind: true,
* handler: function(){
* if(fp.getForm().isValid()){
* fp.getForm().submit({
* url: 'form-submit.php',
* waitMsg: 'Submitting your data...',
* success: function(form, action){
* // server responded with success = true
* var result = action.{@link #result};
* },
* failure: function(form, action){
* if (action.{@link #failureType} === Ext.form.action.Action.CONNECT_FAILURE) {
* Ext.Msg.alert('Error',
* 'Status:'+action.{@link #response}.status+': '+
* action.{@link #response}.statusText);
* }
* if (action.failureType === Ext.form.action.Action.SERVER_INVALID){
* // server responded with success = false
* Ext.Msg.alert('Invalid', action.{@link #result}.errormsg);
* }
* }
* });
* }
* }
* },{
* text: 'Reset',
* handler: function(){
* fp.getForm().reset();
* }
* }]
*/
<span id='Ext-form-action-Action-property-response'> /**
</span> * @property {Object} response
* The raw XMLHttpRequest object used to perform the action.
*/
<span id='Ext-form-action-Action-property-result'> /**
</span> * @property {Object} result
* The decoded response object containing a boolean `success` property and other, action-specific properties.
*/
<span id='Ext-form-action-Action-method-constructor'> /**
</span> * Creates new Action.
* @param {Object} [config] Config object.
*/
constructor: function(config) {
if (config) {
Ext.apply(this, config);
}
// Normalize the params option to an Object
var params = config.params;
if (Ext.isString(params)) {
this.params = Ext.Object.fromQueryString(params);
}
},
<span id='Ext-form-action-Action-method-run'> /**
</span> * @method
* Invokes this action using the current configuration.
*/
run: Ext.emptyFn,
<span id='Ext-form-action-Action-method-onSuccess'> /**
</span> * @private
* @method onSuccess
* Callback method that gets invoked when the action completes successfully. Must be implemented by subclasses.
* @param {Object} response
*/
<span id='Ext-form-action-Action-method-handleResponse'> /**
</span> * @private
* @method handleResponse
* Handles the raw response and builds a result object from it. Must be implemented by subclasses.
* @param {Object} response
*/
<span id='Ext-form-action-Action-method-onFailure'> /**
</span> * @private
* Handles a failure response.
* @param {Object} response
*/
onFailure : function(response){
this.response = response;
this.failureType = Ext.form.action.Action.CONNECT_FAILURE;
this.form.afterAction(this, false);
},
<span id='Ext-form-action-Action-method-processResponse'> /**
</span> * @private
* Validates that a response contains either responseText or responseXML and invokes
* {@link #handleResponse} to build the result object.
* @param {Object} response The raw response object.
* @return {Object/Boolean} The result object as built by handleResponse, or `true` if
* the response had empty responseText and responseXML.
*/
processResponse : function(response){
this.response = response;
if (!response.responseText && !response.responseXML) {
return true;
}
return (this.result = this.handleResponse(response));
},
<span id='Ext-form-action-Action-method-getUrl'> /**
</span> * @private
* Build the URL for the AJAX request. Used by the standard AJAX submit and load actions.
* @return {String} The URL.
*/
getUrl: function() {
return this.url || this.form.url;
},
<span id='Ext-form-action-Action-method-getMethod'> /**
</span> * @private
* Determine the HTTP method to be used for the request.
* @return {String} The HTTP method
*/
getMethod: function() {
return (this.method || this.form.method || 'POST').toUpperCase();
},
<span id='Ext-form-action-Action-method-getParams'> /**
</span> * @private
* Get the set of parameters specified in the BasicForm's baseParams and/or the params option.
* Items in params override items of the same name in baseParams.
* @return {Object} the full set of parameters
*/
getParams: function() {
return Ext.apply({}, this.params, this.form.baseParams);
},
<span id='Ext-form-action-Action-method-createCallback'> /**
</span> * @private
* Creates a callback object.
*/
createCallback: function() {
var me = this,
undef,
form = me.form;
return {
success: me.onSuccess,
failure: me.onFailure,
scope: me,
timeout: (this.timeout * 1000) || (form.timeout * 1000),
upload: form.fileUpload ? me.onSuccess : undef
};
},
statics: {
<span id='Ext-form-action-Action-static-property-CLIENT_INVALID'> /**
</span> * @property
* Failure type returned when client side validation of the Form fails thus aborting a submit action. Client
* side validation is performed unless {@link Ext.form.action.Submit#clientValidation} is explicitly set to
* false.
* @static
*/
CLIENT_INVALID: 'client',
<span id='Ext-form-action-Action-static-property-SERVER_INVALID'> /**
</span> * @property
* Failure type returned when server side processing fails and the {@link #result}'s `success` property is set to
* false.
*
* In the case of a form submission, field-specific error messages may be returned in the {@link #result}'s
* errors property.
* @static
*/
SERVER_INVALID: 'server',
<span id='Ext-form-action-Action-static-property-CONNECT_FAILURE'> /**
</span> * @property
* Failure type returned when a communication error happens when attempting to send a request to the remote
* server. The {@link #response} may be examined to provide further information.
* @static
*/
CONNECT_FAILURE: 'connect',
<span id='Ext-form-action-Action-static-property-LOAD_FAILURE'> /**
</span> * @property
* Failure type returned when the response's `success` property is set to false, or no field values are returned
* in the response's data property.
* @static
*/
LOAD_FAILURE: 'load'
}
});
</pre>
</body>
</html>