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.

417 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.form.TriggerField"></div>/**
  16. * @class Ext.form.TriggerField
  17. * @extends Ext.form.TextField
  18. * Provides a convenient wrapper for TextFields that adds a clickable trigger button (looks like a combobox by default).
  19. * The trigger has no default action, so you must assign a function to implement the trigger click handler by
  20. * overriding {@link #onTriggerClick}. You can create a TriggerField directly, as it renders exactly like a combobox
  21. * for which you can provide a custom implementation. For example:
  22. * <pre><code>
  23. var trigger = new Ext.form.TriggerField();
  24. trigger.onTriggerClick = myTriggerFn;
  25. trigger.applyToMarkup('my-field');
  26. </code></pre>
  27. *
  28. * However, in general you will most likely want to use TriggerField as the base class for a reusable component.
  29. * {@link Ext.form.DateField} and {@link Ext.form.ComboBox} are perfect examples of this.
  30. *
  31. * @constructor
  32. * Create a new TriggerField.
  33. * @param {Object} config Configuration options (valid {@Ext.form.TextField} config options will also be applied
  34. * to the base TextField)
  35. * @xtype trigger
  36. */
  37. Ext.form.TriggerField = Ext.extend(Ext.form.TextField, {
  38. <div id="cfg-Ext.form.TriggerField-triggerClass"></div>/**
  39. * @cfg {String} triggerClass
  40. * An additional CSS class used to style the trigger button. The trigger will always get the
  41. * class <tt>'x-form-trigger'</tt> by default and <tt>triggerClass</tt> will be <b>appended</b> if specified.
  42. */
  43. <div id="cfg-Ext.form.TriggerField-triggerConfig"></div>/**
  44. * @cfg {Mixed} triggerConfig
  45. * <p>A {@link Ext.DomHelper DomHelper} config object specifying the structure of the
  46. * trigger element for this Field. (Optional).</p>
  47. * <p>Specify this when you need a customized element to act as the trigger button for a TriggerField.</p>
  48. * <p>Note that when using this option, it is the developer's responsibility to ensure correct sizing, positioning
  49. * and appearance of the trigger. Defaults to:</p>
  50. * <pre><code>{tag: "img", src: Ext.BLANK_IMAGE_URL, cls: "x-form-trigger " + this.triggerClass}</code></pre>
  51. */
  52. <div id="cfg-Ext.form.TriggerField-autoCreate"></div>/**
  53. * @cfg {String/Object} autoCreate <p>A {@link Ext.DomHelper DomHelper} element spec, or true for a default
  54. * element spec. Used to create the {@link Ext.Component#getEl Element} which will encapsulate this Component.
  55. * See <tt>{@link Ext.Component#autoEl autoEl}</tt> for details. Defaults to:</p>
  56. * <pre><code>{tag: "input", type: "text", size: "16", autocomplete: "off"}</code></pre>
  57. */
  58. defaultAutoCreate : {tag: "input", type: "text", size: "16", autocomplete: "off"},
  59. <div id="cfg-Ext.form.TriggerField-hideTrigger"></div>/**
  60. * @cfg {Boolean} hideTrigger <tt>true</tt> to hide the trigger element and display only the base
  61. * text field (defaults to <tt>false</tt>)
  62. */
  63. hideTrigger:false,
  64. <div id="cfg-Ext.form.TriggerField-editable"></div>/**
  65. * @cfg {Boolean} editable <tt>false</tt> to prevent the user from typing text directly into the field,
  66. * the field will only respond to a click on the trigger to set the value. (defaults to <tt>true</tt>).
  67. */
  68. editable: true,
  69. <div id="cfg-Ext.form.TriggerField-readOnly"></div>/**
  70. * @cfg {Boolean} readOnly <tt>true</tt> to prevent the user from changing the field, and
  71. * hides the trigger. Superceeds the editable and hideTrigger options if the value is true.
  72. * (defaults to <tt>false</tt>)
  73. */
  74. readOnly: false,
  75. <div id="cfg-Ext.form.TriggerField-wrapFocusClass"></div>/**
  76. * @cfg {String} wrapFocusClass The class added to the to the wrap of the trigger element. Defaults to
  77. * <tt>x-trigger-wrap-focus</tt>.
  78. */
  79. wrapFocusClass: 'x-trigger-wrap-focus',
  80. <div id="method-Ext.form.TriggerField-autoSize"></div>/**
  81. * @hide
  82. * @method autoSize
  83. */
  84. autoSize: Ext.emptyFn,
  85. // private
  86. monitorTab : true,
  87. // private
  88. deferHeight : true,
  89. // private
  90. mimicing : false,
  91. actionMode: 'wrap',
  92. defaultTriggerWidth: 17,
  93. // private
  94. onResize : function(w, h){
  95. Ext.form.TriggerField.superclass.onResize.call(this, w, h);
  96. var tw = this.getTriggerWidth();
  97. if(Ext.isNumber(w)){
  98. this.el.setWidth(w - tw);
  99. }
  100. this.wrap.setWidth(this.el.getWidth() + tw);
  101. },
  102. getTriggerWidth: function(){
  103. var tw = this.trigger.getWidth();
  104. if(!this.hideTrigger && !this.readOnly && tw === 0){
  105. tw = this.defaultTriggerWidth;
  106. }
  107. return tw;
  108. },
  109. // private
  110. alignErrorIcon : function(){
  111. if(this.wrap){
  112. this.errorIcon.alignTo(this.wrap, 'tl-tr', [2, 0]);
  113. }
  114. },
  115. // private
  116. onRender : function(ct, position){
  117. this.doc = Ext.isIE ? Ext.getBody() : Ext.getDoc();
  118. Ext.form.TriggerField.superclass.onRender.call(this, ct, position);
  119. this.wrap = this.el.wrap({cls: 'x-form-field-wrap x-form-field-trigger-wrap'});
  120. this.trigger = this.wrap.createChild(this.triggerConfig ||
  121. {tag: "img", src: Ext.BLANK_IMAGE_URL, alt: "", cls: "x-form-trigger " + this.triggerClass});
  122. this.initTrigger();
  123. if(!this.width){
  124. this.wrap.setWidth(this.el.getWidth()+this.trigger.getWidth());
  125. }
  126. this.resizeEl = this.positionEl = this.wrap;
  127. },
  128. getWidth: function() {
  129. return(this.el.getWidth() + this.trigger.getWidth());
  130. },
  131. updateEditState: function(){
  132. if(this.rendered){
  133. if (this.readOnly) {
  134. this.el.dom.readOnly = true;
  135. this.el.addClass('x-trigger-noedit');
  136. this.mun(this.el, 'click', this.onTriggerClick, this);
  137. this.trigger.setDisplayed(false);
  138. } else {
  139. if (!this.editable) {
  140. this.el.dom.readOnly = true;
  141. this.el.addClass('x-trigger-noedit');
  142. this.mon(this.el, 'click', this.onTriggerClick, this);
  143. } else {
  144. this.el.dom.readOnly = false;
  145. this.el.removeClass('x-trigger-noedit');
  146. this.mun(this.el, 'click', this.onTriggerClick, this);
  147. }
  148. this.trigger.setDisplayed(!this.hideTrigger);
  149. }
  150. this.onResize(this.width || this.wrap.getWidth());
  151. }
  152. },
  153. <div id="method-Ext.form.TriggerField-setHideTrigger"></div>/**
  154. * Changes the hidden status of the trigger.
  155. * @param {Boolean} hideTrigger True to hide the trigger, false to show it.
  156. */
  157. setHideTrigger: function(hideTrigger){
  158. if(hideTrigger != this.hideTrigger){
  159. this.hideTrigger = hideTrigger;
  160. this.updateEditState();
  161. }
  162. },
  163. <div id="method-Ext.form.TriggerField-setEditable"></div>/**
  164. * Allow or prevent the user from directly editing the field text. If false is passed,
  165. * the user will only be able to modify the field using the trigger. Will also add
  166. * a click event to the text field which will call the trigger. This method
  167. * is the runtime equivalent of setting the {@link #editable} config option at config time.
  168. * @param {Boolean} value True to allow the user to directly edit the field text.
  169. */
  170. setEditable: function(editable){
  171. if(editable != this.editable){
  172. this.editable = editable;
  173. this.updateEditState();
  174. }
  175. },
  176. <div id="method-Ext.form.TriggerField-setReadOnly"></div>/**
  177. * Setting this to true will supersede settings {@link #editable} and {@link #hideTrigger}.
  178. * Setting this to false will defer back to {@link #editable} and {@link #hideTrigger}. This method
  179. * is the runtime equivalent of setting the {@link #readOnly} config option at config time.
  180. * @param {Boolean} value True to prevent the user changing the field and explicitly
  181. * hide the trigger.
  182. */
  183. setReadOnly: function(readOnly){
  184. if(readOnly != this.readOnly){
  185. this.readOnly = readOnly;
  186. this.updateEditState();
  187. }
  188. },
  189. afterRender : function(){
  190. Ext.form.TriggerField.superclass.afterRender.call(this);
  191. this.updateEditState();
  192. },
  193. // private
  194. initTrigger : function(){
  195. this.mon(this.trigger, 'click', this.onTriggerClick, this, {preventDefault:true});
  196. this.trigger.addClassOnOver('x-form-trigger-over');
  197. this.trigger.addClassOnClick('x-form-trigger-click');
  198. },
  199. // private
  200. onDestroy : function(){
  201. Ext.destroy(this.trigger, this.wrap);
  202. if (this.mimicing){
  203. this.doc.un('mousedown', this.mimicBlur, this);
  204. }
  205. delete this.doc;
  206. Ext.form.TriggerField.superclass.onDestroy.call(this);
  207. },
  208. // private
  209. onFocus : function(){
  210. Ext.form.TriggerField.superclass.onFocus.call(this);
  211. if(!this.mimicing){
  212. this.wrap.addClass(this.wrapFocusClass);
  213. this.mimicing = true;
  214. this.doc.on('mousedown', this.mimicBlur, this, {delay: 10});
  215. if(this.monitorTab){
  216. this.on('specialkey', this.checkTab, this);
  217. }
  218. }
  219. },
  220. // private
  221. checkTab : function(me, e){
  222. if(e.getKey() == e.TAB){
  223. this.triggerBlur();
  224. }
  225. },
  226. // private
  227. onBlur : Ext.emptyFn,
  228. // private
  229. mimicBlur : function(e){
  230. if(!this.isDestroyed && !this.wrap.contains(e.target) && this.validateBlur(e)){
  231. this.triggerBlur();
  232. }
  233. },
  234. // private
  235. triggerBlur : function(){
  236. this.mimicing = false;
  237. this.doc.un('mousedown', this.mimicBlur, this);
  238. if(this.monitorTab && this.el){
  239. this.un('specialkey', this.checkTab, this);
  240. }
  241. Ext.form.TriggerField.superclass.onBlur.call(this);
  242. if(this.wrap){
  243. this.wrap.removeClass(this.wrapFocusClass);
  244. }
  245. },
  246. beforeBlur : Ext.emptyFn,
  247. // private
  248. // This should be overriden by any subclass that needs to check whether or not the field can be blurred.
  249. validateBlur : function(e){
  250. return true;
  251. },
  252. <div id="method-Ext.form.TriggerField-onTriggerClick"></div>/**
  253. * The function that should handle the trigger's click event. This method does nothing by default
  254. * until overridden by an implementing function. See Ext.form.ComboBox and Ext.form.DateField for
  255. * sample implementations.
  256. * @method
  257. * @param {EventObject} e
  258. */
  259. onTriggerClick : Ext.emptyFn
  260. <div id="cfg-Ext.form.TriggerField-grow"></div>/**
  261. * @cfg {Boolean} grow @hide
  262. */
  263. <div id="cfg-Ext.form.TriggerField-growMin"></div>/**
  264. * @cfg {Number} growMin @hide
  265. */
  266. <div id="cfg-Ext.form.TriggerField-growMax"></div>/**
  267. * @cfg {Number} growMax @hide
  268. */
  269. });
  270. <div id="cls-Ext.form.TwinTriggerField"></div>/**
  271. * @class Ext.form.TwinTriggerField
  272. * @extends Ext.form.TriggerField
  273. * TwinTriggerField is not a public class to be used directly. It is meant as an abstract base class
  274. * to be extended by an implementing class. For an example of implementing this class, see the custom
  275. * SearchField implementation here:
  276. * <a href="http://extjs.com/deploy/ext/examples/form/custom.html">http://extjs.com/deploy/ext/examples/form/custom.html</a>
  277. */
  278. Ext.form.TwinTriggerField = Ext.extend(Ext.form.TriggerField, {
  279. <div id="cfg-Ext.form.TwinTriggerField-triggerConfig"></div>/**
  280. * @cfg {Mixed} triggerConfig
  281. * <p>A {@link Ext.DomHelper DomHelper} config object specifying the structure of the trigger elements
  282. * for this Field. (Optional).</p>
  283. * <p>Specify this when you need a customized element to contain the two trigger elements for this Field.
  284. * Each trigger element must be marked by the CSS class <tt>x-form-trigger</tt> (also see
  285. * <tt>{@link #trigger1Class}</tt> and <tt>{@link #trigger2Class}</tt>).</p>
  286. * <p>Note that when using this option, it is the developer's responsibility to ensure correct sizing,
  287. * positioning and appearance of the triggers.</p>
  288. */
  289. <div id="cfg-Ext.form.TwinTriggerField-trigger1Class"></div>/**
  290. * @cfg {String} trigger1Class
  291. * An additional CSS class used to style the trigger button. The trigger will always get the
  292. * class <tt>'x-form-trigger'</tt> by default and <tt>triggerClass</tt> will be <b>appended</b> if specified.
  293. */
  294. <div id="cfg-Ext.form.TwinTriggerField-trigger2Class"></div>/**
  295. * @cfg {String} trigger2Class
  296. * An additional CSS class used to style the trigger button. The trigger will always get the
  297. * class <tt>'x-form-trigger'</tt> by default and <tt>triggerClass</tt> will be <b>appended</b> if specified.
  298. */
  299. initComponent : function(){
  300. Ext.form.TwinTriggerField.superclass.initComponent.call(this);
  301. this.triggerConfig = {
  302. tag:'span', cls:'x-form-twin-triggers', cn:[
  303. {tag: "img", src: Ext.BLANK_IMAGE_URL, alt: "", cls: "x-form-trigger " + this.trigger1Class},
  304. {tag: "img", src: Ext.BLANK_IMAGE_URL, alt: "", cls: "x-form-trigger " + this.trigger2Class}
  305. ]};
  306. },
  307. getTrigger : function(index){
  308. return this.triggers[index];
  309. },
  310. afterRender: function(){
  311. Ext.form.TwinTriggerField.superclass.afterRender.call(this);
  312. var triggers = this.triggers,
  313. i = 0,
  314. len = triggers.length;
  315. for(; i < len; ++i){
  316. if(this['hideTrigger' + (i + 1)]){
  317. triggers[i].hide();
  318. }
  319. }
  320. },
  321. initTrigger : function(){
  322. var ts = this.trigger.select('.x-form-trigger', true),
  323. triggerField = this;
  324. ts.each(function(t, all, index){
  325. var triggerIndex = 'Trigger'+(index+1);
  326. t.hide = function(){
  327. var w = triggerField.wrap.getWidth();
  328. this.dom.style.display = 'none';
  329. triggerField.el.setWidth(w-triggerField.trigger.getWidth());
  330. triggerField['hidden' + triggerIndex] = true;
  331. };
  332. t.show = function(){
  333. var w = triggerField.wrap.getWidth();
  334. this.dom.style.display = '';
  335. triggerField.el.setWidth(w-triggerField.trigger.getWidth());
  336. triggerField['hidden' + triggerIndex] = false;
  337. };
  338. this.mon(t, 'click', this['on'+triggerIndex+'Click'], this, {preventDefault:true});
  339. t.addClassOnOver('x-form-trigger-over');
  340. t.addClassOnClick('x-form-trigger-click');
  341. }, this);
  342. this.triggers = ts.elements;
  343. },
  344. getTriggerWidth: function(){
  345. var tw = 0;
  346. Ext.each(this.triggers, function(t, index){
  347. var triggerIndex = 'Trigger' + (index + 1),
  348. w = t.getWidth();
  349. if(w === 0 && !this['hidden' + triggerIndex]){
  350. tw += this.defaultTriggerWidth;
  351. }else{
  352. tw += w;
  353. }
  354. }, this);
  355. return tw;
  356. },
  357. // private
  358. onDestroy : function() {
  359. Ext.destroy(this.triggers);
  360. Ext.form.TwinTriggerField.superclass.onDestroy.call(this);
  361. },
  362. <div id="method-Ext.form.TwinTriggerField-onTrigger1Click"></div>/**
  363. * The function that should handle the trigger's click event. This method does nothing by default
  364. * until overridden by an implementing function. See {@link Ext.form.TriggerField#onTriggerClick}
  365. * for additional information.
  366. * @method
  367. * @param {EventObject} e
  368. */
  369. onTrigger1Click : Ext.emptyFn,
  370. <div id="method-Ext.form.TwinTriggerField-onTrigger2Click"></div>/**
  371. * The function that should handle the trigger's click event. This method does nothing by default
  372. * until overridden by an implementing function. See {@link Ext.form.TriggerField#onTriggerClick}
  373. * for additional information.
  374. * @method
  375. * @param {EventObject} e
  376. */
  377. onTrigger2Click : Ext.emptyFn
  378. });
  379. Ext.reg('trigger', Ext.form.TriggerField);
  380. </pre>
  381. </body>
  382. </html>