Web Interface For Lite Argus Control modules
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.

788 lines
28 KiB

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