Action2.html 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  5. <title>The source code</title>
  6. <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
  7. <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
  8. <style type="text/css">
  9. .highlight { display: block; background-color: #ddd; }
  10. </style>
  11. <script type="text/javascript">
  12. function highlight() {
  13. document.getElementById(location.hash.replace(/#/, "")).className = "highlight";
  14. }
  15. </script>
  16. </head>
  17. <body onload="prettyPrint(); highlight();">
  18. <pre class="prettyprint lang-js"><span id='Ext-form-action-Action'>/**
  19. </span> * The subclasses of this class provide actions to perform upon {@link Ext.form.Basic Form}s.
  20. *
  21. * Instances of this class are only created by a {@link Ext.form.Basic Form} when the Form needs to perform an action
  22. * such as submit or load. The Configuration options listed for this class are set through the Form's action methods:
  23. * {@link Ext.form.Basic#submit submit}, {@link Ext.form.Basic#load load} and {@link Ext.form.Basic#doAction doAction}
  24. *
  25. * The instance of Action which performed the action is passed to the success and failure callbacks of the Form's action
  26. * methods ({@link Ext.form.Basic#submit submit}, {@link Ext.form.Basic#load load} and
  27. * {@link Ext.form.Basic#doAction doAction}), and to the {@link Ext.form.Basic#actioncomplete actioncomplete} and
  28. * {@link Ext.form.Basic#actionfailed actionfailed} event handlers.
  29. */
  30. Ext.define('Ext.form.action.Action', {
  31. alternateClassName: 'Ext.form.Action',
  32. <span id='Ext-form-action-Action-cfg-form'> /**
  33. </span> * @cfg {Ext.form.Basic} form
  34. * The {@link Ext.form.Basic BasicForm} instance that is invoking this Action. Required.
  35. */
  36. <span id='Ext-form-action-Action-cfg-url'> /**
  37. </span> * @cfg {String} url
  38. * The URL that the Action is to invoke. Will default to the {@link Ext.form.Basic#url url} configured on the
  39. * {@link #form}.
  40. */
  41. <span id='Ext-form-action-Action-cfg-reset'> /**
  42. </span> * @cfg {Boolean} reset
  43. * When set to **true**, causes the Form to be {@link Ext.form.Basic#reset reset} on Action success. If specified,
  44. * this happens before the {@link #success} callback is called and before the Form's
  45. * {@link Ext.form.Basic#actioncomplete actioncomplete} event fires.
  46. */
  47. <span id='Ext-form-action-Action-cfg-method'> /**
  48. </span> * @cfg {String} method
  49. * The HTTP method to use to access the requested URL.
  50. * Defaults to the {@link Ext.form.Basic#method BasicForm's method}, or 'POST' if not specified.
  51. */
  52. <span id='Ext-form-action-Action-cfg-params'> /**
  53. </span> * @cfg {Object/String} params
  54. * Extra parameter values to pass. These are added to the Form's {@link Ext.form.Basic#baseParams} and passed to the
  55. * specified URL along with the Form's input fields.
  56. *
  57. * Parameters are encoded as standard HTTP parameters using {@link Ext#urlEncode Ext.Object.toQueryString}.
  58. */
  59. <span id='Ext-form-action-Action-cfg-headers'> /**
  60. </span> * @cfg {Object} headers
  61. * Extra headers to be sent in the AJAX request for submit and load actions.
  62. * See {@link Ext.data.proxy.Ajax#headers}.
  63. */
  64. <span id='Ext-form-action-Action-cfg-timeout'> /**
  65. </span> * @cfg {Number} timeout
  66. * The number of seconds to wait for a server response before failing with the {@link #failureType} as
  67. * {@link Ext.form.action.Action#CONNECT_FAILURE}. If not specified, defaults to the configured
  68. * {@link Ext.form.Basic#timeout timeout} of the {@link #form}.
  69. */
  70. <span id='Ext-form-action-Action-cfg-success'> /**
  71. </span> * @cfg {Function} success
  72. * The function to call when a valid success return packet is received.
  73. * @cfg {Ext.form.Basic} success.form The form that requested the action
  74. * @cfg {Ext.form.action.Action} success.action The Action class. The {@link #result} property of this object may
  75. * be examined to perform custom postprocessing.
  76. */
  77. <span id='Ext-form-action-Action-cfg-failure'> /**
  78. </span> * @cfg {Function} failure
  79. * The function to call when a failure packet was received, or when an error ocurred in the Ajax communication.
  80. * @cfg {Ext.form.Basic} failure.form The form that requested the action
  81. * @cfg {Ext.form.action.Action} failure.action The Action class. If an Ajax error ocurred, the failure type will
  82. * be in {@link #failureType}. The {@link #result} property of this object may be examined to perform custom
  83. * postprocessing.
  84. */
  85. <span id='Ext-form-action-Action-cfg-scope'> /**
  86. </span> * @cfg {Object} scope
  87. * The scope in which to call the configured #success and #failure callback functions
  88. * (the `this` reference for the callback functions).
  89. */
  90. <span id='Ext-form-action-Action-cfg-waitMsg'> /**
  91. </span> * @cfg {String} waitMsg
  92. * The message to be displayed by a call to {@link Ext.window.MessageBox#wait} during the time the action is being
  93. * processed.
  94. */
  95. <span id='Ext-form-action-Action-cfg-waitTitle'> /**
  96. </span> * @cfg {String} waitTitle
  97. * The title to be displayed by a call to {@link Ext.window.MessageBox#wait} during the time the action is being
  98. * processed.
  99. */
  100. <span id='Ext-form-action-Action-cfg-submitEmptyText'> /**
  101. </span> * @cfg {Boolean} submitEmptyText
  102. * If set to true, the emptyText value will be sent with the form when it is submitted.
  103. */
  104. submitEmptyText : true,
  105. <span id='Ext-form-action-Action-property-type'> /**
  106. </span> * @property {String} type
  107. * The type of action this Action instance performs. Currently only &quot;submit&quot; and &quot;load&quot; are supported.
  108. */
  109. <span id='Ext-form-action-Action-property-failureType'> /**
  110. </span> * @property {String} failureType
  111. * The type of failure detected will be one of these:
  112. * {@link #CLIENT_INVALID}, {@link #SERVER_INVALID}, {@link #CONNECT_FAILURE}, or {@link #LOAD_FAILURE}.
  113. *
  114. * Usage:
  115. *
  116. * var fp = new Ext.form.Panel({
  117. * ...
  118. * buttons: [{
  119. * text: 'Save',
  120. * formBind: true,
  121. * handler: function(){
  122. * if(fp.getForm().isValid()){
  123. * fp.getForm().submit({
  124. * url: 'form-submit.php',
  125. * waitMsg: 'Submitting your data...',
  126. * success: function(form, action){
  127. * // server responded with success = true
  128. * var result = action.{@link #result};
  129. * },
  130. * failure: function(form, action){
  131. * if (action.{@link #failureType} === Ext.form.action.Action.CONNECT_FAILURE) {
  132. * Ext.Msg.alert('Error',
  133. * 'Status:'+action.{@link #response}.status+': '+
  134. * action.{@link #response}.statusText);
  135. * }
  136. * if (action.failureType === Ext.form.action.Action.SERVER_INVALID){
  137. * // server responded with success = false
  138. * Ext.Msg.alert('Invalid', action.{@link #result}.errormsg);
  139. * }
  140. * }
  141. * });
  142. * }
  143. * }
  144. * },{
  145. * text: 'Reset',
  146. * handler: function(){
  147. * fp.getForm().reset();
  148. * }
  149. * }]
  150. */
  151. <span id='Ext-form-action-Action-property-response'> /**
  152. </span> * @property {Object} response
  153. * The raw XMLHttpRequest object used to perform the action.
  154. */
  155. <span id='Ext-form-action-Action-property-result'> /**
  156. </span> * @property {Object} result
  157. * The decoded response object containing a boolean `success` property and other, action-specific properties.
  158. */
  159. <span id='Ext-form-action-Action-method-constructor'> /**
  160. </span> * Creates new Action.
  161. * @param {Object} [config] Config object.
  162. */
  163. constructor: function(config) {
  164. if (config) {
  165. Ext.apply(this, config);
  166. }
  167. // Normalize the params option to an Object
  168. var params = config.params;
  169. if (Ext.isString(params)) {
  170. this.params = Ext.Object.fromQueryString(params);
  171. }
  172. },
  173. <span id='Ext-form-action-Action-method-run'> /**
  174. </span> * @method
  175. * Invokes this action using the current configuration.
  176. */
  177. run: Ext.emptyFn,
  178. <span id='Ext-form-action-Action-method-onSuccess'> /**
  179. </span> * @private
  180. * @method onSuccess
  181. * Callback method that gets invoked when the action completes successfully. Must be implemented by subclasses.
  182. * @param {Object} response
  183. */
  184. <span id='Ext-form-action-Action-method-handleResponse'> /**
  185. </span> * @private
  186. * @method handleResponse
  187. * Handles the raw response and builds a result object from it. Must be implemented by subclasses.
  188. * @param {Object} response
  189. */
  190. <span id='Ext-form-action-Action-method-onFailure'> /**
  191. </span> * @private
  192. * Handles a failure response.
  193. * @param {Object} response
  194. */
  195. onFailure : function(response){
  196. this.response = response;
  197. this.failureType = Ext.form.action.Action.CONNECT_FAILURE;
  198. this.form.afterAction(this, false);
  199. },
  200. <span id='Ext-form-action-Action-method-processResponse'> /**
  201. </span> * @private
  202. * Validates that a response contains either responseText or responseXML and invokes
  203. * {@link #handleResponse} to build the result object.
  204. * @param {Object} response The raw response object.
  205. * @return {Object/Boolean} The result object as built by handleResponse, or `true` if
  206. * the response had empty responseText and responseXML.
  207. */
  208. processResponse : function(response){
  209. this.response = response;
  210. if (!response.responseText &amp;&amp; !response.responseXML) {
  211. return true;
  212. }
  213. return (this.result = this.handleResponse(response));
  214. },
  215. <span id='Ext-form-action-Action-method-getUrl'> /**
  216. </span> * @private
  217. * Build the URL for the AJAX request. Used by the standard AJAX submit and load actions.
  218. * @return {String} The URL.
  219. */
  220. getUrl: function() {
  221. return this.url || this.form.url;
  222. },
  223. <span id='Ext-form-action-Action-method-getMethod'> /**
  224. </span> * @private
  225. * Determine the HTTP method to be used for the request.
  226. * @return {String} The HTTP method
  227. */
  228. getMethod: function() {
  229. return (this.method || this.form.method || 'POST').toUpperCase();
  230. },
  231. <span id='Ext-form-action-Action-method-getParams'> /**
  232. </span> * @private
  233. * Get the set of parameters specified in the BasicForm's baseParams and/or the params option.
  234. * Items in params override items of the same name in baseParams.
  235. * @return {Object} the full set of parameters
  236. */
  237. getParams: function() {
  238. return Ext.apply({}, this.params, this.form.baseParams);
  239. },
  240. <span id='Ext-form-action-Action-method-createCallback'> /**
  241. </span> * @private
  242. * Creates a callback object.
  243. */
  244. createCallback: function() {
  245. var me = this,
  246. undef,
  247. form = me.form;
  248. return {
  249. success: me.onSuccess,
  250. failure: me.onFailure,
  251. scope: me,
  252. timeout: (this.timeout * 1000) || (form.timeout * 1000),
  253. upload: form.fileUpload ? me.onSuccess : undef
  254. };
  255. },
  256. statics: {
  257. <span id='Ext-form-action-Action-static-property-CLIENT_INVALID'> /**
  258. </span> * @property
  259. * Failure type returned when client side validation of the Form fails thus aborting a submit action. Client
  260. * side validation is performed unless {@link Ext.form.action.Submit#clientValidation} is explicitly set to
  261. * false.
  262. * @static
  263. */
  264. CLIENT_INVALID: 'client',
  265. <span id='Ext-form-action-Action-static-property-SERVER_INVALID'> /**
  266. </span> * @property
  267. * Failure type returned when server side processing fails and the {@link #result}'s `success` property is set to
  268. * false.
  269. *
  270. * In the case of a form submission, field-specific error messages may be returned in the {@link #result}'s
  271. * errors property.
  272. * @static
  273. */
  274. SERVER_INVALID: 'server',
  275. <span id='Ext-form-action-Action-static-property-CONNECT_FAILURE'> /**
  276. </span> * @property
  277. * Failure type returned when a communication error happens when attempting to send a request to the remote
  278. * server. The {@link #response} may be examined to provide further information.
  279. * @static
  280. */
  281. CONNECT_FAILURE: 'connect',
  282. <span id='Ext-form-action-Action-static-property-LOAD_FAILURE'> /**
  283. </span> * @property
  284. * Failure type returned when the response's `success` property is set to false, or no field values are returned
  285. * in the response's data property.
  286. * @static
  287. */
  288. LOAD_FAILURE: 'load'
  289. }
  290. });
  291. </pre>
  292. </body>
  293. </html>