Web UI for ARGUS server
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.

368 lines
13 KiB

6 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  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.FormPanel"></div>/**
  16. * @class Ext.form.FormPanel
  17. * @extends Ext.Panel
  18. * <p>Standard form container.</p>
  19. *
  20. * <p><b><u>Layout</u></b></p>
  21. * <p>By default, FormPanel is configured with <tt>layout:'form'</tt> to use an {@link Ext.layout.FormLayout}
  22. * layout manager, which styles and renders fields and labels correctly. When nesting additional Containers
  23. * within a FormPanel, you should ensure that any descendant Containers which host input Fields use the
  24. * {@link Ext.layout.FormLayout} layout manager.</p>
  25. *
  26. * <p><b><u>BasicForm</u></b></p>
  27. * <p>Although <b>not listed</b> as configuration options of FormPanel, the FormPanel class accepts all
  28. * of the config options required to configure its internal {@link Ext.form.BasicForm} for:
  29. * <div class="mdetail-params"><ul>
  30. * <li>{@link Ext.form.BasicForm#fileUpload file uploads}</li>
  31. * <li>functionality for {@link Ext.form.BasicForm#doAction loading, validating and submitting} the form</li>
  32. * </ul></div>
  33. *
  34. * <p><b>Note</b>: If subclassing FormPanel, any configuration options for the BasicForm must be applied to
  35. * the <tt><b>initialConfig</b></tt> property of the FormPanel. Applying {@link Ext.form.BasicForm BasicForm}
  36. * configuration settings to <b><tt>this</tt></b> will <b>not</b> affect the BasicForm's configuration.</p>
  37. *
  38. * <p><b><u>Form Validation</u></b></p>
  39. * <p>For information on form validation see the following:</p>
  40. * <div class="mdetail-params"><ul>
  41. * <li>{@link Ext.form.TextField}</li>
  42. * <li>{@link Ext.form.VTypes}</li>
  43. * <li>{@link Ext.form.BasicForm#doAction BasicForm.doAction <b>clientValidation</b> notes}</li>
  44. * <li><tt>{@link Ext.form.FormPanel#monitorValid monitorValid}</tt></li>
  45. * </ul></div>
  46. *
  47. * <p><b><u>Form Submission</u></b></p>
  48. * <p>By default, Ext Forms are submitted through Ajax, using {@link Ext.form.Action}. To enable normal browser
  49. * submission of the {@link Ext.form.BasicForm BasicForm} contained in this FormPanel, see the
  50. * <tt><b>{@link Ext.form.BasicForm#standardSubmit standardSubmit}</b></tt> option.</p>
  51. *
  52. * @constructor
  53. * @param {Object} config Configuration options
  54. * @xtype form
  55. */
  56. Ext.FormPanel = Ext.extend(Ext.Panel, {
  57. <div id="cfg-Ext.form.FormPanel-formId"></div>/**
  58. * @cfg {String} formId (optional) The id of the FORM tag (defaults to an auto-generated id).
  59. */
  60. <div id="cfg-Ext.form.FormPanel-hideLabels"></div>/**
  61. * @cfg {Boolean} hideLabels
  62. * <p><tt>true</tt> to hide field labels by default (sets <tt>display:none</tt>). Defaults to
  63. * <tt>false</tt>.</p>
  64. * <p>Also see {@link Ext.Component}.<tt>{@link Ext.Component#hideLabel hideLabel}</tt>.
  65. */
  66. <div id="cfg-Ext.form.FormPanel-labelPad"></div>/**
  67. * @cfg {Number} labelPad
  68. * The default padding in pixels for field labels (defaults to <tt>5</tt>). <tt>labelPad</tt> only
  69. * applies if <tt>{@link #labelWidth}</tt> is also specified, otherwise it will be ignored.
  70. */
  71. <div id="cfg-Ext.form.FormPanel-labelSeparator"></div>/**
  72. * @cfg {String} labelSeparator
  73. * See {@link Ext.Component}.<tt>{@link Ext.Component#labelSeparator labelSeparator}</tt>
  74. */
  75. <div id="cfg-Ext.form.FormPanel-labelWidth"></div>/**
  76. * @cfg {Number} labelWidth The width of labels in pixels. This property cascades to child containers
  77. * and can be overridden on any child container (e.g., a fieldset can specify a different <tt>labelWidth</tt>
  78. * for its fields) (defaults to <tt>100</tt>).
  79. */
  80. <div id="cfg-Ext.form.FormPanel-itemCls"></div>/**
  81. * @cfg {String} itemCls A css class to apply to the x-form-item of fields. This property cascades to child containers.
  82. */
  83. <div id="cfg-Ext.form.FormPanel-buttons"></div>/**
  84. * @cfg {Array} buttons
  85. * An array of {@link Ext.Button}s or {@link Ext.Button} configs used to add buttons to the footer of this FormPanel.<br>
  86. * <p>Buttons in the footer of a FormPanel may be configured with the option <tt>formBind: true</tt>. This causes
  87. * the form's {@link #monitorValid valid state monitor task} to enable/disable those Buttons depending on
  88. * the form's valid/invalid state.</p>
  89. */
  90. <div id="cfg-Ext.form.FormPanel-minButtonWidth"></div>/**
  91. * @cfg {Number} minButtonWidth Minimum width of all buttons in pixels (defaults to <tt>75</tt>).
  92. */
  93. minButtonWidth : 75,
  94. <div id="cfg-Ext.form.FormPanel-labelAlign"></div>/**
  95. * @cfg {String} labelAlign The label alignment value used for the <tt>text-align</tt> specification
  96. * for the <b>container</b>. Valid values are <tt>"left</tt>", <tt>"top"</tt> or <tt>"right"</tt>
  97. * (defaults to <tt>"left"</tt>). This property cascades to child <b>containers</b> and can be
  98. * overridden on any child <b>container</b> (e.g., a fieldset can specify a different <tt>labelAlign</tt>
  99. * for its fields).
  100. */
  101. labelAlign : 'left',
  102. <div id="cfg-Ext.form.FormPanel-monitorValid"></div>/**
  103. * @cfg {Boolean} monitorValid If <tt>true</tt>, the form monitors its valid state <b>client-side</b> and
  104. * regularly fires the {@link #clientvalidation} event passing that state.<br>
  105. * <p>When monitoring valid state, the FormPanel enables/disables any of its configured
  106. * {@link #buttons} which have been configured with <code>formBind: true</code> depending
  107. * on whether the {@link Ext.form.BasicForm#isValid form is valid} or not. Defaults to <tt>false</tt></p>
  108. */
  109. monitorValid : false,
  110. <div id="cfg-Ext.form.FormPanel-monitorPoll"></div>/**
  111. * @cfg {Number} monitorPoll The milliseconds to poll valid state, ignored if monitorValid is not true (defaults to 200)
  112. */
  113. monitorPoll : 200,
  114. <div id="cfg-Ext.form.FormPanel-layout"></div>/**
  115. * @cfg {String} layout Defaults to <tt>'form'</tt>. Normally this configuration property should not be altered.
  116. * For additional details see {@link Ext.layout.FormLayout} and {@link Ext.Container#layout Ext.Container.layout}.
  117. */
  118. layout : 'form',
  119. // private
  120. initComponent : function(){
  121. this.form = this.createForm();
  122. Ext.FormPanel.superclass.initComponent.call(this);
  123. this.bodyCfg = {
  124. tag: 'form',
  125. cls: this.baseCls + '-body',
  126. method : this.method || 'POST',
  127. id : this.formId || Ext.id()
  128. };
  129. if(this.fileUpload) {
  130. this.bodyCfg.enctype = 'multipart/form-data';
  131. }
  132. this.initItems();
  133. this.addEvents(
  134. <div id="event-Ext.form.FormPanel-clientvalidation"></div>/**
  135. * @event clientvalidation
  136. * If the monitorValid config option is true, this event fires repetitively to notify of valid state
  137. * @param {Ext.form.FormPanel} this
  138. * @param {Boolean} valid true if the form has passed client-side validation
  139. */
  140. 'clientvalidation'
  141. );
  142. this.relayEvents(this.form, ['beforeaction', 'actionfailed', 'actioncomplete']);
  143. },
  144. // private
  145. createForm : function(){
  146. var config = Ext.applyIf({listeners: {}}, this.initialConfig);
  147. return new Ext.form.BasicForm(null, config);
  148. },
  149. // private
  150. initFields : function(){
  151. var f = this.form;
  152. var formPanel = this;
  153. var fn = function(c){
  154. if(formPanel.isField(c)){
  155. f.add(c);
  156. }else if(c.findBy && c != formPanel){
  157. formPanel.applySettings(c);
  158. //each check required for check/radio groups.
  159. if(c.items && c.items.each){
  160. c.items.each(fn, this);
  161. }
  162. }
  163. };
  164. this.items.each(fn, this);
  165. },
  166. // private
  167. applySettings: function(c){
  168. var ct = c.ownerCt;
  169. Ext.applyIf(c, {
  170. labelAlign: ct.labelAlign,
  171. labelWidth: ct.labelWidth,
  172. itemCls: ct.itemCls
  173. });
  174. },
  175. // private
  176. getLayoutTarget : function(){
  177. return this.form.el;
  178. },
  179. <div id="method-Ext.form.FormPanel-getForm"></div>/**
  180. * Provides access to the {@link Ext.form.BasicForm Form} which this Panel contains.
  181. * @return {Ext.form.BasicForm} The {@link Ext.form.BasicForm Form} which this Panel contains.
  182. */
  183. getForm : function(){
  184. return this.form;
  185. },
  186. // private
  187. onRender : function(ct, position){
  188. this.initFields();
  189. Ext.FormPanel.superclass.onRender.call(this, ct, position);
  190. this.form.initEl(this.body);
  191. },
  192. // private
  193. beforeDestroy : function(){
  194. this.stopMonitoring();
  195. this.form.destroy(true);
  196. Ext.FormPanel.superclass.beforeDestroy.call(this);
  197. },
  198. // Determine if a Component is usable as a form Field.
  199. isField : function(c) {
  200. return !!c.setValue && !!c.getValue && !!c.markInvalid && !!c.clearInvalid;
  201. },
  202. // private
  203. initEvents : function(){
  204. Ext.FormPanel.superclass.initEvents.call(this);
  205. // Listeners are required here to catch bubbling events from children.
  206. this.on({
  207. scope: this,
  208. add: this.onAddEvent,
  209. remove: this.onRemoveEvent
  210. });
  211. if(this.monitorValid){ // initialize after render
  212. this.startMonitoring();
  213. }
  214. },
  215. // private
  216. onAdd: function(c){
  217. Ext.FormPanel.superclass.onAdd.call(this, c);
  218. this.processAdd(c);
  219. },
  220. // private
  221. onAddEvent: function(ct, c){
  222. if(ct !== this){
  223. this.processAdd(c);
  224. }
  225. },
  226. // private
  227. processAdd : function(c){
  228. // If a single form Field, add it
  229. if(this.isField(c)){
  230. this.form.add(c);
  231. // If a Container, add any Fields it might contain
  232. }else if(c.findBy){
  233. this.applySettings(c);
  234. this.form.add.apply(this.form, c.findBy(this.isField));
  235. }
  236. },
  237. // private
  238. onRemove: function(c){
  239. Ext.FormPanel.superclass.onRemove.call(this, c);
  240. this.processRemove(c);
  241. },
  242. onRemoveEvent: function(ct, c){
  243. if(ct !== this){
  244. this.processRemove(c);
  245. }
  246. },
  247. // private
  248. processRemove: function(c){
  249. if(!this.destroying){
  250. // If a single form Field, remove it
  251. if(this.isField(c)){
  252. this.form.remove(c);
  253. // If a Container, its already destroyed by the time it gets here. Remove any references to destroyed fields.
  254. }else if (c.findBy){
  255. Ext.each(c.findBy(this.isField), this.form.remove, this.form);
  256. /*
  257. * This isn't the most efficient way of getting rid of the items, however it's the most
  258. * correct, which in this case is most important.
  259. */
  260. this.form.cleanDestroyed();
  261. }
  262. }
  263. },
  264. <div id="method-Ext.form.FormPanel-startMonitoring"></div>/**
  265. * Starts monitoring of the valid state of this form. Usually this is done by passing the config
  266. * option "monitorValid"
  267. */
  268. startMonitoring : function(){
  269. if(!this.validTask){
  270. this.validTask = new Ext.util.TaskRunner();
  271. this.validTask.start({
  272. run : this.bindHandler,
  273. interval : this.monitorPoll || 200,
  274. scope: this
  275. });
  276. }
  277. },
  278. <div id="method-Ext.form.FormPanel-stopMonitoring"></div>/**
  279. * Stops monitoring of the valid state of this form
  280. */
  281. stopMonitoring : function(){
  282. if(this.validTask){
  283. this.validTask.stopAll();
  284. this.validTask = null;
  285. }
  286. },
  287. <div id="method-Ext.form.FormPanel-load"></div>/**
  288. * This is a proxy for the underlying BasicForm's {@link Ext.form.BasicForm#load} call.
  289. * @param {Object} options The options to pass to the action (see {@link Ext.form.BasicForm#doAction} for details)
  290. */
  291. load : function(){
  292. this.form.load.apply(this.form, arguments);
  293. },
  294. // private
  295. onDisable : function(){
  296. Ext.FormPanel.superclass.onDisable.call(this);
  297. if(this.form){
  298. this.form.items.each(function(){
  299. this.disable();
  300. });
  301. }
  302. },
  303. // private
  304. onEnable : function(){
  305. Ext.FormPanel.superclass.onEnable.call(this);
  306. if(this.form){
  307. this.form.items.each(function(){
  308. this.enable();
  309. });
  310. }
  311. },
  312. // private
  313. bindHandler : function(){
  314. var valid = true;
  315. this.form.items.each(function(f){
  316. if(!f.isValid(true)){
  317. valid = false;
  318. return false;
  319. }
  320. });
  321. if(this.fbar){
  322. var fitems = this.fbar.items.items;
  323. for(var i = 0, len = fitems.length; i < len; i++){
  324. var btn = fitems[i];
  325. if(btn.formBind === true && btn.disabled === valid){
  326. btn.setDisabled(!valid);
  327. }
  328. }
  329. }
  330. this.fireEvent('clientvalidation', this, valid);
  331. }
  332. });
  333. Ext.reg('form', Ext.FormPanel);
  334. Ext.form.FormPanel = Ext.FormPanel;
  335. </pre>
  336. </body>
  337. </html>