Roo.form.TriggerField = function(config){
this.mimicing = false;
Roo.form.TriggerField.superclass.constructor.call(this, config);
};
Roo.extend(Roo.form.TriggerField, Roo.form.TextField, {
defaultAutoCreate : {tag: "input", type: "text", size: "16", autocomplete: "new-password"},
hideTrigger:false,
autoSize: Roo.emptyFn,
monitorTab : true,
deferHeight : true,
actionMode : 'wrap',
onResize : function(w, h){
Roo.form.TriggerField.superclass.onResize.apply(this, arguments);
if(typeof w == 'number'){
var x = w - this.trigger.getWidth();
this.el.setWidth(this.adjustWidth('input', x));
this.trigger.setStyle('left', x+'px');
}
},
adjustSize : Roo.BoxComponent.prototype.adjustSize,
getResizeEl : function(){
return this.wrap;
},
getPositionEl : function(){
return this.wrap;
},
alignErrorIcon : function(){
this.errorIcon.alignTo(this.wrap, 'tl-tr', [2, 0]);
},
onRender : function(ct, position){
Roo.form.TriggerField.superclass.onRender.call(this, ct, position);
this.wrap = this.el.wrap({cls: "x-form-field-wrap"});
this.trigger = this.wrap.createChild(this.triggerConfig ||
{tag: "img", src: Roo.BLANK_IMAGE_URL, cls: "x-form-trigger " + this.triggerClass});
if(this.hideTrigger){
this.trigger.setDisplayed(false);
}
this.initTrigger();
if(!this.width){
this.wrap.setWidth(this.el.getWidth()+this.trigger.getWidth());
}
},
initTrigger : function(){
this.trigger.on("click", this.onTriggerClick, this, {preventDefault:true});
this.trigger.addClassOnOver('x-form-trigger-over');
this.trigger.addClassOnClick('x-form-trigger-click');
},
onDestroy : function(){
if(this.trigger){
this.trigger.removeAllListeners();
this.trigger.remove();
}
if(this.wrap){
this.wrap.remove();
}
Roo.form.TriggerField.superclass.onDestroy.call(this);
},
onFocus : function(){
Roo.form.TriggerField.superclass.onFocus.call(this);
if(!this.mimicing){
this.wrap.addClass('x-trigger-wrap-focus');
this.mimicing = true;
Roo.get(Roo.isIE ? document.body : document).on("mousedown", this.mimicBlur, this);
if(this.monitorTab){
this.el.on("keydown", this.checkTab, this);
}
}
},
checkTab : function(e){
if(e.getKey() == e.TAB){
this.triggerBlur();
}
},
onBlur : function(){
},
mimicBlur : function(e, t){
if(!this.wrap.contains(t) && this.validateBlur()){
this.triggerBlur();
}
},
triggerBlur : function(){
this.mimicing = false;
Roo.get(Roo.isIE ? document.body : document).un("mousedown", this.mimicBlur);
if(this.monitorTab){
this.el.un("keydown", this.checkTab, this);
}
this.wrap.removeClass('x-trigger-wrap-focus');
Roo.form.TriggerField.superclass.onBlur.call(this);
},
validateBlur : function(e, t){
return true;
},
onDisable : function(){
Roo.form.TriggerField.superclass.onDisable.call(this);
if(this.wrap){
this.wrap.addClass('x-item-disabled');
}
},
onEnable : function(){
Roo.form.TriggerField.superclass.onEnable.call(this);
if(this.wrap){
this.wrap.removeClass('x-item-disabled');
}
},
onShow : function(){
var ae = this.getActionEl();
if(ae){
ae.dom.style.display = '';
ae.dom.style.visibility = 'visible';
}
},
onHide : function(){
var ae = this.getActionEl();
ae.dom.style.display = 'none';
},
onTriggerClick : Roo.emptyFn
});
Roo.form.TwinTriggerField = Roo.extend(Roo.form.TriggerField, {
initComponent : function(){
Roo.form.TwinTriggerField.superclass.initComponent.call(this);
this.triggerConfig = {
tag:'span', cls:'x-form-twin-triggers', cn:[
{tag: "img", src: Roo.BLANK_IMAGE_URL, cls: "x-form-trigger " + this.trigger1Class},
{tag: "img", src: Roo.BLANK_IMAGE_URL, cls: "x-form-trigger " + this.trigger2Class}
]};
},
getTrigger : function(index){
return this.triggers[index];
},
initTrigger : function(){
var ts = this.trigger.select('.x-form-trigger', true);
this.wrap.setStyle('overflow', 'hidden');
var triggerField = this;
ts.each(function(t, all, index){
t.hide = function(){
var w = triggerField.wrap.getWidth();
this.dom.style.display = 'none';
triggerField.el.setWidth(w-triggerField.trigger.getWidth());
};
t.show = function(){
var w = triggerField.wrap.getWidth();
this.dom.style.display = '';
triggerField.el.setWidth(w-triggerField.trigger.getWidth());
};
var triggerIndex = 'Trigger'+(index+1);
if(this['hide'+triggerIndex]){
t.dom.style.display = 'none';
}
t.on("click", this['on'+triggerIndex+'Click'], this, {preventDefault:true});
t.addClassOnOver('x-form-trigger-over');
t.addClassOnClick('x-form-trigger-click');
}, this);
this.triggers = ts.elements;
},
onTrigger1Click : Roo.emptyFn,
onTrigger2Click : Roo.emptyFn
});