Ext.form.ComboPlus = Ext.extend(Ext.form.ComboBox, {
emptyText :'请选择',
mode :'local',
triggerAction :'all',
paramname : "parent",
displayField : "text",
valueField : "value",
onLoad : function(){
if(!this.hasFocus){
if(!this.data||this.data.length==0){
var index = this.store.find(this.valueField,this.value);
if(index!=-1){
this.setValue(this.value);
}else{
this.clearValue();
}
// this.setValue(this.value);
}
return;
}
if(this.store.getCount() > 0 || this.listEmptyText){
this.expand();
this.restrictHeight();
if(this.lastQuery == this.allQuery){
if(this.editable){
this.el.dom.select();
}
if(this.autoSelect !== false && !this.selectByValue(this.value, true)){
this.select(0, true);
}
}else{
if(this.autoSelect !== false){
this.selectNext();
}
if(this.typeAhead && this.lastKey != Ext.EventObject.BACKSPACE && this.lastKey != Ext.EventObject.DELETE){
this.taTask.delay(this.typeAheadDelay);
}
}
}else{
this.collapse();
//this.setDisabled(true);
}
},
initComponent: function(){
this.baseParams = {};
this.children = [];
Ext.form.ComboPlus.superclass.initComponent.apply(this, arguments);
if(!this.store){
if(!this.dataroot){
this.dataroot = {}
}else{
this.dataroot = {root:this.dataroot}
}
this.store = new Ext.data.Store({
proxy : new Ext.data.HttpProxy({
url : this.url
}),
reader: new Ext.data.JsonReader(this.dataroot, [
{name : 'text'},
{name : 'value'}
])
});
}
this.store.on("beforeload",function(store){
Ext.apply(store.baseParams,this.baseParams);
store.baseParams["queryper"] = GAS.FormUtils.JsonToString(this.baseParams);
},this)
},
setDefaultValue:function(v){
this.setValue(v);
},
setValue : function(v){
Ext.form.ComboPlus.superclass.setValue.call(this, v);
this.fireEvent('select', this);
},
findRecord : function(prop, value){
var record;
if(this.store.getCount() > 0){
this.store.each(function(r){
if(r.data[prop] === value || parseInt(r.data[prop],10) === parseInt(value,10)){
record = r;
return false;
}
});
}
return record;
},
addParam:function(parameters){
//Ext.apply(this.baseParams, parameters);
for(var a in parameters){
if(typeof parameters[a] == "object" && !Ext.isArray(parameters[a])){
Ext.apply(this.baseParams[a],parameters[a]);
}else{
this.baseParams[a] = parameters[a];
}
}
},
listeners:{
select : function(combo, record,index){
if(combo.getValue()==="" || parseInt(combo.getValue(),10) === NaN)return;
Ext.each(this.children, function(child){
var param = {};
param[combo.paramname] = combo.getValue();
child.addParam(param);
child.setDisabled(false);
child.reload();
});
}
},
addChild:function(child){
this.children.push(child);
return this;
},
reload:function(){
if(this.store)
this.store.load();
if(this.defaultValue){
this.setDefaultValue(this.defaultValue);
this.defaultValue = null; //默认值,只初始化一次
}
return this;
}
});
Ext.reg('comboplus', Ext.form.ComboPlus);