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.

820 lines
33 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.BasicForm"></div>/**
  16. * @class Ext.form.BasicForm
  17. * @extends Ext.util.Observable
  18. * <p>Encapsulates the DOM &lt;form> element at the heart of the {@link Ext.form.FormPanel FormPanel} class, and provides
  19. * input field management, validation, submission, and form loading services.</p>
  20. * <p>By default, Ext Forms are submitted through Ajax, using an instance of {@link Ext.form.Action.Submit}.
  21. * To enable normal browser submission of an Ext Form, use the {@link #standardSubmit} config option.</p>
  22. * <p><b><u>File Uploads</u></b></p>
  23. * <p>{@link #fileUpload File uploads} are not performed using Ajax submission, that
  24. * is they are <b>not</b> performed using XMLHttpRequests. Instead the form is submitted in the standard
  25. * manner with the DOM <tt>&lt;form></tt> element temporarily modified to have its
  26. * <a href="http://www.w3.org/TR/REC-html40/present/frames.html#adef-target">target</a> set to refer
  27. * to a dynamically generated, hidden <tt>&lt;iframe></tt> which is inserted into the document
  28. * but removed after the return data has been gathered.</p>
  29. * <p>The server response is parsed by the browser to create the document for the IFRAME. If the
  30. * server is using JSON to send the return object, then the
  31. * <a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.17">Content-Type</a> header
  32. * must be set to "text/html" in order to tell the browser to insert the text unchanged into the document body.</p>
  33. * <p>Characters which are significant to an HTML parser must be sent as HTML entities, so encode
  34. * "&lt;" as "&amp;lt;", "&amp;" as "&amp;amp;" etc.</p>
  35. * <p>The response text is retrieved from the document, and a fake XMLHttpRequest object
  36. * is created containing a <tt>responseText</tt> property in order to conform to the
  37. * requirements of event handlers and callbacks.</p>
  38. * <p>Be aware that file upload packets are sent with the content type <a href="http://www.faqs.org/rfcs/rfc2388.html">multipart/form</a>
  39. * and some server technologies (notably JEE) may require some custom processing in order to
  40. * retrieve parameter names and parameter values from the packet content.</p>
  41. * @constructor
  42. * @param {Mixed} el The form element or its id
  43. * @param {Object} config Configuration options
  44. */
  45. Ext.form.BasicForm = Ext.extend(Ext.util.Observable, {
  46. constructor: function(el, config){
  47. Ext.apply(this, config);
  48. if(Ext.isString(this.paramOrder)){
  49. this.paramOrder = this.paramOrder.split(/[\s,|]/);
  50. }
  51. <div id="prop-Ext.form.BasicForm-items"></div>/**
  52. * A {@link Ext.util.MixedCollection MixedCollection} containing all the Ext.form.Fields in this form.
  53. * @type MixedCollection
  54. * @property items
  55. */
  56. this.items = new Ext.util.MixedCollection(false, function(o){
  57. return o.getItemId();
  58. });
  59. this.addEvents(
  60. <div id="event-Ext.form.BasicForm-beforeaction"></div>/**
  61. * @event beforeaction
  62. * Fires before any action is performed. Return false to cancel the action.
  63. * @param {Form} this
  64. * @param {Action} action The {@link Ext.form.Action} to be performed
  65. */
  66. 'beforeaction',
  67. <div id="event-Ext.form.BasicForm-actionfailed"></div>/**
  68. * @event actionfailed
  69. * Fires when an action fails.
  70. * @param {Form} this
  71. * @param {Action} action The {@link Ext.form.Action} that failed
  72. */
  73. 'actionfailed',
  74. <div id="event-Ext.form.BasicForm-actioncomplete"></div>/**
  75. * @event actioncomplete
  76. * Fires when an action is completed.
  77. * @param {Form} this
  78. * @param {Action} action The {@link Ext.form.Action} that completed
  79. */
  80. 'actioncomplete'
  81. );
  82. if(el){
  83. this.initEl(el);
  84. }
  85. Ext.form.BasicForm.superclass.constructor.call(this);
  86. },
  87. <div id="cfg-Ext.form.BasicForm-method"></div>/**
  88. * @cfg {String} method
  89. * The request method to use (GET or POST) for form actions if one isn't supplied in the action options.
  90. */
  91. <div id="cfg-Ext.form.BasicForm-reader"></div>/**
  92. * @cfg {DataReader} reader
  93. * An Ext.data.DataReader (e.g. {@link Ext.data.XmlReader}) to be used to read
  94. * data when executing 'load' actions. This is optional as there is built-in
  95. * support for processing JSON. For additional information on using an XMLReader
  96. * see the example provided in examples/form/xml-form.html.
  97. */
  98. <div id="cfg-Ext.form.BasicForm-errorReader"></div>/**
  99. * @cfg {DataReader} errorReader
  100. * <p>An Ext.data.DataReader (e.g. {@link Ext.data.XmlReader}) to be used to
  101. * read field error messages returned from 'submit' actions. This is optional
  102. * as there is built-in support for processing JSON.</p>
  103. * <p>The Records which provide messages for the invalid Fields must use the
  104. * Field name (or id) as the Record ID, and must contain a field called 'msg'
  105. * which contains the error message.</p>
  106. * <p>The errorReader does not have to be a full-blown implementation of a
  107. * DataReader. It simply needs to implement a <tt>read(xhr)</tt> function
  108. * which returns an Array of Records in an object with the following
  109. * structure:</p><pre><code>
  110. {
  111. records: recordArray
  112. }
  113. </code></pre>
  114. */
  115. <div id="cfg-Ext.form.BasicForm-url"></div>/**
  116. * @cfg {String} url
  117. * The URL to use for form actions if one isn't supplied in the
  118. * <code>{@link #doAction doAction} options</code>.
  119. */
  120. <div id="cfg-Ext.form.BasicForm-fileUpload"></div>/**
  121. * @cfg {Boolean} fileUpload
  122. * Set to true if this form is a file upload.
  123. * <p>File uploads are not performed using normal 'Ajax' techniques, that is they are <b>not</b>
  124. * performed using XMLHttpRequests. Instead the form is submitted in the standard manner with the
  125. * DOM <tt>&lt;form></tt> element temporarily modified to have its
  126. * <a href="http://www.w3.org/TR/REC-html40/present/frames.html#adef-target">target</a> set to refer
  127. * to a dynamically generated, hidden <tt>&lt;iframe></tt> which is inserted into the document
  128. * but removed after the return data has been gathered.</p>
  129. * <p>The server response is parsed by the browser to create the document for the IFRAME. If the
  130. * server is using JSON to send the return object, then the
  131. * <a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.17">Content-Type</a> header
  132. * must be set to "text/html" in order to tell the browser to insert the text unchanged into the document body.</p>
  133. * <p>Characters which are significant to an HTML parser must be sent as HTML entities, so encode
  134. * "&lt;" as "&amp;lt;", "&amp;" as "&amp;amp;" etc.</p>
  135. * <p>The response text is retrieved from the document, and a fake XMLHttpRequest object
  136. * is created containing a <tt>responseText</tt> property in order to conform to the
  137. * requirements of event handlers and callbacks.</p>
  138. * <p>Be aware that file upload packets are sent with the content type <a href="http://www.faqs.org/rfcs/rfc2388.html">multipart/form</a>
  139. * and some server technologies (notably JEE) may require some custom processing in order to
  140. * retrieve parameter names and parameter values from the packet content.</p>
  141. */
  142. <div id="cfg-Ext.form.BasicForm-baseParams"></div>/**
  143. * @cfg {Object} baseParams
  144. * <p>Parameters to pass with all requests. e.g. baseParams: {id: '123', foo: 'bar'}.</p>
  145. * <p>Parameters are encoded as standard HTTP parameters using {@link Ext#urlEncode}.</p>
  146. */
  147. <div id="cfg-Ext.form.BasicForm-timeout"></div>/**
  148. * @cfg {Number} timeout Timeout for form actions in seconds (default is 30 seconds).
  149. */
  150. timeout: 30,
  151. <div id="cfg-Ext.form.BasicForm-api"></div>/**
  152. * @cfg {Object} api (Optional) If specified load and submit actions will be handled
  153. * with {@link Ext.form.Action.DirectLoad} and {@link Ext.form.Action.DirectSubmit}.
  154. * Methods which have been imported by Ext.Direct can be specified here to load and submit
  155. * forms.
  156. * Such as the following:<pre><code>
  157. api: {
  158. load: App.ss.MyProfile.load,
  159. submit: App.ss.MyProfile.submit
  160. }
  161. </code></pre>
  162. * <p>Load actions can use <code>{@link #paramOrder}</code> or <code>{@link #paramsAsHash}</code>
  163. * to customize how the load method is invoked.
  164. * Submit actions will always use a standard form submit. The formHandler configuration must
  165. * be set on the associated server-side method which has been imported by Ext.Direct</p>
  166. */
  167. <div id="cfg-Ext.form.BasicForm-paramOrder"></div>/**
  168. * @cfg {Array/String} paramOrder <p>A list of params to be executed server side.
  169. * Defaults to <tt>undefined</tt>. Only used for the <code>{@link #api}</code>
  170. * <code>load</code> configuration.</p>
  171. * <br><p>Specify the params in the order in which they must be executed on the
  172. * server-side as either (1) an Array of String values, or (2) a String of params
  173. * delimited by either whitespace, comma, or pipe. For example,
  174. * any of the following would be acceptable:</p><pre><code>
  175. paramOrder: ['param1','param2','param3']
  176. paramOrder: 'param1 param2 param3'
  177. paramOrder: 'param1,param2,param3'
  178. paramOrder: 'param1|param2|param'
  179. </code></pre>
  180. */
  181. paramOrder: undefined,
  182. <div id="cfg-Ext.form.BasicForm-paramsAsHash"></div>/**
  183. * @cfg {Boolean} paramsAsHash Only used for the <code>{@link #api}</code>
  184. * <code>load</code> configuration. Send parameters as a collection of named
  185. * arguments (defaults to <tt>false</tt>). Providing a
  186. * <tt>{@link #paramOrder}</tt> nullifies this configuration.
  187. */
  188. paramsAsHash: false,
  189. <div id="cfg-Ext.form.BasicForm-waitTitle"></div>/**
  190. * @cfg {String} waitTitle
  191. * The default title to show for the waiting message box (defaults to <tt>'Please Wait...'</tt>)
  192. */
  193. waitTitle: 'Please Wait...',
  194. // private
  195. activeAction : null,
  196. <div id="cfg-Ext.form.BasicForm-trackResetOnLoad"></div>/**
  197. * @cfg {Boolean} trackResetOnLoad If set to <tt>true</tt>, {@link #reset}() resets to the last loaded
  198. * or {@link #setValues}() data instead of when the form was first created. Defaults to <tt>false</tt>.
  199. */
  200. trackResetOnLoad : false,
  201. <div id="cfg-Ext.form.BasicForm-standardSubmit"></div>/**
  202. * @cfg {Boolean} standardSubmit
  203. * <p>If set to <tt>true</tt>, standard HTML form submits are used instead
  204. * of XHR (Ajax) style form submissions. Defaults to <tt>false</tt>.</p>
  205. * <br><p><b>Note:</b> When using <code>standardSubmit</code>, the
  206. * <code>options</code> to <code>{@link #submit}</code> are ignored because
  207. * Ext's Ajax infrastracture is bypassed. To pass extra parameters (e.g.
  208. * <code>baseParams</code> and <code>params</code>), utilize hidden fields
  209. * to submit extra data, for example:</p>
  210. * <pre><code>
  211. new Ext.FormPanel({
  212. standardSubmit: true,
  213. baseParams: {
  214. foo: 'bar'
  215. },
  216. {@link url}: 'myProcess.php',
  217. items: [{
  218. xtype: 'textfield',
  219. name: 'userName'
  220. }],
  221. buttons: [{
  222. text: 'Save',
  223. handler: function(){
  224. var fp = this.ownerCt.ownerCt,
  225. form = fp.getForm();
  226. if (form.isValid()) {
  227. // check if there are baseParams and if
  228. // hiddent items have been added already
  229. if (fp.baseParams && !fp.paramsAdded) {
  230. // add hidden items for all baseParams
  231. for (i in fp.baseParams) {
  232. fp.add({
  233. xtype: 'hidden',
  234. name: i,
  235. value: fp.baseParams[i]
  236. });
  237. }
  238. fp.doLayout();
  239. // set a custom flag to prevent re-adding
  240. fp.paramsAdded = true;
  241. }
  242. form.{@link #submit}();
  243. }
  244. }
  245. }]
  246. });
  247. * </code></pre>
  248. */
  249. <div id="prop-Ext.form.BasicForm-waitMsgTarget"></div>/**
  250. * By default wait messages are displayed with Ext.MessageBox.wait. You can target a specific
  251. * element by passing it or its id or mask the form itself by passing in true.
  252. * @type Mixed
  253. * @property waitMsgTarget
  254. */
  255. // private
  256. initEl : function(el){
  257. this.el = Ext.get(el);
  258. this.id = this.el.id || Ext.id();
  259. if(!this.standardSubmit){
  260. this.el.on('submit', this.onSubmit, this);
  261. }
  262. this.el.addClass('x-form');
  263. },
  264. <div id="method-Ext.form.BasicForm-getEl"></div>/**
  265. * Get the HTML form Element
  266. * @return Ext.Element
  267. */
  268. getEl: function(){
  269. return this.el;
  270. },
  271. // private
  272. onSubmit : function(e){
  273. e.stopEvent();
  274. },
  275. /**
  276. * Destroys this object.
  277. * @private
  278. * @param {Boolean} bound true if the object is bound to a form panel. If this is the case
  279. * the FormPanel will take care of destroying certain things, so we're just doubling up.
  280. */
  281. destroy: function(bound){
  282. if(bound !== true){
  283. this.items.each(function(f){
  284. Ext.destroy(f);
  285. });
  286. Ext.destroy(this.el);
  287. }
  288. this.items.clear();
  289. this.purgeListeners();
  290. },
  291. <div id="method-Ext.form.BasicForm-isValid"></div>/**
  292. * Returns true if client-side validation on the form is successful.
  293. * @return Boolean
  294. */
  295. isValid : function(){
  296. var valid = true;
  297. this.items.each(function(f){
  298. if(!f.validate()){
  299. valid = false;
  300. }
  301. });
  302. return valid;
  303. },
  304. <div id="method-Ext.form.BasicForm-isDirty"></div>/**
  305. * <p>Returns true if any fields in this form have changed from their original values.</p>
  306. * <p>Note that if this BasicForm was configured with {@link #trackResetOnLoad} then the
  307. * Fields' <i>original values</i> are updated when the values are loaded by {@link #setValues}
  308. * or {@link #loadRecord}.</p>
  309. * @return Boolean
  310. */
  311. isDirty : function(){
  312. var dirty = false;
  313. this.items.each(function(f){
  314. if(f.isDirty()){
  315. dirty = true;
  316. return false;
  317. }
  318. });
  319. return dirty;
  320. },
  321. <div id="method-Ext.form.BasicForm-doAction"></div>/**
  322. * Performs a predefined action ({@link Ext.form.Action.Submit} or
  323. * {@link Ext.form.Action.Load}) or a custom extension of {@link Ext.form.Action}
  324. * to perform application-specific processing.
  325. * @param {String/Object} actionName The name of the predefined action type,
  326. * or instance of {@link Ext.form.Action} to perform.
  327. * @param {Object} options (optional) The options to pass to the {@link Ext.form.Action}.
  328. * All of the config options listed below are supported by both the
  329. * {@link Ext.form.Action.Submit submit} and {@link Ext.form.Action.Load load}
  330. * actions unless otherwise noted (custom actions could also accept
  331. * other config options):<ul>
  332. *
  333. * <li><b>url</b> : String<div class="sub-desc">The url for the action (defaults
  334. * to the form's {@link #url}.)</div></li>
  335. *
  336. * <li><b>method</b> : String<div class="sub-desc">The form method to use (defaults
  337. * to the form's method, or POST if not defined)</div></li>
  338. *
  339. * <li><b>params</b> : String/Object<div class="sub-desc"><p>The params to pass
  340. * (defaults to the form's baseParams, or none if not defined)</p>
  341. * <p>Parameters are encoded as standard HTTP parameters using {@link Ext#urlEncode}.</p></div></li>
  342. *
  343. * <li><b>headers</b> : Object<div class="sub-desc">Request headers to set for the action
  344. * (defaults to the form's default headers)</div></li>
  345. *
  346. * <li><b>success</b> : Function<div class="sub-desc">The callback that will
  347. * be invoked after a successful response (see top of
  348. * {@link Ext.form.Action.Submit submit} and {@link Ext.form.Action.Load load}
  349. * for a description of what constitutes a successful response).
  350. * The function is passed the following parameters:<ul>
  351. * <li><tt>form</tt> : Ext.form.BasicForm<div class="sub-desc">The form that requested the action</div></li>
  352. * <li><tt>action</tt> : The {@link Ext.form.Action Action} object which performed the operation.
  353. * <div class="sub-desc">The action object contains these properties of interest:<ul>
  354. * <li><tt>{@link Ext.form.Action#response response}</tt></li>
  355. * <li><tt>{@link Ext.form.Action#result result}</tt> : interrogate for custom postprocessing</li>
  356. * <li><tt>{@link Ext.form.Action#type type}</tt></li>
  357. * </ul></div></li></ul></div></li>
  358. *
  359. * <li><b>failure</b> : Function<div class="sub-desc">The callback that will be invoked after a
  360. * failed transaction attempt. The function is passed the following parameters:<ul>
  361. * <li><tt>form</tt> : The {@link Ext.form.BasicForm} that requested the action.</li>
  362. * <li><tt>action</tt> : The {@link Ext.form.Action Action} object which performed the operation.
  363. * <div class="sub-desc">The action object contains these properties of interest:<ul>
  364. * <li><tt>{@link Ext.form.Action#failureType failureType}</tt></li>
  365. * <li><tt>{@link Ext.form.Action#response response}</tt></li>
  366. * <li><tt>{@link Ext.form.Action#result result}</tt> : interrogate for custom postprocessing</li>
  367. * <li><tt>{@link Ext.form.Action#type type}</tt></li>
  368. * </ul></div></li></ul></div></li>
  369. *
  370. * <li><b>scope</b> : Object<div class="sub-desc">The scope in which to call the
  371. * callback functions (The <tt>this</tt> reference for the callback functions).</div></li>
  372. *
  373. * <li><b>clientValidation</b> : Boolean<div class="sub-desc">Submit Action only.
  374. * Determines whether a Form's fields are validated in a final call to
  375. * {@link Ext.form.BasicForm#isValid isValid} prior to submission. Set to <tt>false</tt>
  376. * to prevent this. If undefined, pre-submission field validation is performed.</div></li></ul>
  377. *
  378. * @return {BasicForm} this
  379. */
  380. doAction : function(action, options){
  381. if(Ext.isString(action)){
  382. action = new Ext.form.Action.ACTION_TYPES[action](this, options);
  383. }
  384. if(this.fireEvent('beforeaction', this, action) !== false){
  385. this.beforeAction(action);
  386. action.run.defer(100, action);
  387. }
  388. return this;
  389. },
  390. <div id="method-Ext.form.BasicForm-submit"></div>/**
  391. * Shortcut to {@link #doAction do} a {@link Ext.form.Action.Submit submit action}.
  392. * @param {Object} options The options to pass to the action (see {@link #doAction} for details).<br>
  393. * <p><b>Note:</b> this is ignored when using the {@link #standardSubmit} option.</p>
  394. * <p>The following code:</p><pre><code>
  395. myFormPanel.getForm().submit({
  396. clientValidation: true,
  397. url: 'updateConsignment.php',
  398. params: {
  399. newStatus: 'delivered'
  400. },
  401. success: function(form, action) {
  402. Ext.Msg.alert('Success', action.result.msg);
  403. },
  404. failure: function(form, action) {
  405. switch (action.failureType) {
  406. case Ext.form.Action.CLIENT_INVALID:
  407. Ext.Msg.alert('Failure', 'Form fields may not be submitted with invalid values');
  408. break;
  409. case Ext.form.Action.CONNECT_FAILURE:
  410. Ext.Msg.alert('Failure', 'Ajax communication failed');
  411. break;
  412. case Ext.form.Action.SERVER_INVALID:
  413. Ext.Msg.alert('Failure', action.result.msg);
  414. }
  415. }
  416. });
  417. </code></pre>
  418. * would process the following server response for a successful submission:<pre><code>
  419. {
  420. "success":true, // note this is Boolean, not string
  421. "msg":"Consignment updated"
  422. }
  423. </code></pre>
  424. * and the following server response for a failed submission:<pre><code>
  425. {
  426. "success":false, // note this is Boolean, not string
  427. "msg":"You do not have permission to perform this operation"
  428. }
  429. </code></pre>
  430. * @return {BasicForm} this
  431. */
  432. submit : function(options){
  433. options = options || {};
  434. if(this.standardSubmit){
  435. var v = options.clientValidation === false || this.isValid();
  436. if(v){
  437. var el = this.el.dom;
  438. if(this.url && Ext.isEmpty(el.action)){
  439. el.action = this.url;
  440. }
  441. el.submit();
  442. }
  443. return v;
  444. }
  445. var submitAction = String.format('{0}submit', this.api ? 'direct' : '');
  446. this.doAction(submitAction, options);
  447. return this;
  448. },
  449. <div id="method-Ext.form.BasicForm-load"></div>/**
  450. * Shortcut to {@link #doAction do} a {@link Ext.form.Action.Load load action}.
  451. * @param {Object} options The options to pass to the action (see {@link #doAction} for details)
  452. * @return {BasicForm} this
  453. */
  454. load : function(options){
  455. var loadAction = String.format('{0}load', this.api ? 'direct' : '');
  456. this.doAction(loadAction, options);
  457. return this;
  458. },
  459. <div id="method-Ext.form.BasicForm-updateRecord"></div>/**
  460. * Persists the values in this form into the passed {@link Ext.data.Record} object in a beginEdit/endEdit block.
  461. * @param {Record} record The record to edit
  462. * @return {BasicForm} this
  463. */
  464. updateRecord : function(record){
  465. record.beginEdit();
  466. var fs = record.fields,
  467. field,
  468. value;
  469. fs.each(function(f){
  470. field = this.findField(f.name);
  471. if(field){
  472. value = field.getValue();
  473. if (typeof value != undefined && value.getGroupValue) {
  474. value = value.getGroupValue();
  475. } else if ( field.eachItem ) {
  476. value = [];
  477. field.eachItem(function(item){
  478. value.push(item.getValue());
  479. });
  480. }
  481. record.set(f.name, value);
  482. }
  483. }, this);
  484. record.endEdit();
  485. return this;
  486. },
  487. <div id="method-Ext.form.BasicForm-loadRecord"></div>/**
  488. * Loads an {@link Ext.data.Record} into this form by calling {@link #setValues} with the
  489. * {@link Ext.data.Record#data record data}.
  490. * See also {@link #trackResetOnLoad}.
  491. * @param {Record} record The record to load
  492. * @return {BasicForm} this
  493. */
  494. loadRecord : function(record){
  495. this.setValues(record.data);
  496. return this;
  497. },
  498. // private
  499. beforeAction : function(action){
  500. // Call HtmlEditor's syncValue before actions
  501. this.items.each(function(f){
  502. if(f.isFormField && f.syncValue){
  503. f.syncValue();
  504. }
  505. });
  506. var o = action.options;
  507. if(o.waitMsg){
  508. if(this.waitMsgTarget === true){
  509. this.el.mask(o.waitMsg, 'x-mask-loading');
  510. }else if(this.waitMsgTarget){
  511. this.waitMsgTarget = Ext.get(this.waitMsgTarget);
  512. this.waitMsgTarget.mask(o.waitMsg, 'x-mask-loading');
  513. }else{
  514. Ext.MessageBox.wait(o.waitMsg, o.waitTitle || this.waitTitle);
  515. }
  516. }
  517. },
  518. // private
  519. afterAction : function(action, success){
  520. this.activeAction = null;
  521. var o = action.options;
  522. if(o.waitMsg){
  523. if(this.waitMsgTarget === true){
  524. this.el.unmask();
  525. }else if(this.waitMsgTarget){
  526. this.waitMsgTarget.unmask();
  527. }else{
  528. Ext.MessageBox.updateProgress(1);
  529. Ext.MessageBox.hide();
  530. }
  531. }
  532. if(success){
  533. if(o.reset){
  534. this.reset();
  535. }
  536. Ext.callback(o.success, o.scope, [this, action]);
  537. this.fireEvent('actioncomplete', this, action);
  538. }else{
  539. Ext.callback(o.failure, o.scope, [this, action]);
  540. this.fireEvent('actionfailed', this, action);
  541. }
  542. },
  543. <div id="method-Ext.form.BasicForm-findField"></div>/**
  544. * Find a {@link Ext.form.Field} in this form.
  545. * @param {String} id The value to search for (specify either a {@link Ext.Component#id id},
  546. * {@link Ext.grid.Column#dataIndex dataIndex}, {@link Ext.form.Field#getName name or hiddenName}).
  547. * @return Field
  548. */
  549. findField : function(id) {
  550. var field = this.items.get(id);
  551. if (!Ext.isObject(field)) {
  552. //searches for the field corresponding to the given id. Used recursively for composite fields
  553. var findMatchingField = function(f) {
  554. if (f.isFormField) {
  555. if (f.dataIndex == id || f.id == id || f.getName() == id) {
  556. field = f;
  557. return false;
  558. } else if (f.isComposite) {
  559. return f.items.each(findMatchingField);
  560. } else if (f instanceof Ext.form.CheckboxGroup && f.rendered) {
  561. return f.eachItem(findMatchingField);
  562. }
  563. }
  564. };
  565. this.items.each(findMatchingField);
  566. }
  567. return field || null;
  568. },
  569. <div id="method-Ext.form.BasicForm-markInvalid"></div>/**
  570. * Mark fields in this form invalid in bulk.
  571. * @param {Array/Object} errors Either an array in the form [{id:'fieldId', msg:'The message'},...] or an object hash of {id: msg, id2: msg2}
  572. * @return {BasicForm} this
  573. */
  574. markInvalid : function(errors){
  575. if (Ext.isArray(errors)) {
  576. for(var i = 0, len = errors.length; i < len; i++){
  577. var fieldError = errors[i];
  578. var f = this.findField(fieldError.id);
  579. if(f){
  580. f.markInvalid(fieldError.msg);
  581. }
  582. }
  583. } else {
  584. var field, id;
  585. for(id in errors){
  586. if(!Ext.isFunction(errors[id]) && (field = this.findField(id))){
  587. field.markInvalid(errors[id]);
  588. }
  589. }
  590. }
  591. return this;
  592. },
  593. <div id="method-Ext.form.BasicForm-setValues"></div>/**
  594. * Set values for fields in this form in bulk.
  595. * @param {Array/Object} values Either an array in the form:<pre><code>
  596. [{id:'clientName', value:'Fred. Olsen Lines'},
  597. {id:'portOfLoading', value:'FXT'},
  598. {id:'portOfDischarge', value:'OSL'} ]</code></pre>
  599. * or an object hash of the form:<pre><code>
  600. {
  601. clientName: 'Fred. Olsen Lines',
  602. portOfLoading: 'FXT',
  603. portOfDischarge: 'OSL'
  604. }</code></pre>
  605. * @return {BasicForm} this
  606. */
  607. setValues : function(values){
  608. if(Ext.isArray(values)){ // array of objects
  609. for(var i = 0, len = values.length; i < len; i++){
  610. var v = values[i];
  611. var f = this.findField(v.id);
  612. if(f){
  613. f.setValue(v.value);
  614. if(this.trackResetOnLoad){
  615. f.originalValue = f.getValue();
  616. }
  617. }
  618. }
  619. }else{ // object hash
  620. var field, id;
  621. for(id in values){
  622. if(!Ext.isFunction(values[id]) && (field = this.findField(id))){
  623. field.setValue(values[id]);
  624. if(this.trackResetOnLoad){
  625. field.originalValue = field.getValue();
  626. }
  627. }
  628. }
  629. }
  630. return this;
  631. },
  632. <div id="method-Ext.form.BasicForm-getValues"></div>/**
  633. * <p>Returns the fields in this form as an object with key/value pairs as they would be submitted using a standard form submit.
  634. * If multiple fields exist with the same name they are returned as an array.</p>
  635. * <p><b>Note:</b> The values are collected from all enabled HTML input elements within the form, <u>not</u> from
  636. * the Ext Field objects. This means that all returned values are Strings (or Arrays of Strings) and that the
  637. * value can potentially be the emptyText of a field.</p>
  638. * @param {Boolean} asString (optional) Pass true to return the values as a string. (defaults to false, returning an Object)
  639. * @return {String/Object}
  640. */
  641. getValues : function(asString){
  642. var fs = Ext.lib.Ajax.serializeForm(this.el.dom);
  643. if(asString === true){
  644. return fs;
  645. }
  646. return Ext.urlDecode(fs);
  647. },
  648. <div id="method-Ext.form.BasicForm-getFieldValues"></div>/**
  649. * Retrieves the fields in the form as a set of key/value pairs, using the {@link Ext.form.Field#getValue getValue()} method.
  650. * If multiple fields exist with the same name they are returned as an array.
  651. * @param {Boolean} dirtyOnly (optional) True to return only fields that are dirty.
  652. * @return {Object} The values in the form
  653. */
  654. getFieldValues : function(dirtyOnly){
  655. var o = {},
  656. n,
  657. key,
  658. val;
  659. this.items.each(function(f) {
  660. if (!f.disabled && (dirtyOnly !== true || f.isDirty())) {
  661. n = f.getName();
  662. key = o[n];
  663. val = f.getValue();
  664. if(Ext.isDefined(key)){
  665. if(Ext.isArray(key)){
  666. o[n].push(val);
  667. }else{
  668. o[n] = [key, val];
  669. }
  670. }else{
  671. o[n] = val;
  672. }
  673. }
  674. });
  675. return o;
  676. },
  677. <div id="method-Ext.form.BasicForm-clearInvalid"></div>/**
  678. * Clears all invalid messages in this form.
  679. * @return {BasicForm} this
  680. */
  681. clearInvalid : function(){
  682. this.items.each(function(f){
  683. f.clearInvalid();
  684. });
  685. return this;
  686. },
  687. <div id="method-Ext.form.BasicForm-reset"></div>/**
  688. * Resets this form.
  689. * @return {BasicForm} this
  690. */
  691. reset : function(){
  692. this.items.each(function(f){
  693. f.reset();
  694. });
  695. return this;
  696. },
  697. <div id="method-Ext.form.BasicForm-add"></div>/**
  698. * Add Ext.form Components to this form's Collection. This does not result in rendering of
  699. * the passed Component, it just enables the form to validate Fields, and distribute values to
  700. * Fields.
  701. * <p><b>You will not usually call this function. In order to be rendered, a Field must be added
  702. * to a {@link Ext.Container Container}, usually an {@link Ext.form.FormPanel FormPanel}.
  703. * The FormPanel to which the field is added takes care of adding the Field to the BasicForm's
  704. * collection.</b></p>
  705. * @param {Field} field1
  706. * @param {Field} field2 (optional)
  707. * @param {Field} etc (optional)
  708. * @return {BasicForm} this
  709. */
  710. add : function(){
  711. this.items.addAll(Array.prototype.slice.call(arguments, 0));
  712. return this;
  713. },
  714. <div id="method-Ext.form.BasicForm-remove"></div>/**
  715. * Removes a field from the items collection (does NOT remove its markup).
  716. * @param {Field} field
  717. * @return {BasicForm} this
  718. */
  719. remove : function(field){
  720. this.items.remove(field);
  721. return this;
  722. },
  723. <div id="method-Ext.form.BasicForm-cleanDestroyed"></div>/**
  724. * Removes all fields from the collection that have been destroyed.
  725. */
  726. cleanDestroyed : function() {
  727. this.items.filterBy(function(o) { return !!o.isDestroyed; }).each(this.remove, this);
  728. },
  729. <div id="method-Ext.form.BasicForm-render"></div>/**
  730. * Iterates through the {@link Ext.form.Field Field}s which have been {@link #add add}ed to this BasicForm,
  731. * checks them for an id attribute, and calls {@link Ext.form.Field#applyToMarkup} on the existing dom element with that id.
  732. * @return {BasicForm} this
  733. */
  734. render : function(){
  735. this.items.each(function(f){
  736. if(f.isFormField && !f.rendered && document.getElementById(f.id)){ // if the element exists
  737. f.applyToMarkup(f.id);
  738. }
  739. });
  740. return this;
  741. },
  742. <div id="method-Ext.form.BasicForm-applyToFields"></div>/**
  743. * Calls {@link Ext#apply} for all fields in this form with the passed object.
  744. * @param {Object} values
  745. * @return {BasicForm} this
  746. */
  747. applyToFields : function(o){
  748. this.items.each(function(f){
  749. Ext.apply(f, o);
  750. });
  751. return this;
  752. },
  753. <div id="method-Ext.form.BasicForm-applyIfToFields"></div>/**
  754. * Calls {@link Ext#applyIf} for all field in this form with the passed object.
  755. * @param {Object} values
  756. * @return {BasicForm} this
  757. */
  758. applyIfToFields : function(o){
  759. this.items.each(function(f){
  760. Ext.applyIf(f, o);
  761. });
  762. return this;
  763. },
  764. callFieldMethod : function(fnName, args){
  765. args = args || [];
  766. this.items.each(function(f){
  767. if(Ext.isFunction(f[fnName])){
  768. f[fnName].apply(f, args);
  769. }
  770. });
  771. return this;
  772. }
  773. });
  774. // back compat
  775. Ext.BasicForm = Ext.form.BasicForm;
  776. </pre>
  777. </body>
  778. </html>