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.

421 lines
19 KiB

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