Roo.form.ComboCheck = function(config){
Roo.form.ComboCheck.superclass.constructor.call(this, config);
var req= [ 'hiddenName', 'displayField', 'valueField' ];
var _t = this;
Roo.each(req, function(e) {
if ((typeof(_t[e]) == 'undefined' ) || !_t[e].length) {
throw "Roo.form.ComboCheck : missing value for: " + e;
}
});
};
Roo.extend(Roo.form.ComboCheck, Roo.form.ComboBox, {
editable : false,
selectedClass: 'x-menu-item-checked',
onRender : function(ct, position){
var _t = this;
if(!this.tpl){
var cls = 'x-combo-list';
this.tpl = new Roo.Template({
html : '<div class="'+cls+'-item x-menu-check-item">' +
'<img class="x-menu-item-icon" style="margin: 0px;" src="' + Roo.BLANK_IMAGE_URL + '">' +
'<span>{' + this.displayField + '}</span>' +
'</div>'
});
}
Roo.form.ComboCheck.superclass.onRender.call(this, ct, position);
this.view.singleSelect = false;
this.view.multiSelect = true;
this.view.toggleSelect = true;
this.pageTb.add(new Roo.Toolbar.Fill(),{
text: 'Select All',
handler: function() {
_t.selectAll();
}
},
{
text: 'Done',
handler: function() {
_t.collapse();
}
});
},
cleanLeadingSpace : function(e)
{
return;
},
doForce : function() {
return;
},
onViewOver : function(e, t){
return;
},
onViewClick : function(doFocus,index){
return;
},
select: function () {
},
selectByValue : function(xv, scrollIntoView){
var ar = this.getValueArray();
var sels = [];
Roo.each(ar, function(v) {
if(v === undefined || v === null){
return;
}
var r = this.findRecord(this.valueField, v);
if(r){
sels.push(this.store.indexOf(r))
}
},this);
this.view.select(sels);
return false;
},
selectAll : function()
{
var sels = [];
this.store.each(function(r,i) {
sels.push(i);
});
this.view.select(sels);
this.collapse();
return false;
},
onSelect : function(record, index){
this.view.clearSelections();
this.setValue('[]');
if (this.value != this.valueBefore) {
this.fireEvent('change', this, this.value, this.valueBefore);
this.valueBefore = this.value;
}
},
getValueArray : function()
{
var ar = [] ;
try {
if (typeof(this.value) == 'undefined') {
return [];
}
var ar = Roo.decode(this.value);
return ar instanceof Array ? ar : []; } catch(e) {
Roo.log(e + "\nRoo.form.ComboCheck:getValueArray invalid data:" + this.getValue());
return [];
}
},
expand : function ()
{
Roo.form.ComboCheck.superclass.expand.call(this);
this.valueBefore = typeof(this.value) == 'undefined' ? '' : this.value;
},
collapse : function(){
Roo.form.ComboCheck.superclass.collapse.call(this);
var sl = this.view.getSelectedIndexes();
var st = this.store;
var nv = [];
var tv = [];
var r;
Roo.each(sl, function(i) {
r = st.getAt(i);
nv.push(r.get(this.valueField));
},this);
this.setValue(Roo.encode(nv));
if (this.value != this.valueBefore) {
this.fireEvent('change', this, this.value, this.valueBefore);
this.valueBefore = this.value;
}
},
setValue : function(v){
this.value = v;
var vals = this.getValueArray();
var tv = [];
Roo.each(vals, function(k) {
var r = this.findRecord(this.valueField, k);
if(r){
tv.push(r.data[this.displayField]);
}else if(this.valueNotFoundText !== undefined){
tv.push( this.valueNotFoundText );
}
},this);
Roo.form.ComboBox.superclass.setValue.call(this, tv.join(', '));
this.hiddenField.value = v;
this.value = v;
}
});