You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

800 lines
32 KiB

2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  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'>/**
  19. </span> * @class Ext.form.Action
  20. * &lt;p&gt;The subclasses of this class provide actions to perform upon {@link Ext.form.BasicForm Form}s.&lt;/p&gt;
  21. * &lt;p&gt;Instances of this class are only created by a {@link Ext.form.BasicForm Form} when
  22. * the Form needs to perform an action such as submit or load. The Configuration options
  23. * listed for this class are set through the Form's action methods: {@link Ext.form.BasicForm#submit submit},
  24. * {@link Ext.form.BasicForm#load load} and {@link Ext.form.BasicForm#doAction doAction}&lt;/p&gt;
  25. * &lt;p&gt;The instance of Action which performed the action is passed to the success
  26. * and failure callbacks of the Form's action methods ({@link Ext.form.BasicForm#submit submit},
  27. * {@link Ext.form.BasicForm#load load} and {@link Ext.form.BasicForm#doAction doAction}),
  28. * and to the {@link Ext.form.BasicForm#actioncomplete actioncomplete} and
  29. * {@link Ext.form.BasicForm#actionfailed actionfailed} event handlers.&lt;/p&gt;
  30. */
  31. Ext.form.Action = function(form, options){
  32. this.form = form;
  33. this.options = options || {};
  34. };
  35. <span id='Ext-form-Action-static-property-CLIENT_INVALID'>/**
  36. </span> * Failure type returned when client side validation of the Form fails
  37. * thus aborting a submit action. Client side validation is performed unless
  38. * {@link #clientValidation} is explicitly set to &lt;tt&gt;false&lt;/tt&gt;.
  39. * @type {String}
  40. * @static
  41. */
  42. Ext.form.Action.CLIENT_INVALID = 'client';
  43. <span id='Ext-form-Action-static-property-SERVER_INVALID'>/**
  44. </span> * &lt;p&gt;Failure type returned when server side processing fails and the {@link #result}'s
  45. * &lt;tt style=&quot;font-weight:bold&quot;&gt;success&lt;/tt&gt; property is set to &lt;tt&gt;false&lt;/tt&gt;.&lt;/p&gt;
  46. * &lt;p&gt;In the case of a form submission, field-specific error messages may be returned in the
  47. * {@link #result}'s &lt;tt style=&quot;font-weight:bold&quot;&gt;errors&lt;/tt&gt; property.&lt;/p&gt;
  48. * @type {String}
  49. * @static
  50. */
  51. Ext.form.Action.SERVER_INVALID = 'server';
  52. <span id='Ext-form-Action-static-property-CONNECT_FAILURE'>/**
  53. </span> * Failure type returned when a communication error happens when attempting
  54. * to send a request to the remote server. The {@link #response} may be examined to
  55. * provide further information.
  56. * @type {String}
  57. * @static
  58. */
  59. Ext.form.Action.CONNECT_FAILURE = 'connect';
  60. <span id='Ext-form-Action-static-property-LOAD_FAILURE'>/**
  61. </span> * Failure type returned when the response's &lt;tt style=&quot;font-weight:bold&quot;&gt;success&lt;/tt&gt;
  62. * property is set to &lt;tt&gt;false&lt;/tt&gt;, or no field values are returned in the response's
  63. * &lt;tt style=&quot;font-weight:bold&quot;&gt;data&lt;/tt&gt; property.
  64. * @type {String}
  65. * @static
  66. */
  67. Ext.form.Action.LOAD_FAILURE = 'load';
  68. Ext.form.Action.prototype = {
  69. <span id='Ext-form-Action-cfg-url'>/**
  70. </span> * @cfg {String} url The URL that the Action is to invoke.
  71. */
  72. <span id='Ext-form-Action-cfg-reset'>/**
  73. </span> * @cfg {Boolean} reset When set to &lt;tt&gt;&lt;b&gt;true&lt;/b&gt;&lt;/tt&gt;, causes the Form to be
  74. * {@link Ext.form.BasicForm.reset reset} on Action success. If specified, this happens
  75. * &lt;b&gt;before&lt;/b&gt; the {@link #success} callback is called and before the Form's
  76. * {@link Ext.form.BasicForm.actioncomplete actioncomplete} event fires.
  77. */
  78. <span id='Ext-form-Action-cfg-method'>/**
  79. </span> * @cfg {String} method The HTTP method to use to access the requested URL. Defaults to the
  80. * {@link Ext.form.BasicForm}'s method, or if that is not specified, the underlying DOM form's method.
  81. */
  82. <span id='Ext-form-Action-cfg-params'>/**
  83. </span> * @cfg {Mixed} params &lt;p&gt;Extra parameter values to pass. These are added to the Form's
  84. * {@link Ext.form.BasicForm#baseParams} and passed to the specified URL along with the Form's
  85. * input fields.&lt;/p&gt;
  86. * &lt;p&gt;Parameters are encoded as standard HTTP parameters using {@link Ext#urlEncode}.&lt;/p&gt;
  87. */
  88. <span id='Ext-form-Action-cfg-timeout'>/**
  89. </span> * @cfg {Number} timeout The number of seconds to wait for a server response before
  90. * failing with the {@link #failureType} as {@link #Action.CONNECT_FAILURE}. If not specified,
  91. * defaults to the configured &lt;tt&gt;{@link Ext.form.BasicForm#timeout timeout}&lt;/tt&gt; of the
  92. * {@link Ext.form.BasicForm form}.
  93. */
  94. <span id='Ext-form-Action-cfg-success'>/**
  95. </span> * @cfg {Function} success The function to call when a valid success return packet is recieved.
  96. * The function is passed the following parameters:&lt;ul class=&quot;mdetail-params&quot;&gt;
  97. * &lt;li&gt;&lt;b&gt;form&lt;/b&gt; : Ext.form.BasicForm&lt;div class=&quot;sub-desc&quot;&gt;The form that requested the action&lt;/div&gt;&lt;/li&gt;
  98. * &lt;li&gt;&lt;b&gt;action&lt;/b&gt; : Ext.form.Action&lt;div class=&quot;sub-desc&quot;&gt;The Action class. The {@link #result}
  99. * property of this object may be examined to perform custom postprocessing.&lt;/div&gt;&lt;/li&gt;
  100. * &lt;/ul&gt;
  101. */
  102. <span id='Ext-form-Action-cfg-failure'>/**
  103. </span> * @cfg {Function} failure The function to call when a failure packet was recieved, or when an
  104. * error ocurred in the Ajax communication.
  105. * The function is passed the following parameters:&lt;ul class=&quot;mdetail-params&quot;&gt;
  106. * &lt;li&gt;&lt;b&gt;form&lt;/b&gt; : Ext.form.BasicForm&lt;div class=&quot;sub-desc&quot;&gt;The form that requested the action&lt;/div&gt;&lt;/li&gt;
  107. * &lt;li&gt;&lt;b&gt;action&lt;/b&gt; : Ext.form.Action&lt;div class=&quot;sub-desc&quot;&gt;The Action class. If an Ajax
  108. * error ocurred, the failure type will be in {@link #failureType}. The {@link #result}
  109. * property of this object may be examined to perform custom postprocessing.&lt;/div&gt;&lt;/li&gt;
  110. * &lt;/ul&gt;
  111. */
  112. <span id='Ext-form-Action-cfg-scope'>/**
  113. </span> * @cfg {Object} scope The scope in which to call the callback functions (The &lt;tt&gt;this&lt;/tt&gt; reference
  114. * for the callback functions).
  115. */
  116. <span id='Ext-form-Action-cfg-waitMsg'>/**
  117. </span> * @cfg {String} waitMsg The message to be displayed by a call to {@link Ext.MessageBox#wait}
  118. * during the time the action is being processed.
  119. */
  120. <span id='Ext-form-Action-cfg-waitTitle'>/**
  121. </span> * @cfg {String} waitTitle The title to be displayed by a call to {@link Ext.MessageBox#wait}
  122. * during the time the action is being processed.
  123. */
  124. <span id='Ext-form-Action-cfg-submitEmptyText'>/**
  125. </span> * @cfg {Boolean} submitEmptyText If set to &lt;tt&gt;true&lt;/tt&gt;, the emptyText value will be sent with the form
  126. * when it is submitted. Defaults to &lt;tt&gt;true&lt;/tt&gt;.
  127. */
  128. <span id='Ext-form-Action-property-type'>/**
  129. </span> * The type of action this Action instance performs.
  130. * Currently only &quot;submit&quot; and &quot;load&quot; are supported.
  131. * @type {String}
  132. */
  133. type : 'default',
  134. <span id='Ext-form-Action-property-failureType'>/**
  135. </span> * The type of failure detected will be one of these: {@link #CLIENT_INVALID},
  136. * {@link #SERVER_INVALID}, {@link #CONNECT_FAILURE}, or {@link #LOAD_FAILURE}. Usage:
  137. * &lt;pre&gt;&lt;code&gt;
  138. var fp = new Ext.form.FormPanel({
  139. ...
  140. buttons: [{
  141. text: 'Save',
  142. formBind: true,
  143. handler: function(){
  144. if(fp.getForm().isValid()){
  145. fp.getForm().submit({
  146. url: 'form-submit.php',
  147. waitMsg: 'Submitting your data...',
  148. success: function(form, action){
  149. // server responded with success = true
  150. var result = action.{@link #result};
  151. },
  152. failure: function(form, action){
  153. if (action.{@link #failureType} === Ext.form.Action.{@link #CONNECT_FAILURE}) {
  154. Ext.Msg.alert('Error',
  155. 'Status:'+action.{@link #response}.status+': '+
  156. action.{@link #response}.statusText);
  157. }
  158. if (action.failureType === Ext.form.Action.{@link #SERVER_INVALID}){
  159. // server responded with success = false
  160. Ext.Msg.alert('Invalid', action.{@link #result}.errormsg);
  161. }
  162. }
  163. });
  164. }
  165. }
  166. },{
  167. text: 'Reset',
  168. handler: function(){
  169. fp.getForm().reset();
  170. }
  171. }]
  172. * &lt;/code&gt;&lt;/pre&gt;
  173. * @property failureType
  174. * @type {String}
  175. */
  176. <span id='Ext-form-Action-property-response'> /**
  177. </span> * The XMLHttpRequest object used to perform the action.
  178. * @property response
  179. * @type {Object}
  180. */
  181. <span id='Ext-form-Action-property-result'> /**
  182. </span> * The decoded response object containing a boolean &lt;tt style=&quot;font-weight:bold&quot;&gt;success&lt;/tt&gt; property and
  183. * other, action-specific properties.
  184. * @property result
  185. * @type {Object}
  186. */
  187. // interface method
  188. run : function(options){
  189. },
  190. // interface method
  191. success : function(response){
  192. },
  193. // interface method
  194. handleResponse : function(response){
  195. },
  196. // default connection failure
  197. failure : function(response){
  198. this.response = response;
  199. this.failureType = Ext.form.Action.CONNECT_FAILURE;
  200. this.form.afterAction(this, false);
  201. },
  202. // private
  203. // shared code among all Actions to validate that there was a response
  204. // with either responseText or responseXml
  205. processResponse : function(response){
  206. this.response = response;
  207. if(!response.responseText &amp;&amp; !response.responseXML){
  208. return true;
  209. }
  210. this.result = this.handleResponse(response);
  211. return this.result;
  212. },
  213. decodeResponse: function(response) {
  214. try {
  215. return Ext.decode(response.responseText);
  216. } catch(e) {
  217. return false;
  218. }
  219. },
  220. // utility functions used internally
  221. getUrl : function(appendParams){
  222. var url = this.options.url || this.form.url || this.form.el.dom.action;
  223. if(appendParams){
  224. var p = this.getParams();
  225. if(p){
  226. url = Ext.urlAppend(url, p);
  227. }
  228. }
  229. return url;
  230. },
  231. // private
  232. getMethod : function(){
  233. return (this.options.method || this.form.method || this.form.el.dom.method || 'POST').toUpperCase();
  234. },
  235. // private
  236. getParams : function(){
  237. var bp = this.form.baseParams;
  238. var p = this.options.params;
  239. if(p){
  240. if(typeof p == &quot;object&quot;){
  241. p = Ext.urlEncode(Ext.applyIf(p, bp));
  242. }else if(typeof p == 'string' &amp;&amp; bp){
  243. p += '&amp;' + Ext.urlEncode(bp);
  244. }
  245. }else if(bp){
  246. p = Ext.urlEncode(bp);
  247. }
  248. return p;
  249. },
  250. // private
  251. createCallback : function(opts){
  252. var opts = opts || {};
  253. return {
  254. success: this.success,
  255. failure: this.failure,
  256. scope: this,
  257. timeout: (opts.timeout*1000) || (this.form.timeout*1000),
  258. upload: this.form.fileUpload ? this.success : undefined
  259. };
  260. }
  261. };
  262. <span id='Ext-form-Action-Submit'>/**
  263. </span> * @class Ext.form.Action.Submit
  264. * @extends Ext.form.Action
  265. * &lt;p&gt;A class which handles submission of data from {@link Ext.form.BasicForm Form}s
  266. * and processes the returned response.&lt;/p&gt;
  267. * &lt;p&gt;Instances of this class are only created by a {@link Ext.form.BasicForm Form} when
  268. * {@link Ext.form.BasicForm#submit submit}ting.&lt;/p&gt;
  269. * &lt;p&gt;&lt;u&gt;&lt;b&gt;Response Packet Criteria&lt;/b&gt;&lt;/u&gt;&lt;/p&gt;
  270. * &lt;p&gt;A response packet may contain:
  271. * &lt;div class=&quot;mdetail-params&quot;&gt;&lt;ul&gt;
  272. * &lt;li&gt;&lt;b&gt;&lt;code&gt;success&lt;/code&gt;&lt;/b&gt; property : Boolean
  273. * &lt;div class=&quot;sub-desc&quot;&gt;The &lt;code&gt;success&lt;/code&gt; property is required.&lt;/div&gt;&lt;/li&gt;
  274. * &lt;li&gt;&lt;b&gt;&lt;code&gt;errors&lt;/code&gt;&lt;/b&gt; property : Object
  275. * &lt;div class=&quot;sub-desc&quot;&gt;&lt;div class=&quot;sub-desc&quot;&gt;The &lt;code&gt;errors&lt;/code&gt; property,
  276. * which is optional, contains error messages for invalid fields.&lt;/div&gt;&lt;/li&gt;
  277. * &lt;/ul&gt;&lt;/div&gt;
  278. * &lt;p&gt;&lt;u&gt;&lt;b&gt;JSON Packets&lt;/b&gt;&lt;/u&gt;&lt;/p&gt;
  279. * &lt;p&gt;By default, response packets are assumed to be JSON, so a typical response
  280. * packet may look like this:&lt;/p&gt;&lt;pre&gt;&lt;code&gt;
  281. {
  282. success: false,
  283. errors: {
  284. clientCode: &quot;Client not found&quot;,
  285. portOfLoading: &quot;This field must not be null&quot;
  286. }
  287. }&lt;/code&gt;&lt;/pre&gt;
  288. * &lt;p&gt;Other data may be placed into the response for processing by the {@link Ext.form.BasicForm}'s callback
  289. * or event handler methods. The object decoded from this JSON is available in the
  290. * {@link Ext.form.Action#result result} property.&lt;/p&gt;
  291. * &lt;p&gt;Alternatively, if an {@link #errorReader} is specified as an {@link Ext.data.XmlReader XmlReader}:&lt;/p&gt;&lt;pre&gt;&lt;code&gt;
  292. errorReader: new Ext.data.XmlReader({
  293. record : 'field',
  294. success: '@success'
  295. }, [
  296. 'id', 'msg'
  297. ]
  298. )
  299. &lt;/code&gt;&lt;/pre&gt;
  300. * &lt;p&gt;then the results may be sent back in XML format:&lt;/p&gt;&lt;pre&gt;&lt;code&gt;
  301. &amp;lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&amp;gt;
  302. &amp;lt;message success=&quot;false&quot;&amp;gt;
  303. &amp;lt;errors&amp;gt;
  304. &amp;lt;field&amp;gt;
  305. &amp;lt;id&amp;gt;clientCode&amp;lt;/id&amp;gt;
  306. &amp;lt;msg&amp;gt;&amp;lt;![CDATA[Code not found. &amp;lt;br /&amp;gt;&amp;lt;i&amp;gt;This is a test validation message from the server &amp;lt;/i&amp;gt;]]&amp;gt;&amp;lt;/msg&amp;gt;
  307. &amp;lt;/field&amp;gt;
  308. &amp;lt;field&amp;gt;
  309. &amp;lt;id&amp;gt;portOfLoading&amp;lt;/id&amp;gt;
  310. &amp;lt;msg&amp;gt;&amp;lt;![CDATA[Port not found. &amp;lt;br /&amp;gt;&amp;lt;i&amp;gt;This is a test validation message from the server &amp;lt;/i&amp;gt;]]&amp;gt;&amp;lt;/msg&amp;gt;
  311. &amp;lt;/field&amp;gt;
  312. &amp;lt;/errors&amp;gt;
  313. &amp;lt;/message&amp;gt;
  314. &lt;/code&gt;&lt;/pre&gt;
  315. * &lt;p&gt;Other elements may be placed into the response XML for processing by the {@link Ext.form.BasicForm}'s callback
  316. * or event handler methods. The XML document is available in the {@link #errorReader}'s {@link Ext.data.XmlReader#xmlData xmlData} property.&lt;/p&gt;
  317. */
  318. Ext.form.Action.Submit = function(form, options){
  319. Ext.form.Action.Submit.superclass.constructor.call(this, form, options);
  320. };
  321. Ext.extend(Ext.form.Action.Submit, Ext.form.Action, {
  322. <span id='Ext-form-Action-Submit-cfg-errorReader'> /**
  323. </span> * @cfg {Ext.data.DataReader} errorReader &lt;p&gt;&lt;b&gt;Optional. JSON is interpreted with
  324. * no need for an errorReader.&lt;/b&gt;&lt;/p&gt;
  325. * &lt;p&gt;A Reader which reads a single record from the returned data. The DataReader's
  326. * &lt;b&gt;success&lt;/b&gt; property specifies how submission success is determined. The Record's
  327. * data provides the error messages to apply to any invalid form Fields.&lt;/p&gt;
  328. */
  329. <span id='Ext-form-Action-Submit-cfg-clientValidation'> /**
  330. </span> * @cfg {boolean} clientValidation Determines whether a Form's fields are validated
  331. * in a final call to {@link Ext.form.BasicForm#isValid isValid} prior to submission.
  332. * Pass &lt;tt&gt;false&lt;/tt&gt; in the Form's submit options to prevent this. If not defined, pre-submission field validation
  333. * is performed.
  334. */
  335. type : 'submit',
  336. // private
  337. run : function(){
  338. var o = this.options,
  339. method = this.getMethod(),
  340. isGet = method == 'GET';
  341. if(o.clientValidation === false || this.form.isValid()){
  342. if (o.submitEmptyText === false) {
  343. var fields = this.form.items,
  344. emptyFields = [],
  345. setupEmptyFields = function(f){
  346. if (f.el.getValue() == f.emptyText) {
  347. emptyFields.push(f);
  348. f.el.dom.value = &quot;&quot;;
  349. }
  350. if(f.isComposite &amp;&amp; f.rendered){
  351. f.items.each(setupEmptyFields);
  352. }
  353. };
  354. fields.each(setupEmptyFields);
  355. }
  356. Ext.Ajax.request(Ext.apply(this.createCallback(o), {
  357. form:this.form.el.dom,
  358. url:this.getUrl(isGet),
  359. method: method,
  360. headers: o.headers,
  361. params:!isGet ? this.getParams() : null,
  362. isUpload: this.form.fileUpload
  363. }));
  364. if (o.submitEmptyText === false) {
  365. Ext.each(emptyFields, function(f) {
  366. if (f.applyEmptyText) {
  367. f.applyEmptyText();
  368. }
  369. });
  370. }
  371. }else if (o.clientValidation !== false){ // client validation failed
  372. this.failureType = Ext.form.Action.CLIENT_INVALID;
  373. this.form.afterAction(this, false);
  374. }
  375. },
  376. // private
  377. success : function(response){
  378. var result = this.processResponse(response);
  379. if(result === true || result.success){
  380. this.form.afterAction(this, true);
  381. return;
  382. }
  383. if(result.errors){
  384. this.form.markInvalid(result.errors);
  385. }
  386. this.failureType = Ext.form.Action.SERVER_INVALID;
  387. this.form.afterAction(this, false);
  388. },
  389. // private
  390. handleResponse : function(response){
  391. if(this.form.errorReader){
  392. var rs = this.form.errorReader.read(response);
  393. var errors = [];
  394. if(rs.records){
  395. for(var i = 0, len = rs.records.length; i &lt; len; i++) {
  396. var r = rs.records[i];
  397. errors[i] = r.data;
  398. }
  399. }
  400. if(errors.length &lt; 1){
  401. errors = null;
  402. }
  403. return {
  404. success : rs.success,
  405. errors : errors
  406. };
  407. }
  408. return this.decodeResponse(response);
  409. }
  410. });
  411. <span id='Ext-form-Action-Load'>/**
  412. </span> * @class Ext.form.Action.Load
  413. * @extends Ext.form.Action
  414. * &lt;p&gt;A class which handles loading of data from a server into the Fields of an {@link Ext.form.BasicForm}.&lt;/p&gt;
  415. * &lt;p&gt;Instances of this class are only created by a {@link Ext.form.BasicForm Form} when
  416. * {@link Ext.form.BasicForm#load load}ing.&lt;/p&gt;
  417. * &lt;p&gt;&lt;u&gt;&lt;b&gt;Response Packet Criteria&lt;/b&gt;&lt;/u&gt;&lt;/p&gt;
  418. * &lt;p&gt;A response packet &lt;b&gt;must&lt;/b&gt; contain:
  419. * &lt;div class=&quot;mdetail-params&quot;&gt;&lt;ul&gt;
  420. * &lt;li&gt;&lt;b&gt;&lt;code&gt;success&lt;/code&gt;&lt;/b&gt; property : Boolean&lt;/li&gt;
  421. * &lt;li&gt;&lt;b&gt;&lt;code&gt;data&lt;/code&gt;&lt;/b&gt; property : Object&lt;/li&gt;
  422. * &lt;div class=&quot;sub-desc&quot;&gt;The &lt;code&gt;data&lt;/code&gt; property contains the values of Fields to load.
  423. * The individual value object for each Field is passed to the Field's
  424. * {@link Ext.form.Field#setValue setValue} method.&lt;/div&gt;&lt;/li&gt;
  425. * &lt;/ul&gt;&lt;/div&gt;
  426. * &lt;p&gt;&lt;u&gt;&lt;b&gt;JSON Packets&lt;/b&gt;&lt;/u&gt;&lt;/p&gt;
  427. * &lt;p&gt;By default, response packets are assumed to be JSON, so for the following form load call:&lt;pre&gt;&lt;code&gt;
  428. var myFormPanel = new Ext.form.FormPanel({
  429. title: 'Client and routing info',
  430. items: [{
  431. fieldLabel: 'Client',
  432. name: 'clientName'
  433. }, {
  434. fieldLabel: 'Port of loading',
  435. name: 'portOfLoading'
  436. }, {
  437. fieldLabel: 'Port of discharge',
  438. name: 'portOfDischarge'
  439. }]
  440. });
  441. myFormPanel.{@link Ext.form.FormPanel#getForm getForm}().{@link Ext.form.BasicForm#load load}({
  442. url: '/getRoutingInfo.php',
  443. params: {
  444. consignmentRef: myConsignmentRef
  445. },
  446. failure: function(form, action) {
  447. Ext.Msg.alert(&quot;Load failed&quot;, action.result.errorMessage);
  448. }
  449. });
  450. &lt;/code&gt;&lt;/pre&gt;
  451. * a &lt;b&gt;success response&lt;/b&gt; packet may look like this:&lt;/p&gt;&lt;pre&gt;&lt;code&gt;
  452. {
  453. success: true,
  454. data: {
  455. clientName: &quot;Fred. Olsen Lines&quot;,
  456. portOfLoading: &quot;FXT&quot;,
  457. portOfDischarge: &quot;OSL&quot;
  458. }
  459. }&lt;/code&gt;&lt;/pre&gt;
  460. * while a &lt;b&gt;failure response&lt;/b&gt; packet may look like this:&lt;/p&gt;&lt;pre&gt;&lt;code&gt;
  461. {
  462. success: false,
  463. errorMessage: &quot;Consignment reference not found&quot;
  464. }&lt;/code&gt;&lt;/pre&gt;
  465. * &lt;p&gt;Other data may be placed into the response for processing the {@link Ext.form.BasicForm Form}'s
  466. * callback or event handler methods. The object decoded from this JSON is available in the
  467. * {@link Ext.form.Action#result result} property.&lt;/p&gt;
  468. */
  469. Ext.form.Action.Load = function(form, options){
  470. Ext.form.Action.Load.superclass.constructor.call(this, form, options);
  471. this.reader = this.form.reader;
  472. };
  473. Ext.extend(Ext.form.Action.Load, Ext.form.Action, {
  474. // private
  475. type : 'load',
  476. // private
  477. run : function(){
  478. Ext.Ajax.request(Ext.apply(
  479. this.createCallback(this.options), {
  480. method:this.getMethod(),
  481. url:this.getUrl(false),
  482. headers: this.options.headers,
  483. params:this.getParams()
  484. }));
  485. },
  486. // private
  487. success : function(response){
  488. var result = this.processResponse(response);
  489. if(result === true || !result.success || !result.data){
  490. this.failureType = Ext.form.Action.LOAD_FAILURE;
  491. this.form.afterAction(this, false);
  492. return;
  493. }
  494. this.form.clearInvalid();
  495. this.form.setValues(result.data);
  496. this.form.afterAction(this, true);
  497. },
  498. // private
  499. handleResponse : function(response){
  500. if(this.form.reader){
  501. var rs = this.form.reader.read(response);
  502. var data = rs.records &amp;&amp; rs.records[0] ? rs.records[0].data : null;
  503. return {
  504. success : rs.success,
  505. data : data
  506. };
  507. }
  508. return this.decodeResponse(response);
  509. }
  510. });
  511. <span id='Ext-form-Action-DirectLoad'>/**
  512. </span> * @class Ext.form.Action.DirectLoad
  513. * @extends Ext.form.Action.Load
  514. * &lt;p&gt;Provides Ext.direct support for loading form data.&lt;/p&gt;
  515. * &lt;p&gt;This example illustrates usage of Ext.Direct to &lt;b&gt;load&lt;/b&gt; a form through Ext.Direct.&lt;/p&gt;
  516. * &lt;pre&gt;&lt;code&gt;
  517. var myFormPanel = new Ext.form.FormPanel({
  518. // configs for FormPanel
  519. title: 'Basic Information',
  520. renderTo: document.body,
  521. width: 300, height: 160,
  522. padding: 10,
  523. // configs apply to child items
  524. defaults: {anchor: '100%'},
  525. defaultType: 'textfield',
  526. items: [{
  527. fieldLabel: 'Name',
  528. name: 'name'
  529. },{
  530. fieldLabel: 'Email',
  531. name: 'email'
  532. },{
  533. fieldLabel: 'Company',
  534. name: 'company'
  535. }],
  536. // configs for BasicForm
  537. api: {
  538. // The server-side method to call for load() requests
  539. load: Profile.getBasicInfo,
  540. // The server-side must mark the submit handler as a 'formHandler'
  541. submit: Profile.updateBasicInfo
  542. },
  543. // specify the order for the passed params
  544. paramOrder: ['uid', 'foo']
  545. });
  546. // load the form
  547. myFormPanel.getForm().load({
  548. // pass 2 arguments to server side getBasicInfo method (len=2)
  549. params: {
  550. foo: 'bar',
  551. uid: 34
  552. }
  553. });
  554. * &lt;/code&gt;&lt;/pre&gt;
  555. * The data packet sent to the server will resemble something like:
  556. * &lt;pre&gt;&lt;code&gt;
  557. [
  558. {
  559. &quot;action&quot;:&quot;Profile&quot;,&quot;method&quot;:&quot;getBasicInfo&quot;,&quot;type&quot;:&quot;rpc&quot;,&quot;tid&quot;:2,
  560. &quot;data&quot;:[34,&quot;bar&quot;] // note the order of the params
  561. }
  562. ]
  563. * &lt;/code&gt;&lt;/pre&gt;
  564. * The form will process a data packet returned by the server that is similar
  565. * to the following format:
  566. * &lt;pre&gt;&lt;code&gt;
  567. [
  568. {
  569. &quot;action&quot;:&quot;Profile&quot;,&quot;method&quot;:&quot;getBasicInfo&quot;,&quot;type&quot;:&quot;rpc&quot;,&quot;tid&quot;:2,
  570. &quot;result&quot;:{
  571. &quot;success&quot;:true,
  572. &quot;data&quot;:{
  573. &quot;name&quot;:&quot;Fred Flintstone&quot;,
  574. &quot;company&quot;:&quot;Slate Rock and Gravel&quot;,
  575. &quot;email&quot;:&quot;fred.flintstone@slaterg.com&quot;
  576. }
  577. }
  578. }
  579. ]
  580. * &lt;/code&gt;&lt;/pre&gt;
  581. */
  582. Ext.form.Action.DirectLoad = Ext.extend(Ext.form.Action.Load, {
  583. <span id='Ext-form-Action-DirectLoad-method-constructor'> constructor: function(form, opts) {
  584. </span> Ext.form.Action.DirectLoad.superclass.constructor.call(this, form, opts);
  585. },
  586. <span id='Ext-form-Action-DirectLoad-property-type'> type : 'directload',
  587. </span>
  588. <span id='Ext-form-Action-DirectLoad-method-run'> run : function(){
  589. </span> var args = this.getParams();
  590. args.push(this.success, this);
  591. this.form.api.load.apply(window, args);
  592. },
  593. <span id='Ext-form-Action-DirectLoad-method-getParams'> getParams : function() {
  594. </span> var buf = [], o = {};
  595. var bp = this.form.baseParams;
  596. var p = this.options.params;
  597. Ext.apply(o, p, bp);
  598. var paramOrder = this.form.paramOrder;
  599. if(paramOrder){
  600. for(var i = 0, len = paramOrder.length; i &lt; len; i++){
  601. buf.push(o[paramOrder[i]]);
  602. }
  603. }else if(this.form.paramsAsHash){
  604. buf.push(o);
  605. }
  606. return buf;
  607. },
  608. <span id='Ext-form-Action-DirectLoad-method-processResponse'> // Direct actions have already been processed and therefore
  609. </span> // we can directly set the result; Direct Actions do not have
  610. // a this.response property.
  611. processResponse : function(result) {
  612. this.result = result;
  613. return result;
  614. },
  615. <span id='Ext-form-Action-DirectLoad-method-success'> success : function(response, trans){
  616. </span> if(trans.type == Ext.Direct.exceptions.SERVER){
  617. response = {};
  618. }
  619. Ext.form.Action.DirectLoad.superclass.success.call(this, response);
  620. }
  621. });
  622. <span id='Ext-form-Action-DirectSubmit'>/**
  623. </span> * @class Ext.form.Action.DirectSubmit
  624. * @extends Ext.form.Action.Submit
  625. * &lt;p&gt;Provides Ext.direct support for submitting form data.&lt;/p&gt;
  626. * &lt;p&gt;This example illustrates usage of Ext.Direct to &lt;b&gt;submit&lt;/b&gt; a form through Ext.Direct.&lt;/p&gt;
  627. * &lt;pre&gt;&lt;code&gt;
  628. var myFormPanel = new Ext.form.FormPanel({
  629. // configs for FormPanel
  630. title: 'Basic Information',
  631. renderTo: document.body,
  632. width: 300, height: 160,
  633. padding: 10,
  634. buttons:[{
  635. text: 'Submit',
  636. handler: function(){
  637. myFormPanel.getForm().submit({
  638. params: {
  639. foo: 'bar',
  640. uid: 34
  641. }
  642. });
  643. }
  644. }],
  645. // configs apply to child items
  646. defaults: {anchor: '100%'},
  647. defaultType: 'textfield',
  648. items: [{
  649. fieldLabel: 'Name',
  650. name: 'name'
  651. },{
  652. fieldLabel: 'Email',
  653. name: 'email'
  654. },{
  655. fieldLabel: 'Company',
  656. name: 'company'
  657. }],
  658. // configs for BasicForm
  659. api: {
  660. // The server-side method to call for load() requests
  661. load: Profile.getBasicInfo,
  662. // The server-side must mark the submit handler as a 'formHandler'
  663. submit: Profile.updateBasicInfo
  664. },
  665. // specify the order for the passed params
  666. paramOrder: ['uid', 'foo']
  667. });
  668. * &lt;/code&gt;&lt;/pre&gt;
  669. * The data packet sent to the server will resemble something like:
  670. * &lt;pre&gt;&lt;code&gt;
  671. {
  672. &quot;action&quot;:&quot;Profile&quot;,&quot;method&quot;:&quot;updateBasicInfo&quot;,&quot;type&quot;:&quot;rpc&quot;,&quot;tid&quot;:&quot;6&quot;,
  673. &quot;result&quot;:{
  674. &quot;success&quot;:true,
  675. &quot;id&quot;:{
  676. &quot;extAction&quot;:&quot;Profile&quot;,&quot;extMethod&quot;:&quot;updateBasicInfo&quot;,
  677. &quot;extType&quot;:&quot;rpc&quot;,&quot;extTID&quot;:&quot;6&quot;,&quot;extUpload&quot;:&quot;false&quot;,
  678. &quot;name&quot;:&quot;Aaron Conran&quot;,&quot;email&quot;:&quot;aaron@extjs.com&quot;,&quot;company&quot;:&quot;Ext JS, LLC&quot;
  679. }
  680. }
  681. }
  682. * &lt;/code&gt;&lt;/pre&gt;
  683. * The form will process a data packet returned by the server that is similar
  684. * to the following:
  685. * &lt;pre&gt;&lt;code&gt;
  686. // sample success packet (batched requests)
  687. [
  688. {
  689. &quot;action&quot;:&quot;Profile&quot;,&quot;method&quot;:&quot;updateBasicInfo&quot;,&quot;type&quot;:&quot;rpc&quot;,&quot;tid&quot;:3,
  690. &quot;result&quot;:{
  691. &quot;success&quot;:true
  692. }
  693. }
  694. ]
  695. // sample failure packet (one request)
  696. {
  697. &quot;action&quot;:&quot;Profile&quot;,&quot;method&quot;:&quot;updateBasicInfo&quot;,&quot;type&quot;:&quot;rpc&quot;,&quot;tid&quot;:&quot;6&quot;,
  698. &quot;result&quot;:{
  699. &quot;errors&quot;:{
  700. &quot;email&quot;:&quot;already taken&quot;
  701. },
  702. &quot;success&quot;:false,
  703. &quot;foo&quot;:&quot;bar&quot;
  704. }
  705. }
  706. * &lt;/code&gt;&lt;/pre&gt;
  707. * Also see the discussion in {@link Ext.form.Action.DirectLoad}.
  708. */
  709. Ext.form.Action.DirectSubmit = Ext.extend(Ext.form.Action.Submit, {
  710. <span id='Ext-form-Action-DirectSubmit-method-constructor'> constructor : function(form, opts) {
  711. </span> Ext.form.Action.DirectSubmit.superclass.constructor.call(this, form, opts);
  712. },
  713. <span id='Ext-form-Action-DirectSubmit-property-type'> type : 'directsubmit',
  714. </span><span id='Ext-form-Action-DirectSubmit-method-run'> // override of Submit
  715. </span> run : function(){
  716. var o = this.options;
  717. if(o.clientValidation === false || this.form.isValid()){
  718. // tag on any additional params to be posted in the
  719. // form scope
  720. this.success.params = this.getParams();
  721. this.form.api.submit(this.form.el.dom, this.success, this);
  722. }else if (o.clientValidation !== false){ // client validation failed
  723. this.failureType = Ext.form.Action.CLIENT_INVALID;
  724. this.form.afterAction(this, false);
  725. }
  726. },
  727. <span id='Ext-form-Action-DirectSubmit-method-getParams'> getParams : function() {
  728. </span> var o = {};
  729. var bp = this.form.baseParams;
  730. var p = this.options.params;
  731. Ext.apply(o, p, bp);
  732. return o;
  733. },
  734. <span id='Ext-form-Action-DirectSubmit-method-processResponse'> // Direct actions have already been processed and therefore
  735. </span> // we can directly set the result; Direct Actions do not have
  736. // a this.response property.
  737. processResponse : function(result) {
  738. this.result = result;
  739. return result;
  740. },
  741. <span id='Ext-form-Action-DirectSubmit-method-success'> success : function(response, trans){
  742. </span> if(trans.type == Ext.Direct.exceptions.SERVER){
  743. response = {};
  744. }
  745. Ext.form.Action.DirectSubmit.superclass.success.call(this, response);
  746. }
  747. });
  748. Ext.form.Action.ACTION_TYPES = {
  749. 'load' : Ext.form.Action.Load,
  750. 'submit' : Ext.form.Action.Submit,
  751. 'directload' : Ext.form.Action.DirectLoad,
  752. 'directsubmit' : Ext.form.Action.DirectSubmit
  753. };
  754. </pre>
  755. </body>
  756. </html>