3 * Copyright(c) 2006-2010 Ext JS, LLC
5 * http://www.extjs.com/license
8 Ext.ns('Ext.ux.MultiCombo');
13 Ext.ux.MultiCombo.Checkable = function(cfg) {
16 Ext.ux.MultiCombo.Checkable.prototype = {
18 * @cfg {String} checkSelector DomQuery config for locating checkbox
20 checkSelector: 'input[type=checkbox]',
22 * @cfg {String} itemSelector The itemSelector used with Combo's internal DataView [x-combo-list]
24 itemSelector : 'x-combo-list',
28 cls: 'combo-checkable',
30 * @cfg {String} selectAllText The "SELECT ALL" phrase [Select All]
32 selectAllText: 'Select All',
34 * @cfg {String} clearAllText the text to display for "clear all" link
36 clearAllText : 'clear all',
39 * @cfg {String} separatorHtml arbitrary html rendered after Checkable controls. Can be used to add an
40 * html separator markup.
44 // private {Boolean} checked
47 init : function(combo) {
51 var cls = combo.itemSelector || this.itemSelector;
54 combo.tpl =['<tpl for=".">','<div class="'+cls+'-item">{'+combo.displayField+'}</div>','</tpl>'] . join('');
57 '<div class="plugin ' + this.cls + '">',
58 '<span class="' + this.cls + '-select-all">',
59 '<input id="'+id+'" type="checkbox" /> <label>'+this.selectAllText+'</label>',
61 ' <span class="'+this.cls+'-clear-all">(<a href="#">' + this.clearAllText + '</a>)</span>',
64 ].join('') + combo.tpl.replace(new RegExp('({'+combo.displayField+'})'), "<input type=\"checkbox\" <tpl if=\"values._checked\">checked</tpl> /> <label>$1</label>");
66 combo.on('initview', function(c, dv) {
67 dv.on('containerclick', this.onContainerClick.createDelegate(this));
68 dv.on('selectionchange', this.onSelectionChange.createDelegate(this));
69 dv.el.on('mouseover', this.onViewOver, this);
71 combo.on('select', this.onSelect.createDelegate(this));
74 onViewOver : function(ev, node){
75 var target = ev.getTarget('.' + this.cls, 5);
77 this.combo.clearHighlight();
78 Ext.fly(target).addClass(this.combo.highlightClass);
80 if(this.inKeyMode){ // prevent key nav and mouse over conflicts
86 onSelect : function(rec, index) {
94 getCheckbox : function() {
95 return this.combo.view.el.child('.'+this.cls+' '+this.checkSelector, true);
99 * onSelectChange Fired by MultiCombo
103 onSelectionChange : function(dv, rs) {
104 this.checked = (rs.length > 0 && rs.length == this.combo.store.getCount()) ? true : false;
105 this.getCheckbox().checked = this.checked;
107 var selector = this.checkSelector;
108 setTimeout(function() {
109 dv.el.select(dv.itemSelector + ' ' + selector).each(function(f) {
110 f.dom.checked = false;
112 dv.el.select('.' + dv.selectedClass + ' ' + selector).each(function(f) {
113 f.dom.checked = true;
119 * selectNext Called by MultiCombo. use this to apply hover-class to this row.
120 * @param {Object} sender
122 selectNext: function(sender) {
123 sender.view.el.child('.' + this.cls).addClass(sender.highlightClass);
127 * selectPrev Called by MultiCombo, use this to apply hover class to row.
128 * @param {Object} sender
130 selectPrev : function(sender) {
131 sender.view.el.child('.' + this.cls).addClass(sender.highlightClass);
135 * onEnter Called by MultiCombo
136 * @param {Object} sender
138 onEnter : function(sender) {
139 this.setChecked(!this.checked);
143 * onContainerClick Fired by MultiCombo
147 onContainerClick : function(dv, ev) {
148 var btnClearAll = ev.getTarget('.'+this.cls+'-clear-all');
153 this.setChecked(!this.checked);
159 selectAll : function() {
161 this.combo.store.each(function(r) { value.push(r.data[this.combo.valueField]); },this);
162 this.combo.setValue(value);
163 this.combo.selectByValue(this.combo.getValue());
168 clearAll : function() {
169 this.combo.updateValue([]);
170 this.combo.selectByValue([]);
171 this.combo.view.clearSelections();
173 this.combo.fireEvent('clearall', this.combo);
180 setChecked : function(v) {
181 if (v == this.checked) {
185 this.getCheckbox().checked = this.checked;
186 if (this.checked == true) {