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.

214 lines
5.9 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. Ext.ns('Ext.ux.form');
  16. <div id="cls-Ext.ux.form.SelectBox"></div>/**
  17. * @class Ext.ux.form.SelectBox
  18. * @extends Ext.form.ComboBox
  19. * <p>Makes a ComboBox more closely mimic an HTML SELECT. Supports clicking and dragging
  20. * through the list, with item selection occurring when the mouse button is released.
  21. * When used will automatically set {@link #editable} to false and call {@link Ext.Element#unselectable}
  22. * on inner elements. Re-enabling editable after calling this will NOT work.</p>
  23. * @author Corey Gilmore http://extjs.com/forum/showthread.php?t=6392
  24. * @history 2007-07-08 jvs
  25. * Slight mods for Ext 2.0
  26. * @xtype selectbox
  27. */
  28. Ext.ux.form.SelectBox = Ext.extend(Ext.form.ComboBox, {
  29. constructor: function(config){
  30. this.searchResetDelay = 1000;
  31. config = config || {};
  32. config = Ext.apply(config || {}, {
  33. editable: false,
  34. forceSelection: true,
  35. rowHeight: false,
  36. lastSearchTerm: false,
  37. triggerAction: 'all',
  38. mode: 'local'
  39. });
  40. Ext.ux.form.SelectBox.superclass.constructor.apply(this, arguments);
  41. this.lastSelectedIndex = this.selectedIndex || 0;
  42. },
  43. initEvents : function(){
  44. Ext.ux.form.SelectBox.superclass.initEvents.apply(this, arguments);
  45. // you need to use keypress to capture upper/lower case and shift+key, but it doesn't work in IE
  46. this.el.on('keydown', this.keySearch, this, true);
  47. this.cshTask = new Ext.util.DelayedTask(this.clearSearchHistory, this);
  48. },
  49. keySearch : function(e, target, options) {
  50. var raw = e.getKey();
  51. var key = String.fromCharCode(raw);
  52. var startIndex = 0;
  53. if( !this.store.getCount() ) {
  54. return;
  55. }
  56. switch(raw) {
  57. case Ext.EventObject.HOME:
  58. e.stopEvent();
  59. this.selectFirst();
  60. return;
  61. case Ext.EventObject.END:
  62. e.stopEvent();
  63. this.selectLast();
  64. return;
  65. case Ext.EventObject.PAGEDOWN:
  66. this.selectNextPage();
  67. e.stopEvent();
  68. return;
  69. case Ext.EventObject.PAGEUP:
  70. this.selectPrevPage();
  71. e.stopEvent();
  72. return;
  73. }
  74. // skip special keys other than the shift key
  75. if( (e.hasModifier() && !e.shiftKey) || e.isNavKeyPress() || e.isSpecialKey() ) {
  76. return;
  77. }
  78. if( this.lastSearchTerm == key ) {
  79. startIndex = this.lastSelectedIndex;
  80. }
  81. this.search(this.displayField, key, startIndex);
  82. this.cshTask.delay(this.searchResetDelay);
  83. },
  84. onRender : function(ct, position) {
  85. this.store.on('load', this.calcRowsPerPage, this);
  86. Ext.ux.form.SelectBox.superclass.onRender.apply(this, arguments);
  87. if( this.mode == 'local' ) {
  88. this.initList();
  89. this.calcRowsPerPage();
  90. }
  91. },
  92. onSelect : function(record, index, skipCollapse){
  93. if(this.fireEvent('beforeselect', this, record, index) !== false){
  94. this.setValue(record.data[this.valueField || this.displayField]);
  95. if( !skipCollapse ) {
  96. this.collapse();
  97. }
  98. this.lastSelectedIndex = index + 1;
  99. this.fireEvent('select', this, record, index);
  100. }
  101. },
  102. afterRender : function() {
  103. Ext.ux.form.SelectBox.superclass.afterRender.apply(this, arguments);
  104. if(Ext.isWebKit) {
  105. this.el.swallowEvent('mousedown', true);
  106. }
  107. this.el.unselectable();
  108. this.innerList.unselectable();
  109. this.trigger.unselectable();
  110. this.innerList.on('mouseup', function(e, target, options) {
  111. if( target.id && target.id == this.innerList.id ) {
  112. return;
  113. }
  114. this.onViewClick();
  115. }, this);
  116. this.innerList.on('mouseover', function(e, target, options) {
  117. if( target.id && target.id == this.innerList.id ) {
  118. return;
  119. }
  120. this.lastSelectedIndex = this.view.getSelectedIndexes()[0] + 1;
  121. this.cshTask.delay(this.searchResetDelay);
  122. }, this);
  123. this.trigger.un('click', this.onTriggerClick, this);
  124. this.trigger.on('mousedown', function(e, target, options) {
  125. e.preventDefault();
  126. this.onTriggerClick();
  127. }, this);
  128. this.on('collapse', function(e, target, options) {
  129. Ext.getDoc().un('mouseup', this.collapseIf, this);
  130. }, this, true);
  131. this.on('expand', function(e, target, options) {
  132. Ext.getDoc().on('mouseup', this.collapseIf, this);
  133. }, this, true);
  134. },
  135. clearSearchHistory : function() {
  136. this.lastSelectedIndex = 0;
  137. this.lastSearchTerm = false;
  138. },
  139. selectFirst : function() {
  140. this.focusAndSelect(this.store.data.first());
  141. },
  142. selectLast : function() {
  143. this.focusAndSelect(this.store.data.last());
  144. },
  145. selectPrevPage : function() {
  146. if( !this.rowHeight ) {
  147. return;
  148. }
  149. var index = Math.max(this.selectedIndex-this.rowsPerPage, 0);
  150. this.focusAndSelect(this.store.getAt(index));
  151. },
  152. selectNextPage : function() {
  153. if( !this.rowHeight ) {
  154. return;
  155. }
  156. var index = Math.min(this.selectedIndex+this.rowsPerPage, this.store.getCount() - 1);
  157. this.focusAndSelect(this.store.getAt(index));
  158. },
  159. search : function(field, value, startIndex) {
  160. field = field || this.displayField;
  161. this.lastSearchTerm = value;
  162. var index = this.store.find.apply(this.store, arguments);
  163. if( index !== -1 ) {
  164. this.focusAndSelect(index);
  165. }
  166. },
  167. focusAndSelect : function(record) {
  168. var index = Ext.isNumber(record) ? record : this.store.indexOf(record);
  169. this.select(index, this.isExpanded());
  170. this.onSelect(this.store.getAt(index), index, this.isExpanded());
  171. },
  172. calcRowsPerPage : function() {
  173. if( this.store.getCount() ) {
  174. this.rowHeight = Ext.fly(this.view.getNode(0)).getHeight();
  175. this.rowsPerPage = this.maxHeight / this.rowHeight;
  176. } else {
  177. this.rowHeight = false;
  178. }
  179. }
  180. });
  181. Ext.reg('selectbox', Ext.ux.form.SelectBox);
  182. //backwards compat
  183. Ext.ux.SelectBox = Ext.ux.form.SelectBox;
  184. </pre>
  185. </body>
  186. </html>