4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
5 <title>The source code</title>
6 <link href="../prettify/prettify.css" type="text/css" rel="stylesheet" />
7 <script type="text/javascript" src="../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-form-action-Action-method-constructor'><span id='Ext-form-action-Action'>/**
19 </span></span> * @class Ext.form.action.Action
21 * <p>The subclasses of this class provide actions to perform upon {@link Ext.form.Basic Form}s.</p>
22 * <p>Instances of this class are only created by a {@link Ext.form.Basic Form} when
23 * the Form needs to perform an action such as submit or load. The Configuration options
24 * listed for this class are set through the Form's action methods: {@link Ext.form.Basic#submit submit},
25 * {@link Ext.form.Basic#load load} and {@link Ext.form.Basic#doAction doAction}</p>
26 * <p>The instance of Action which performed the action is passed to the success
27 * and failure callbacks of the Form's action methods ({@link Ext.form.Basic#submit submit},
28 * {@link Ext.form.Basic#load load} and {@link Ext.form.Basic#doAction doAction}),
29 * and to the {@link Ext.form.Basic#actioncomplete actioncomplete} and
30 * {@link Ext.form.Basic#actionfailed actionfailed} event handlers.</p>
32 * @param {Object} config The configuration for this instance.
34 Ext.define('Ext.form.action.Action', {
35 alternateClassName: 'Ext.form.Action',
37 <span id='Ext-form-action-Action-cfg-form'> /**
38 </span> * @cfg {Ext.form.Basic} form The {@link Ext.form.Basic BasicForm} instance that
39 * is invoking this Action. Required.
42 <span id='Ext-form-action-Action-cfg-url'> /**
43 </span> * @cfg {String} url The URL that the Action is to invoke. Will default to the {@link Ext.form.Basic#url url}
44 * configured on the {@link #form}.
47 <span id='Ext-form-action-Action-cfg-reset'> /**
48 </span> * @cfg {Boolean} reset When set to <tt><b>true</b></tt>, causes the Form to be
49 * {@link Ext.form.Basic#reset reset} on Action success. If specified, this happens
50 * before the {@link #success} callback is called and before the Form's
51 * {@link Ext.form.Basic#actioncomplete actioncomplete} event fires.
54 <span id='Ext-form-action-Action-cfg-method'> /**
55 </span> * @cfg {String} method The HTTP method to use to access the requested URL. Defaults to the
56 * {@link Ext.form.Basic#method BasicForm's method}, or 'POST' if not specified.
59 <span id='Ext-form-action-Action-cfg-params'> /**
60 </span> * @cfg {Object/String} params <p>Extra parameter values to pass. These are added to the Form's
61 * {@link Ext.form.Basic#baseParams} and passed to the specified URL along with the Form's
62 * input fields.</p>
63 * <p>Parameters are encoded as standard HTTP parameters using {@link Ext#urlEncode Ext.Object.toQueryString}.</p>
66 <span id='Ext-form-action-Action-cfg-headers'> /**
67 </span> * @cfg {Object} headers <p>Extra headers to be sent in the AJAX request for submit and load actions. See
68 * {@link Ext.data.Connection#headers}.</p>
71 <span id='Ext-form-action-Action-cfg-timeout'> /**
72 </span> * @cfg {Number} timeout The number of seconds to wait for a server response before
73 * failing with the {@link #failureType} as {@link Ext.form.action.Action#CONNECT_FAILURE}. If not specified,
74 * defaults to the configured <tt>{@link Ext.form.Basic#timeout timeout}</tt> of the
78 <span id='Ext-form-action-Action-cfg-success'> /**
79 </span> * @cfg {Function} success The function to call when a valid success return packet is received.
80 * The function is passed the following parameters:<ul class="mdetail-params">
81 * <li><b>form</b> : Ext.form.Basic<div class="sub-desc">The form that requested the action</div></li>
82 * <li><b>action</b> : Ext.form.action.Action<div class="sub-desc">The Action class. The {@link #result}
83 * property of this object may be examined to perform custom postprocessing.</div></li>
87 <span id='Ext-form-action-Action-cfg-failure'> /**
88 </span> * @cfg {Function} failure The function to call when a failure packet was received, or when an
89 * error ocurred in the Ajax communication.
90 * The function is passed the following parameters:<ul class="mdetail-params">
91 * <li><b>form</b> : Ext.form.Basic<div class="sub-desc">The form that requested the action</div></li>
92 * <li><b>action</b> : Ext.form.action.Action<div class="sub-desc">The Action class. If an Ajax
93 * error ocurred, the failure type will be in {@link #failureType}. The {@link #result}
94 * property of this object may be examined to perform custom postprocessing.</div></li>
98 <span id='Ext-form-action-Action-cfg-scope'> /**
99 </span> * @cfg {Object} scope The scope in which to call the configured <tt>success</tt> and <tt>failure</tt>
100 * callback functions (the <tt>this</tt> reference for the callback functions).
103 <span id='Ext-form-action-Action-cfg-waitMsg'> /**
104 </span> * @cfg {String} waitMsg The message to be displayed by a call to {@link Ext.window.MessageBox#wait}
105 * during the time the action is being processed.
108 <span id='Ext-form-action-Action-cfg-waitTitle'> /**
109 </span> * @cfg {String} waitTitle The title to be displayed by a call to {@link Ext.window.MessageBox#wait}
110 * during the time the action is being processed.
113 <span id='Ext-form-action-Action-cfg-submitEmptyText'> /**
114 </span> * @cfg {Boolean} submitEmptyText If set to <tt>true</tt>, the emptyText value will be sent with the form
115 * when it is submitted. Defaults to <tt>true</tt>.
118 <span id='Ext-form-action-Action-property-type'> /**
119 </span> * @property type
120 * The type of action this Action instance performs.
121 * Currently only "submit" and "load" are supported.
125 <span id='Ext-form-action-Action-property-failureType'> /**
126 </span> * The type of failure detected will be one of these: {@link Ext.form.action.Action#CLIENT_INVALID},
127 * {@link Ext.form.action.Action#SERVER_INVALID}, {@link Ext.form.action.Action#CONNECT_FAILURE}, or
128 * {@link Ext.form.action.Action#LOAD_FAILURE}. Usage:
129 * <pre><code>
130 var fp = new Ext.form.Panel({
136 if(fp.getForm().isValid()){
137 fp.getForm().submit({
138 url: 'form-submit.php',
139 waitMsg: 'Submitting your data...',
140 success: function(form, action){
141 // server responded with success = true
142 var result = action.{@link #result};
144 failure: function(form, action){
145 if (action.{@link #failureType} === {@link Ext.form.action.Action#CONNECT_FAILURE}) {
146 Ext.Msg.alert('Error',
147 'Status:'+action.{@link #response}.status+': '+
148 action.{@link #response}.statusText);
150 if (action.failureType === {@link Ext.form.action.Action#SERVER_INVALID}){
151 // server responded with success = false
152 Ext.Msg.alert('Invalid', action.{@link #result}.errormsg);
161 fp.getForm().reset();
164 * </code></pre>
165 * @property failureType
169 <span id='Ext-form-action-Action-property-response'> /**
170 </span> * The raw XMLHttpRequest object used to perform the action.
175 <span id='Ext-form-action-Action-property-result'> /**
176 </span> * The decoded response object containing a boolean <tt>success</tt> property and
177 * other, action-specific properties.
184 constructor: function(config) {
186 Ext.apply(this, config);
189 // Normalize the params option to an Object
190 var params = config.params;
191 if (Ext.isString(params)) {
192 this.params = Ext.Object.fromQueryString(params);
196 <span id='Ext-form-action-Action-property-run'> /**
197 </span> * Invokes this action using the current configuration.
201 <span id='Ext-form-action-Action-method-onSuccess'> /**
204 * Callback method that gets invoked when the action completes successfully. Must be implemented by subclasses.
205 * @param {Object} response
208 <span id='Ext-form-action-Action-method-handleResponse'> /**
210 * @method handleResponse
211 * Handles the raw response and builds a result object from it. Must be implemented by subclasses.
212 * @param {Object} response
215 <span id='Ext-form-action-Action-method-onFailure'> /**
217 * Handles a failure response.
218 * @param {Object} response
220 onFailure : function(response){
221 this.response = response;
222 this.failureType = Ext.form.action.Action.CONNECT_FAILURE;
223 this.form.afterAction(this, false);
226 <span id='Ext-form-action-Action-method-processResponse'> /**
228 * Validates that a response contains either responseText or responseXML and invokes
229 * {@link #handleResponse} to build the result object.
230 * @param {Object} response The raw response object.
231 * @return {Object/Boolean} result The result object as built by handleResponse, or <tt>true</tt> if
232 * the response had empty responseText and responseXML.
234 processResponse : function(response){
235 this.response = response;
236 if (!response.responseText && !response.responseXML) {
239 return (this.result = this.handleResponse(response));
242 <span id='Ext-form-action-Action-method-getUrl'> /**
244 * Build the URL for the AJAX request. Used by the standard AJAX submit and load actions.
245 * @return {String} The URL.
248 return this.url || this.form.url;
251 <span id='Ext-form-action-Action-method-getMethod'> /**
253 * Determine the HTTP method to be used for the request.
254 * @return {String} The HTTP method
256 getMethod: function() {
257 return (this.method || this.form.method || 'POST').toUpperCase();
260 <span id='Ext-form-action-Action-method-getParams'> /**
262 * Get the set of parameters specified in the BasicForm's baseParams and/or the params option.
263 * Items in params override items of the same name in baseParams.
264 * @return {Object} the full set of parameters
266 getParams: function() {
267 return Ext.apply({}, this.params, this.form.baseParams);
270 <span id='Ext-form-action-Action-method-createCallback'> /**
272 * Creates a callback object.
274 createCallback: function() {
279 success: me.onSuccess,
280 failure: me.onFailure,
282 timeout: (this.timeout * 1000) || (form.timeout * 1000),
283 upload: form.fileUpload ? me.onSuccess : undef
288 <span id='Ext-form-action-Action-property-CLIENT_INVALID'> /**
289 </span> * @property CLIENT_INVALID
290 * Failure type returned when client side validation of the Form fails
291 * thus aborting a submit action. Client side validation is performed unless
292 * {@link Ext.form.action.Submit#clientValidation} is explicitly set to <tt>false</tt>.
296 CLIENT_INVALID: 'client',
298 <span id='Ext-form-action-Action-property-SERVER_INVALID'> /**
299 </span> * @property SERVER_INVALID
300 * <p>Failure type returned when server side processing fails and the {@link #result}'s
301 * <tt>success</tt> property is set to <tt>false</tt>.</p>
302 * <p>In the case of a form submission, field-specific error messages may be returned in the
303 * {@link #result}'s <tt>errors</tt> property.</p>
307 SERVER_INVALID: 'server',
309 <span id='Ext-form-action-Action-property-CONNECT_FAILURE'> /**
310 </span> * @property CONNECT_FAILURE
311 * Failure type returned when a communication error happens when attempting
312 * to send a request to the remote server. The {@link #response} may be examined to
313 * provide further information.
317 CONNECT_FAILURE: 'connect',
319 <span id='Ext-form-action-Action-property-LOAD_FAILURE'> /**
320 </span> * @property LOAD_FAILURE
321 * Failure type returned when the response's <tt>success</tt>
322 * property is set to <tt>false</tt>, or no field values are returned in the response's
323 * <tt>data</tt> property.