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.

206 lines
5.4 KiB

2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. /*
  2. This file is part of Ext JS 3.4
  3. Copyright (c) 2011-2013 Sencha Inc
  4. Contact: http://www.sencha.com/contact
  5. GNU General Public License Usage
  6. This file may be used under the terms of the GNU General Public License version 3.0 as
  7. published by the Free Software Foundation and appearing in the file LICENSE included in the
  8. packaging of this file.
  9. Please review the following information to ensure the GNU General Public License version 3.0
  10. requirements will be met: http://www.gnu.org/copyleft/gpl.html.
  11. If you are unsure which license is appropriate for your use, please contact the sales department
  12. at http://www.sencha.com/contact.
  13. Build date: 2013-04-03 15:07:25
  14. */
  15. Ext.ns('Ext.ux.MultiCombo');
  16. /**
  17. * Checkable
  18. * @plugin
  19. */
  20. Ext.ux.MultiCombo.Checkable = function(cfg) {
  21. Ext.apply(this, cfg);
  22. };
  23. Ext.ux.MultiCombo.Checkable.prototype = {
  24. /**
  25. * @cfg {String} checkSelector DomQuery config for locating checkbox
  26. */
  27. checkSelector: 'input[type=checkbox]',
  28. /**
  29. * @cfg {String} itemSelector The itemSelector used with Combo's internal DataView [x-combo-list]
  30. */
  31. itemSelector : 'x-combo-list',
  32. /**
  33. * @cfg {String} cls
  34. */
  35. cls: 'combo-checkable',
  36. /**
  37. * @cfg {String} selectAllText The "SELECT ALL" phrase [Select All]
  38. */
  39. selectAllText: 'Select All',
  40. /**
  41. * @cfg {String} clearAllText the text to display for "clear all" link
  42. */
  43. clearAllText : 'clear all',
  44. /**
  45. * @cfg {String} separatorHtml arbitrary html rendered after Checkable controls. Can be used to add an
  46. * html separator markup.
  47. */
  48. separatorHtml : '',
  49. // private {Boolean} checked
  50. checked : null,
  51. init : function(combo) {
  52. this.combo = combo;
  53. var checkable = this;
  54. var id = Ext.id();
  55. var cls = combo.itemSelector || this.itemSelector;
  56. if (!combo.tpl) {
  57. combo.tpl =['<tpl for=".">','<div class="'+cls+'-item">{'+combo.displayField+'}</div>','</tpl>'] . join('');
  58. }
  59. combo.tpl = [
  60. '<div class="plugin ' + this.cls + '">',
  61. '<span class="' + this.cls + '-select-all">',
  62. '<input id="'+id+'" type="checkbox" />&nbsp;<label>'+this.selectAllText+'</label>',
  63. '</span>',
  64. '&nbsp;<span class="'+this.cls+'-clear-all">(<a href="#">' + this.clearAllText + '</a>)</span>',
  65. '</div>',
  66. this.separatorHtml
  67. ].join('') + combo.tpl.replace(new RegExp('({'+combo.displayField+'})'), "<input type=\"checkbox\" <tpl if=\"values._checked\">checked</tpl> />&nbsp;<label>$1</label>");
  68. combo.on('initview', function(c, dv) {
  69. dv.on('containerclick', this.onContainerClick.createDelegate(this));
  70. dv.on('selectionchange', this.onSelectionChange.createDelegate(this));
  71. dv.el.on('mouseover', this.onViewOver, this);
  72. },this);
  73. combo.on('select', this.onSelect.createDelegate(this));
  74. },
  75. onViewOver : function(ev, node){
  76. var target = ev.getTarget('.' + this.cls, 5);
  77. if (target) {
  78. this.combo.clearHighlight();
  79. Ext.fly(target).addClass(this.combo.highlightClass);
  80. }
  81. if(this.inKeyMode){ // prevent key nav and mouse over conflicts
  82. return;
  83. }
  84. return;
  85. },
  86. onSelect : function(rec, index) {
  87. // anything?
  88. },
  89. /**
  90. * getCheckbox
  91. * @return {DomNode}
  92. */
  93. getCheckbox : function() {
  94. return this.combo.view.el.child('.'+this.cls+' '+this.checkSelector, true);
  95. },
  96. /**
  97. * onSelectChange Fired by MultiCombo
  98. * @param {Object} dv
  99. * @param {Object} rs
  100. */
  101. onSelectionChange : function(dv, rs) {
  102. this.checked = (rs.length > 0 && rs.length == this.combo.store.getCount()) ? true : false;
  103. this.getCheckbox().checked = this.checked;
  104. var selector = this.checkSelector;
  105. setTimeout(function() {
  106. dv.el.select(dv.itemSelector + ' ' + selector).each(function(f) {
  107. f.dom.checked = false;
  108. });
  109. dv.el.select('.' + dv.selectedClass + ' ' + selector).each(function(f) {
  110. f.dom.checked = true;
  111. });
  112. },1);
  113. },
  114. /**
  115. * selectNext Called by MultiCombo. use this to apply hover-class to this row.
  116. * @param {Object} sender
  117. */
  118. selectNext: function(sender) {
  119. sender.view.el.child('.' + this.cls).addClass(sender.highlightClass);
  120. },
  121. /**
  122. * selectPrev Called by MultiCombo, use this to apply hover class to row.
  123. * @param {Object} sender
  124. */
  125. selectPrev : function(sender) {
  126. sender.view.el.child('.' + this.cls).addClass(sender.highlightClass);
  127. },
  128. /**
  129. * onEnter Called by MultiCombo
  130. * @param {Object} sender
  131. */
  132. onEnter : function(sender) {
  133. this.setChecked(!this.checked);
  134. },
  135. /**
  136. * onContainerClick Fired by MultiCombo
  137. * @param {Object} dv
  138. * @param {Object} ev
  139. */
  140. onContainerClick : function(dv, ev) {
  141. var btnClearAll = ev.getTarget('.'+this.cls+'-clear-all');
  142. if (btnClearAll) {
  143. this.clearAll();
  144. }
  145. else {
  146. this.setChecked(!this.checked);
  147. }
  148. return false;
  149. },
  150. // private selectAll
  151. selectAll : function() {
  152. var value = [];
  153. this.combo.store.each(function(r) { value.push(r.data[this.combo.valueField]); },this);
  154. this.combo.setValue(value);
  155. this.combo.selectByValue(this.combo.getValue());
  156. this.combo.focus();
  157. },
  158. // private clearAll
  159. clearAll : function() {
  160. this.combo.updateValue([]);
  161. this.combo.selectByValue([]);
  162. this.combo.view.clearSelections();
  163. this.combo.focus();
  164. this.combo.fireEvent('clearall', this.combo);
  165. },
  166. /**
  167. * setChecked
  168. * @param {Object} v
  169. */
  170. setChecked : function(v) {
  171. if (v == this.checked) {
  172. return;
  173. }
  174. this.checked = v;
  175. this.getCheckbox().checked = this.checked;
  176. if (this.checked == true) {
  177. this.selectAll();
  178. }
  179. else {
  180. this.clearAll();
  181. }
  182. }
  183. }