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.

370 lines
16 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.layout.FormLayout"></div>/**
  16. * @class Ext.layout.FormLayout
  17. * @extends Ext.layout.AnchorLayout
  18. * <p>This layout manager is specifically designed for rendering and managing child Components of
  19. * {@link Ext.form.FormPanel forms}. It is responsible for rendering the labels of
  20. * {@link Ext.form.Field Field}s.</p>
  21. *
  22. * <p>This layout manager is used when a Container is configured with the <tt>layout:'form'</tt>
  23. * {@link Ext.Container#layout layout} config option, and should generally not need to be created directly
  24. * via the new keyword. See <tt><b>{@link Ext.Container#layout}</b></tt> for additional details.</p>
  25. *
  26. * <p>In an application, it will usually be preferrable to use a {@link Ext.form.FormPanel FormPanel}
  27. * (which is configured with FormLayout as its layout class by default) since it also provides built-in
  28. * functionality for {@link Ext.form.BasicForm#doAction loading, validating and submitting} the form.</p>
  29. *
  30. * <p>A {@link Ext.Container Container} <i>using</i> the FormLayout layout manager (e.g.
  31. * {@link Ext.form.FormPanel} or specifying <tt>layout:'form'</tt>) can also accept the following
  32. * layout-specific config properties:<div class="mdetail-params"><ul>
  33. * <li><b><tt>{@link Ext.form.FormPanel#hideLabels hideLabels}</tt></b></li>
  34. * <li><b><tt>{@link Ext.form.FormPanel#labelAlign labelAlign}</tt></b></li>
  35. * <li><b><tt>{@link Ext.form.FormPanel#labelPad labelPad}</tt></b></li>
  36. * <li><b><tt>{@link Ext.form.FormPanel#labelSeparator labelSeparator}</tt></b></li>
  37. * <li><b><tt>{@link Ext.form.FormPanel#labelWidth labelWidth}</tt></b></li>
  38. * </ul></div></p>
  39. *
  40. * <p>Any Component (including Fields) managed by FormLayout accepts the following as a config option:
  41. * <div class="mdetail-params"><ul>
  42. * <li><b><tt>{@link Ext.Component#anchor anchor}</tt></b></li>
  43. * </ul></div></p>
  44. *
  45. * <p>Any Component managed by FormLayout may be rendered as a form field (with an associated label) by
  46. * configuring it with a non-null <b><tt>{@link Ext.Component#fieldLabel fieldLabel}</tt></b>. Components configured
  47. * in this way may be configured with the following options which affect the way the FormLayout renders them:
  48. * <div class="mdetail-params"><ul>
  49. * <li><b><tt>{@link Ext.Component#clearCls clearCls}</tt></b></li>
  50. * <li><b><tt>{@link Ext.Component#fieldLabel fieldLabel}</tt></b></li>
  51. * <li><b><tt>{@link Ext.Component#hideLabel hideLabel}</tt></b></li>
  52. * <li><b><tt>{@link Ext.Component#itemCls itemCls}</tt></b></li>
  53. * <li><b><tt>{@link Ext.Component#labelSeparator labelSeparator}</tt></b></li>
  54. * <li><b><tt>{@link Ext.Component#labelStyle labelStyle}</tt></b></li>
  55. * </ul></div></p>
  56. *
  57. * <p>Example usage:</p>
  58. * <pre><code>
  59. // Required if showing validation messages
  60. Ext.QuickTips.init();
  61. // While you can create a basic Panel with layout:'form', practically
  62. // you should usually use a FormPanel to also get its form functionality
  63. // since it already creates a FormLayout internally.
  64. var form = new Ext.form.FormPanel({
  65. title: 'Form Layout',
  66. bodyStyle: 'padding:15px',
  67. width: 350,
  68. defaultType: 'textfield',
  69. defaults: {
  70. // applied to each contained item
  71. width: 230,
  72. msgTarget: 'side'
  73. },
  74. items: [{
  75. fieldLabel: 'First Name',
  76. name: 'first',
  77. allowBlank: false,
  78. {@link Ext.Component#labelSeparator labelSeparator}: ':' // override labelSeparator layout config
  79. },{
  80. fieldLabel: 'Last Name',
  81. name: 'last'
  82. },{
  83. fieldLabel: 'Email',
  84. name: 'email',
  85. vtype:'email'
  86. }, {
  87. xtype: 'textarea',
  88. hideLabel: true, // override hideLabels layout config
  89. name: 'msg',
  90. anchor: '100% -53'
  91. }
  92. ],
  93. buttons: [
  94. {text: 'Save'},
  95. {text: 'Cancel'}
  96. ],
  97. layoutConfig: {
  98. {@link #labelSeparator}: '~' // superseded by assignment below
  99. },
  100. // config options applicable to container when layout='form':
  101. hideLabels: false,
  102. labelAlign: 'left', // or 'right' or 'top'
  103. {@link Ext.form.FormPanel#labelSeparator labelSeparator}: '>>', // takes precedence over layoutConfig value
  104. labelWidth: 65, // defaults to 100
  105. labelPad: 8 // defaults to 5, must specify labelWidth to be honored
  106. });
  107. </code></pre>
  108. */
  109. Ext.layout.FormLayout = Ext.extend(Ext.layout.AnchorLayout, {
  110. <div id="cfg-Ext.layout.FormLayout-labelSeparator"></div>/**
  111. * @cfg {String} labelSeparator
  112. * See {@link Ext.form.FormPanel}.{@link Ext.form.FormPanel#labelSeparator labelSeparator}. Configuration
  113. * of this property at the <b>container</b> level takes precedence.
  114. */
  115. labelSeparator : ':',
  116. <div id="prop-Ext.layout.FormLayout-labelStyle"></div>/**
  117. * Read only. The CSS style specification string added to field labels in this layout if not
  118. * otherwise {@link Ext.Component#labelStyle specified by each contained field}.
  119. * @type String
  120. * @property labelStyle
  121. */
  122. <div id="cfg-Ext.layout.FormLayout-trackLabels"></div>/**
  123. * @cfg {Boolean} trackLabels
  124. * True to show/hide the field label when the field is hidden. Defaults to <tt>true</tt>.
  125. */
  126. trackLabels: true,
  127. type: 'form',
  128. onRemove: function(c){
  129. Ext.layout.FormLayout.superclass.onRemove.call(this, c);
  130. if(this.trackLabels){
  131. c.un('show', this.onFieldShow, this);
  132. c.un('hide', this.onFieldHide, this);
  133. }
  134. // check for itemCt, since we may be removing a fieldset or something similar
  135. var el = c.getPositionEl(),
  136. ct = c.getItemCt && c.getItemCt();
  137. if (c.rendered && ct) {
  138. if (el && el.dom) {
  139. el.insertAfter(ct);
  140. }
  141. Ext.destroy(ct);
  142. Ext.destroyMembers(c, 'label', 'itemCt');
  143. if (c.customItemCt) {
  144. Ext.destroyMembers(c, 'getItemCt', 'customItemCt');
  145. }
  146. }
  147. },
  148. // private
  149. setContainer : function(ct){
  150. Ext.layout.FormLayout.superclass.setContainer.call(this, ct);
  151. if(ct.labelAlign){
  152. ct.addClass('x-form-label-'+ct.labelAlign);
  153. }
  154. if(ct.hideLabels){
  155. Ext.apply(this, {
  156. labelStyle: 'display:none',
  157. elementStyle: 'padding-left:0;',
  158. labelAdjust: 0
  159. });
  160. }else{
  161. this.labelSeparator = Ext.isDefined(ct.labelSeparator) ? ct.labelSeparator : this.labelSeparator;
  162. ct.labelWidth = ct.labelWidth || 100;
  163. if(Ext.isNumber(ct.labelWidth)){
  164. var pad = Ext.isNumber(ct.labelPad) ? ct.labelPad : 5;
  165. Ext.apply(this, {
  166. labelAdjust: ct.labelWidth + pad,
  167. labelStyle: 'width:' + ct.labelWidth + 'px;',
  168. elementStyle: 'padding-left:' + (ct.labelWidth + pad) + 'px'
  169. });
  170. }
  171. if(ct.labelAlign == 'top'){
  172. Ext.apply(this, {
  173. labelStyle: 'width:auto;',
  174. labelAdjust: 0,
  175. elementStyle: 'padding-left:0;'
  176. });
  177. }
  178. }
  179. },
  180. // private
  181. isHide: function(c){
  182. return c.hideLabel || this.container.hideLabels;
  183. },
  184. onFieldShow: function(c){
  185. c.getItemCt().removeClass('x-hide-' + c.hideMode);
  186. // Composite fields will need to layout after the container is made visible
  187. if (c.isComposite) {
  188. c.doLayout();
  189. }
  190. },
  191. onFieldHide: function(c){
  192. c.getItemCt().addClass('x-hide-' + c.hideMode);
  193. },
  194. //private
  195. getLabelStyle: function(s){
  196. var ls = '', items = [this.labelStyle, s];
  197. for (var i = 0, len = items.length; i < len; ++i){
  198. if (items[i]){
  199. ls += items[i];
  200. if (ls.substr(-1, 1) != ';'){
  201. ls += ';';
  202. }
  203. }
  204. }
  205. return ls;
  206. },
  207. <div id="cfg-Ext.layout.FormLayout-fieldTpl"></div>/**
  208. * @cfg {Ext.Template} fieldTpl
  209. * A {@link Ext.Template#compile compile}d {@link Ext.Template} for rendering
  210. * the fully wrapped, labeled and styled form Field. Defaults to:</p><pre><code>
  211. new Ext.Template(
  212. &#39;&lt;div class="x-form-item {itemCls}" tabIndex="-1">&#39;,
  213. &#39;&lt;&#108;abel for="{id}" style="{labelStyle}" class="x-form-item-&#108;abel">{&#108;abel}{labelSeparator}&lt;/&#108;abel>&#39;,
  214. &#39;&lt;div class="x-form-element" id="x-form-el-{id}" style="{elementStyle}">&#39;,
  215. &#39;&lt;/div>&lt;div class="{clearCls}">&lt;/div>&#39;,
  216. '&lt;/div>'
  217. );
  218. </code></pre>
  219. * <p>This may be specified to produce a different DOM structure when rendering form Fields.</p>
  220. * <p>A description of the properties within the template follows:</p><div class="mdetail-params"><ul>
  221. * <li><b><tt>itemCls</tt></b> : String<div class="sub-desc">The CSS class applied to the outermost div wrapper
  222. * that contains this field label and field element (the default class is <tt>'x-form-item'</tt> and <tt>itemCls</tt>
  223. * will be added to that). If supplied, <tt>itemCls</tt> at the field level will override the default <tt>itemCls</tt>
  224. * supplied at the container level.</div></li>
  225. * <li><b><tt>id</tt></b> : String<div class="sub-desc">The id of the Field</div></li>
  226. * <li><b><tt>{@link #labelStyle}</tt></b> : String<div class="sub-desc">
  227. * A CSS style specification string to add to the field label for this field (defaults to <tt>''</tt> or the
  228. * {@link #labelStyle layout's value for <tt>labelStyle</tt>}).</div></li>
  229. * <li><b><tt>label</tt></b> : String<div class="sub-desc">The text to display as the label for this
  230. * field (defaults to <tt>''</tt>)</div></li>
  231. * <li><b><tt>{@link #labelSeparator}</tt></b> : String<div class="sub-desc">The separator to display after
  232. * the text of the label for this field (defaults to a colon <tt>':'</tt> or the
  233. * {@link #labelSeparator layout's value for labelSeparator}). To hide the separator use empty string ''.</div></li>
  234. * <li><b><tt>elementStyle</tt></b> : String<div class="sub-desc">The styles text for the input element's wrapper.</div></li>
  235. * <li><b><tt>clearCls</tt></b> : String<div class="sub-desc">The CSS class to apply to the special clearing div
  236. * rendered directly after each form field wrapper (defaults to <tt>'x-form-clear-left'</tt>)</div></li>
  237. * </ul></div>
  238. * <p>Also see <tt>{@link #getTemplateArgs}</tt></p>
  239. */
  240. /**
  241. * @private
  242. *
  243. */
  244. renderItem : function(c, position, target){
  245. if(c && (c.isFormField || c.fieldLabel) && c.inputType != 'hidden'){
  246. var args = this.getTemplateArgs(c);
  247. if(Ext.isNumber(position)){
  248. position = target.dom.childNodes[position] || null;
  249. }
  250. if(position){
  251. c.itemCt = this.fieldTpl.insertBefore(position, args, true);
  252. }else{
  253. c.itemCt = this.fieldTpl.append(target, args, true);
  254. }
  255. if(!c.getItemCt){
  256. // Non form fields don't have getItemCt, apply it here
  257. // This will get cleaned up in onRemove
  258. Ext.apply(c, {
  259. getItemCt: function(){
  260. return c.itemCt;
  261. },
  262. customItemCt: true
  263. });
  264. }
  265. c.label = c.getItemCt().child('label.x-form-item-label');
  266. if(!c.rendered){
  267. c.render('x-form-el-' + c.id);
  268. }else if(!this.isValidParent(c, target)){
  269. Ext.fly('x-form-el-' + c.id).appendChild(c.getPositionEl());
  270. }
  271. if(this.trackLabels){
  272. if(c.hidden){
  273. this.onFieldHide(c);
  274. }
  275. c.on({
  276. scope: this,
  277. show: this.onFieldShow,
  278. hide: this.onFieldHide
  279. });
  280. }
  281. this.configureItem(c);
  282. }else {
  283. Ext.layout.FormLayout.superclass.renderItem.apply(this, arguments);
  284. }
  285. },
  286. <div id="method-Ext.layout.FormLayout-getTemplateArgs"></div>/**
  287. * <p>Provides template arguments for rendering the fully wrapped, labeled and styled form Field.</p>
  288. * <p>This method returns an object hash containing properties used by the layout's {@link #fieldTpl}
  289. * to create a correctly wrapped, labeled and styled form Field. This may be overriden to
  290. * create custom layouts. The properties which must be returned are:</p><div class="mdetail-params"><ul>
  291. * <li><b><tt>itemCls</tt></b> : String<div class="sub-desc">The CSS class applied to the outermost div wrapper
  292. * that contains this field label and field element (the default class is <tt>'x-form-item'</tt> and <tt>itemCls</tt>
  293. * will be added to that). If supplied, <tt>itemCls</tt> at the field level will override the default <tt>itemCls</tt>
  294. * supplied at the container level.</div></li>
  295. * <li><b><tt>id</tt></b> : String<div class="sub-desc">The id of the Field</div></li>
  296. * <li><b><tt>{@link #labelStyle}</tt></b> : String<div class="sub-desc">
  297. * A CSS style specification string to add to the field label for this field (defaults to <tt>''</tt> or the
  298. * {@link #labelStyle layout's value for <tt>labelStyle</tt>}).</div></li>
  299. * <li><b><tt>label</tt></b> : String<div class="sub-desc">The text to display as the label for this
  300. * field (defaults to the field's configured fieldLabel property)</div></li>
  301. * <li><b><tt>{@link #labelSeparator}</tt></b> : String<div class="sub-desc">The separator to display after
  302. * the text of the label for this field (defaults to a colon <tt>':'</tt> or the
  303. * {@link #labelSeparator layout's value for labelSeparator}). To hide the separator use empty string ''.</div></li>
  304. * <li><b><tt>elementStyle</tt></b> : String<div class="sub-desc">The styles text for the input element's wrapper.</div></li>
  305. * <li><b><tt>clearCls</tt></b> : String<div class="sub-desc">The CSS class to apply to the special clearing div
  306. * rendered directly after each form field wrapper (defaults to <tt>'x-form-clear-left'</tt>)</div></li>
  307. * </ul></div>
  308. * @param (Ext.form.Field} field The {@link Ext.form.Field Field} being rendered.
  309. * @return {Object} An object hash containing the properties required to render the Field.
  310. */
  311. getTemplateArgs: function(field) {
  312. var noLabelSep = !field.fieldLabel || field.hideLabel;
  313. return {
  314. id : field.id,
  315. label : field.fieldLabel,
  316. itemCls : (field.itemCls || this.container.itemCls || '') + (field.hideLabel ? ' x-hide-label' : ''),
  317. clearCls : field.clearCls || 'x-form-clear-left',
  318. labelStyle : this.getLabelStyle(field.labelStyle),
  319. elementStyle : this.elementStyle || '',
  320. labelSeparator: noLabelSep ? '' : (Ext.isDefined(field.labelSeparator) ? field.labelSeparator : this.labelSeparator)
  321. };
  322. },
  323. // private
  324. adjustWidthAnchor: function(value, c){
  325. if(c.label && !this.isHide(c) && (this.container.labelAlign != 'top')){
  326. var adjust = Ext.isIE6 || (Ext.isIE && !Ext.isStrict);
  327. return value - this.labelAdjust + (adjust ? -3 : 0);
  328. }
  329. return value;
  330. },
  331. adjustHeightAnchor : function(value, c){
  332. if(c.label && !this.isHide(c) && (this.container.labelAlign == 'top')){
  333. return value - c.label.getHeight();
  334. }
  335. return value;
  336. },
  337. // private
  338. isValidParent : function(c, target){
  339. return target && this.container.getEl().contains(c.getPositionEl());
  340. }
  341. <div id="prop-Ext.layout.FormLayout-activeItem"></div>/**
  342. * @property activeItem
  343. * @hide
  344. */
  345. });
  346. Ext.Container.LAYOUTS['form'] = Ext.layout.FormLayout;
  347. </pre>
  348. </body>
  349. </html>