//ntype(1:数字框,2:日期框,3:选择框)
Ext.form.ChangeField = Ext.extend(Ext.form.TextField, {
defaultAutoCreate : {
tag : "input",
type : "text",
size : "10",
autocomplete : "off"
},
format : "m/d/Y",
altFormats : "m/d/Y|n/j/Y|n/j/y|m/j/y|n/d/y|m/j/Y|n/d/Y|m-d-y|m-d-Y|m/d|m-d|md|mdy|mdY|d|Y-m-d",
disabledDaysText : "Disabled",
disabledDatesText : "Disabled",
invalidText : "{0} is not a valid date - it must be in the format {1}",
showToday : true,
//TriggerField
hideTrigger : false,
autoSize : Ext.emptyFn,
monitorTab : true,
deferHeight : true,
mimicing : false,
actionMode : 'wrap',
//NumberField
fieldClass : "x-form-field x-form-num-field",
allowDecimals : true,
decimalSeparator : ".",
decimalPrecision : 2,
allowNegative : true,
nanText : "{0} is not a valid number",
baseChars : "0123456789",
//combox
listClass : '',
selectedClass : 'x-combo-selected',
triggerClass : 'x-form-arrow-trigger',
shadow : 'sides',
listAlign : 'tl-bl?',
maxHeight : 300,
minHeight : 90,
triggerAction : 'query',
minChars : 4,
typeAhead : false,
queryDelay : 500,
pageSize : 0,
selectOnFocus : false,
queryParam : 'query',
loadingText : 'Loading...',
resizable : false,
handleHeight : 8,
editable : true,
allQuery : '',
mode : 'remote',
minListWidth : 70,
forceSelection : false,
typeAheadDelay : 250,
lazyInit : true,
//自定义
ntype:0,
minText : "this field value for this field is {0}",
maxText : "this field value for this field is {0}",
initComponent : function() {
Ext.form.ChangeField.superclass.initComponent.call(this);
this.addEvents("select","expand", "collapse", "beforeselect", "select","beforequery");
if (typeof this.minValue == 'string') {
this.minValue = this.parseDate(this.minValue);
}
if (typeof this.maxValue == 'string') {
this.maxValue = this.parseDate(this.maxValue);
}
this.disabledDatesRE = null;
this.initDisabledDays();
//combox
if (this.transform) {
this.allowDomMove = false;
var s = Ext.getDom(this.transform);
if (!this.hiddenName) {
this.hiddenName = s.name;
}
if (!this.store) {
this.mode = 'local';
var d = [], opts = s.options;
for (var i = 0, len = opts.length; i < len; i++) {
var o = opts[i], value = (o.hasAttribute ? o
.hasAttribute('value') : o
.getAttributeNode('value').specified)
? o.value
: o.text;
if (o.selected) {
this.value = value;
}
d.push([value, o.text]);
}
this.store = new Ext.data.SimpleStore({
'id' : 0,
fields : ['value', 'text'],
data : d
});
this.valueField = 'value';
this.displayField = 'text';
}
s.name = Ext.id();
if (!this.lazyRender) {
this.target = true;
this.el = Ext.DomHelper.insertBefore(s, this.autoCreate
|| this.defaultAutoCreate);
Ext.removeNode(s);
this.render(this.el.parentNode);
} else {
Ext.removeNode(s);
}
} else if (Ext.isArray(this.store)) {
if (Ext.isArray(this.store[0])) {
this.store = new Ext.data.SimpleStore({
fields : ['value', 'text'],
data : this.store
});
this.valueField = 'value';
} else {
this.store = new Ext.data.SimpleStore({
fields : ['text'],
data : this.store,
expandData : true
});
this.valueField = 'text';
}
this.displayField = 'text';
this.mode = 'local';
}
this.selectedIndex = -1;
if (this.mode == 'local') {
if (this.initialConfig.queryDelay === undefined) {
this.queryDelay = 10;
}
if (this.initialConfig.minChars === undefined) {
this.minChars = 0;
}
}
},
initDisabledDays : function() {
if (this.disabledDates) {
var b = this.disabledDates, a = b.length - 1, c = "(?:";
Ext.each(b, function(g, e) {
c += Ext.isDate(g)
? "^" + Ext.escapeRe(g.dateFormat(this.format))
+ "$"
: b[e];
if (e != a) {
c += "|"
}
}, this);
this.disabledDatesRE = new RegExp(c + ")")
}
},
setDisabledDates : function(a) {
this.disabledDates = a;
this.initDisabledDays();
if (this.menu) {
this.menu.picker.setDisabledDates(this.disabledDatesRE)
}
},
setDisabledDays : function(a) {
this.disabledDays = a;
if (this.menu) {
this.menu.picker.setDisabledDays(a)
}
},
setMinValue : function(a) {
this.minValue = (Ext.isString(a) ? this.parseDate(a) : a);
if (this.menu) {
this.menu.picker.setMinDate(this.minValue)
}
},
setMaxValue : function(a) {
this.maxValue = (Ext.isString(a) ? this.parseDate(a) : a);
if (this.menu) {
this.menu.picker.setMaxDate(this.maxValue)
}
},
getValue : function() {
if(this.ntype ==1){
return this.fixPrecision(this
.parseValue(Ext.form.ChangeField.superclass.getValue
.call(this)))
}
else if(this.ntype ==2){
return this
.parseDate(Ext.form.ChangeField.superclass.getValue.call(this))
|| ""
}else if(this.ntype ==3){
if (this.valueField) {
return (typeof this.value !== "undefined") ? this.value : ""
} else {
return Ext.form.ChangeField.superclass.getValue.call(this)
}
}else {
return Ext.form.ChangeField.superclass.getValue.call(this)
}
},
setValue : function(a) {
if(this.ntype == 1){
a = typeof a == "number" ? a : parseFloat(String(a).replace(
this.decimalSeparator, "."));
a = isNaN(a) ? "" : String(a).replace(".",
this.decimalSeparator);
return Ext.form.ChangeField.superclass.setValue.call(this,a);
}else if(this.ntype ==2){
return Ext.form.ChangeField.superclass.setValue.call(this, this.formatDate(this.parseDate(a)));
}else if(this.ntype == 3){
var c = a;
if (this.valueField) {
var b = this.findRecord(this.valueField, a);
if (b) {
c = b.data[this.displayField]
} else {
if (typeof (this.valueNotFoundText) !== "undefined") {
c = this.valueNotFoundText
}
}
}
this.lastSelectionText = c;
if (this.hiddenField) {
this.hiddenField.value = a
}
Ext.form.ChangeField.superclass.setValue.call(this, c);
this.value = a;
return this
}
else{
return Ext.form.ChangeField.superclass.setValue.call(this,a);
}
},
parseDate : function(d) {
if (!d || Ext.isDate(d)) {
return d
}
var b = Date.parseDate(d, this.format);
if (!b && this.altFormats) {
if (!this.altFormatsArray) {
this.altFormatsArray = this.altFormats.split("|")
}
for (var c = 0, a = this.altFormatsArray.length; c < a && !b; c++) {
b = Date.parseDate(d, this.altFormatsArray[c])
}
}
return b;
},
onDestroy : function() {
if(this.ntype ==2){
Ext.destroy(this.menu,this.trigger, this.wrap);
if (this.mimicing) {
this.doc.un("mousedown", this.mimicBlur, this)
}
}else if(this.ntype ==3){
if (this.dqTask) {
this.dqTask.cancel();
this.dqTask = null
}
this.bindStore(null);
Ext.destroy(this.resizer, this.view, this.pageTb, this.innerList,
this.list);
}
Ext.form.ChangeField.superclass.onDestroy.call(this)
},
formatDate : function(a) {
return Ext.isDate(a) ? a.dateFormat(this.format) : a;
},
onTriggerClick : function() {
if(this.ntype ==2 ){
if (this.disabled) {
return;
}
if (this.menu == null) {
this.menu = new Ext.menu.DateMenu();
}
Ext.apply(this.menu.picker, {
minDate : this.minValue,
maxDate : this.maxValue,
disabledDatesRE : this.disabledDatesRE,
disabledDatesText : this.disabledDatesText,
disabledDays : this.disabledDays,
disabledDaysText : this.disabledDaysText,
format : this.format,
showToday : this.showToday,
minText : String.format(this.minText, this
.formatDate(this.minValue)),
maxText : String.format(this.maxText, this
.formatDate(this.maxValue))
});
this.menu.on(Ext.apply({}, this.menuListeners, {
scope : this
}));
this.menu.picker.setValue(this.getValue() || new Date());
this.menu.show(this.el, "tl-bl?");
this.menuEvents("on");
}else if(this.ntype ==3){
if (this.disabled) {
return;
}
if (this.isExpanded()) {
this.collapse();
this.el.focus();
} else {
this.onFocus({});
if (this.triggerAction == 'all') {
this.doQuery(this.allQuery, true);
} else {
this.doQuery(this.getRawValue());
}
this.el.focus();
}
}
},
menuEvents : function(a) {
this.menu[a]("select", this.onSelect, this);
this.menu[a]("hide", this.onMenuHide, this);
this.menu[a]("show", this.onFocus, this)
},
onSelect : function(a, b) {
if(this.ntype ==2){
this.setValue(b);
this.fireEvent("select", this, b);
this.menu.hide();
}else if(this.ntype ==3){
if (this.fireEvent("beforeselect", this, a, b) !== false) {
this.setValue(a.data[this.valueField || this.displayField]);
this.collapse();
this.fireEvent("select", this, a, b)
}
}
},
onMenuHide : function() {
this.focus(false, 60);
this.menuEvents("un")
},
beforeBlur : function() {
//NumberFiled
if(this.ntype == 1){
var a = this.parseValue(this.getRawValue());
if (!Ext.isEmpty(a)) {
this.setValue(this.fixPrecision(a))
}
}
//DateFiled
else if(this.ntype == 2){
var a = this.parseDate(this.getRawValue());
if (a) {
this.setValue(a)
}
}else if(this.ntype ==3){
var b = this.getRawValue(), a = this.findRecord(this.displayField, b);
if (!a && this.forceSelection) {
if (b.length > 0 && b != this.emptyText) {
this.el.dom.value = (typeof (this.lastSelectionText) !== "undefined")
? this.lastSelectionText
: "";
this.applyEmptyText()
} else {
this.clearValue()
}
} else {
if (a) {
b = a.get(this.valueField || this.displayField)
}
this.setValue(b)
}
}
},
//TriggerField
onFocus : function() {
Ext.form.ChangeField.superclass.onFocus.call(this);
if(this.ntype ==2){
if (!this.mimicing) {
this.wrap.addClass(this.wrapFocusClass);
this.mimicing = true;
this.doc.on("mousedown", this.mimicBlur, this, {
delay : 10
});
if (this.monitorTab) {
this.on("specialkey", this.checkTab, this)
}
}
}
},
checkTab : function(a, b) {
if (b.getKey() == b.TAB) {
this.triggerBlur()
}
},
mimicBlur : function(a) {
if (!this.isDestroyed && !this.wrap.contains(a.target)/*&& this.validateBlur(a)*/) {
this.triggerBlur()
}
},
triggerBlur : function() {
this.mimicing = false;
this.doc.un("mousedown", this.mimicBlur, this);
if (this.monitorTab && this.el) {
this.un("specialkey", this.checkTab, this)
}
Ext.form.TriggerField.superclass.onBlur.call(this);
if (this.wrap) {
this.wrap.removeClass(this.wrapFocusClass)
}
},
triggerBlur : function() {
this.mimicing = false;
this.doc.un("mousedown", this.mimicBlur, this);
if (this.monitorTab && this.el) {
this.un("specialkey", this.checkTab, this)
}
Ext.form.TriggerField.superclass.onBlur.call(this);
if (this.wrap) {
this.wrap.removeClass(this.wrapFocusClass)
}
},
// onRender : function(b, a) {
// this.doc = Ext.isIE ? Ext.getBody() : Ext.getDoc();
// Ext.form.ChangeField.superclass.onRender.call(this, b, a);
// this.wrap = this.el.wrap({
// cls : "x-form-field-wrap x-form-field-trigger-wrap"
// });
// this.trigger = this.wrap.createChild(this.triggerConfig || {
// tag : "img",
// src : Ext.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())
// }
// if (!this.editable) {
// this.editable = true;
// this.setEditable(false)
// }
// this.resizeEl = this.positionEl = this.wrap
//combox
// if (this.hiddenName) {
// this.hiddenField = this.el.insertSibling({
// tag : "input",
// type : "hidden",
// name : this.hiddenName,
// id : (this.hiddenId || this.hiddenName)
// }, "before", true);
// this.el.dom.removeAttribute("name")
// }
// if (Ext.isGecko) {
// this.el.dom.setAttribute("autocomplete", "off")
// }
// if (!this.lazyInit) {
// this.initList()
// } else {
// this.on("focus", this.initList, this, {
// single : true
// })
// }
// },
initTrigger : function() {
this.mon(this.trigger, "click", this.onTriggerClick, this, {
preventDefault : true
});
this.trigger.addClassOnOver("x-form-trigger-over");
this.trigger.addClassOnClick("x-form-trigger-click")
},
setEditable : function(a) {
if (a == this.editable) {
return
}
this.editable = a;
if (!a) {
this.el.addClass("x-trigger-noedit").on("click",
this.onTriggerClick, this).dom.setAttribute(
"readOnly", true)
} else {
this.el.removeClass("x-trigger-noedit").un("click",
this.onTriggerClick, this).dom
.removeAttribute("readOnly")
}
},
//Number
// initEvents : function() {
// var a = this.baseChars + "";
// if (this.allowDecimals) {
// a += this.decimalSeparator
// }
// if (this.allowNegative) {
// a += "-"
// }
// this.maskRe = new RegExp("[" + Ext.escapeRe(a) + "]");
// Ext.form.ChangeField.superclass.initEvents.call(this)
// },
fixPrecision : function(b) {
var a = isNaN(b);
if (!this.allowDecimals || this.decimalPrecision == -1 || a
|| !b) {
return a ? "" : b;
}
return parseFloat(parseFloat(b).toFixed(this.decimalPrecision));
},
parseValue : function(a) {
a = parseFloat(String(a).replace(this.decimalSeparator, "."));
return isNaN(a) ? "" : a;
},
//自定义['0', '文本框'], ['1', '数字框'], ['2', '日期框'], ['3', '选择框']
setNType:function(t){//设置文本类型
this.ntype=t;//类型赋值
this.setValue('');
if(t == 0 || t == 1){
if(t == 1){
var a = this.baseChars + "";
if (this.allowDecimals) {
a += this.decimalSeparator;
}
if (this.allowNegative) {
a += "-";
}
this.maskRe = new RegExp("[" + Ext.escapeRe(a) + "]");
if (this.maskRe
|| (this.vtype && this.disableKeyFilter !== true && (this.maskRe = Ext.form.VTypes[this.vtype
+ "Mask"]))) {
this.mon(this.el, "keypress", this.filterKeys, this)
}
}else{
this.maskRe = new RegExp("[]]");//NumberField
this.el.un( "keypress", this.filterKeys, this);
}
Ext.removeNode(this.trigger==null?'':this.trigger.dom);
}
if(t == 2 || t == 3){
//datefield
if(t == 2){
this.triggerClass='x-form-date-trigger';
}
//combox
else if(t == 3){
if (this.hiddenName) {
this.hiddenField = this.el.insertSibling({
tag : "input",
type : "hidden",
name : this.hiddenName,
id : (this.hiddenId || this.hiddenName)
}, "before", true);
this.el.dom.removeAttribute("name");
}
if (Ext.isGecko) {
this.el.dom.setAttribute("autocomplete", "off");
}
if (!this.lazyInit) {
this.initList();
} else {
this.on("focus", this.initList, this, {
single : true
});
}
this.triggerClass='x-form-arrow-trigger';
}
this.doc = Ext.isIE ? Ext.getBody() : Ext.getDoc();
this.wrap = this.el.wrap({
cls : "x-form-field-wrap x-form-field-trigger-wrap"
});
Ext.removeNode(this.trigger==null?'':this.trigger.dom);
this.trigger = this.wrap.createChild(this.triggerConfig || {
tag : "img",
src : Ext.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())
}
if (!this.editable) {
this.editable = true;
this.setEditable(false)
}
this.resizeEl = this.positionEl = this.wrap
this.maskRe = new RegExp("[]]");//NumberField
this.el.un("keypress", this.filterKeys, this);
}
},
//combox
initValue : function() {
Ext.form.ChangeField.superclass.initValue.call(this);
if (this.hiddenField) {
this.hiddenField.value = (typeof this.hiddenValue !== "undefined")
? this.hiddenValue
: (typeof this.value !== "undefined") ? this.value : ""
}
},
initList : function() {
if (!this.list) {
var a = "x-combo-list";
this.list = new Ext.Layer({
parentEl : this.getListParent(),
shadow : this.shadow,
cls : [a, this.listClass].join(" "),
constrain : false
});
var b = this.listWidth
|| Math.max(this.wrap.getWidth(), this.minListWidth);
this.list.setSize(b, 0);
this.list.swallowEvent("mousewheel");
this.assetHeight = 0;
if (this.syncFont !== false) {
this.list.setStyle("font-size", this.el.getStyle("font-size"))
}
if (this.title) {
this.header = this.list.createChild({
cls : a + "-hd",
html : this.title
});
this.assetHeight += this.header.getHeight()
}
this.innerList = this.list.createChild({
cls : a + "-inner"
});
this.mon(this.innerList, "mouseover", this.onViewOver, this);
this.mon(this.innerList, "mousemove", this.onViewMove, this);
this.innerList.setWidth(b - this.list.getFrameWidth("lr"));
if (this.pageSize) {
this.footer = this.list.createChild({
cls : a + "-ft"
});
this.pageTb = new Ext.PagingToolbar({
store : this.store,
pageSize : this.pageSize,
renderTo : this.footer
});
this.assetHeight += this.footer.getHeight()
}
if (!this.tpl) {
this.tpl = '<tpl for="."><div class="' + a + '-item">{'
+ this.displayField + "}</div></tpl>"
}
this.view = new Ext.DataView({
applyTo : this.innerList,
tpl : this.tpl,
singleSelect : true,
selectedClass : this.selectedClass,
itemSelector : this.itemSelector || "." + a + "-item",
emptyText : this.listEmptyText
});
this.mon(this.view, "click", this.onViewClick, this);
this.bindStore(this.store, true);
if (this.resizable) {
this.resizer = new Ext.Resizable(this.list, {
pinned : true,
handles : "se"
});
this.mon(this.resizer, "resize", function(e, c, d) {
this.maxHeight = d - this.handleHeight
- this.list.getFrameWidth("tb")
- this.assetHeight;
this.listWidth = c;
this.innerList.setWidth(c
- this.list.getFrameWidth("lr"));
this.restrictHeight()
}, this);
this[this.pageSize ? "footer" : "innerList"].setStyle(
"margin-bottom", this.handleHeight + "px")
}
}
},
getListParent : function() {
return document.body
},
getStore : function() {
return this.store
},
bindStore : function(store, initial) {
if (this.store && !initial) {
this.store.un('beforeload', this.onBeforeLoad, this);
this.store.un('load', this.onLoad, this);
this.store.un('loadexception', this.collapse, this);
if (!store) {
this.store = null;
if (this.view) {
this.view.setStore(null);
}
}
}
if (store) {
this.store = Ext.StoreMgr.lookup(store);
this.store.on('beforeload', this.onBeforeLoad, this);
this.store.on('load', this.onLoad, this);
this.store.on('loadexception', this.collapse, this);
if (this.view) {
this.view.setStore(store);
}
}
},
getEvents:function(){
this.keyNav = new Ext.KeyNav(this.el, {
up : function(a) {
this.inKeyMode = true;
this.selectPrev()
},
down : function(a) {
if (!this.isExpanded()) {
this.onTriggerClick()
} else {
this.inKeyMode = true;
this.selectNext()
}
},
enter : function(a) {
this.onViewClick()
},
esc : function(a) {
this.collapse()
},
tab : function(a) {
this.onViewClick(false);
return true
},
scope : this,
doRelay : function(c, b, a) {
if (a == "down" || this.scope.isExpanded()) {
var d = Ext.KeyNav.prototype.doRelay.apply(this, arguments);
if (!Ext.isIE && Ext.EventManager.useKeydown) {
this.scope.fireKey(c)
}
return d
}
return true
},
forceKeyDown : true,
defaultEventAction : "stopEvent"
});
this.queryDelay = Math.max(this.queryDelay || 10, this.mode == "local"
? 10
: 250);
this.dqTask = new Ext.util.DelayedTask(this.initQuery, this);
if (this.typeAhead) {
this.taTask = new Ext.util.DelayedTask(this.onTypeAhead, this)
}
if (this.editable !== false && !this.enableKeyEvents) {
this.mon(this.el, "keyup", this.onKeyUp, this)
}
},
fireKey : function(a) {
if (!this.isExpanded()) {
Ext.form.ChangeField.superclass.fireKey.call(this, a)
}
},
onResize : function(a, b) {
Ext.form.ChangeField.superclass.onResize.apply(this, arguments);
if (this.isVisible() && this.list) {
this.doResize(a)
} else {
this.bufferSize = a
}
},
doResize : function(a) {
if (typeof this.listWidth == "undefined") {
var b = Math.max(a, this.minListWidth);
this.list.setWidth(b);
this.innerList.setWidth(b - this.list.getFrameWidth("lr"))
}
},
onEnable : function() {
Ext.form.ChangeField.superclass.onEnable.apply(this, arguments);
if (this.hiddenField) {
this.hiddenField.disabled = false
}
},
onDisable : function() {
Ext.form.ChangeField.superclass.onDisable.apply(this, arguments);
if (this.hiddenField) {
this.hiddenField.disabled = true
}
},
onBeforeLoad : function() {
if (!this.hasFocus) {
return
}
this.innerList.update(this.loadingText
? '<div class="loading-indicator">' + this.loadingText
+ "</div>"
: "");
this.restrictHeight();
this.selectedIndex = -1
},
onLoad : function() {
if (!this.hasFocus) {
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.selectByValue(this.value, true)) {
this.select(0, true)
}
} else {
this.selectNext();
if (this.typeAhead && this.lastKey != Ext.EventObject.BACKSPACE
&& this.lastKey != Ext.EventObject.DELETE) {
this.taTask.delay(this.typeAheadDelay)
}
}
} else {
this.onEmptyResults()
}
},
onTypeAhead : function() {
if (this.store.getCount() > 0) {
var b = this.store.getAt(0);
var c = b.data[this.displayField];
var a = c.length;
var d = this.getRawValue().length;
if (d != a) {
this.setRawValue(c);
this.selectText(d, c.length)
}
}
},
getName : function() {
var a = this.hiddenField;
return a && a.name ? a.name : this.hiddenName
|| Ext.form.ChangeField.superclass.getName.call(this)
},
clearValue : function() {
if (this.hiddenField) {
this.hiddenField.value = ""
}
this.setRawValue("");
this.lastSelectionText = "";
this.applyEmptyText();
this.value = ""
},
findRecord : function(c, b) {
var a;
if(this.store != null){
if (this.store.getCount() > 0) {
this.store.each(function(d) {
if (d.data[c] == b) {
a = d;
return false
}
})
}
}
return a
},
onViewMove : function(b, a) {
this.inKeyMode = false
},
onViewOver : function(d, b) {
if (this.inKeyMode) {
return
}
var c = this.view.findItemFromChild(b);
if (c) {
var a = this.view.indexOf(c);
this.select(a, false)
}
},
onViewClick : function(b) {
var a = this.view.getSelectedIndexes()[0], c = this.store, d = c
.getAt(a);
if (d) {
this.onSelect(d, a)
} else {
if (c.getCount() === 0) {
this.onEmptyResults()
}
}
if (b !== false) {
this.el.focus()
}
},
restrictHeight : function() {
this.innerList.dom.style.height = "";
var b = this.innerList.dom, e = this.list.getFrameWidth("tb")
+ (this.resizable ? this.handleHeight : 0) + this.assetHeight, c = Math
.max(b.clientHeight, b.offsetHeight, b.scrollHeight), a = this
.getPosition()[1]
- Ext.getBody().getScroll().top, g = Ext.lib.Dom
.getViewHeight()
- a - this.getSize().height, d = Math.max(a, g, this.minHeight
|| 0)
- this.list.shadowOffset - e - 5;
c = Math.min(c, d, this.maxHeight);
this.innerList.setHeight(c);
this.list.beginUpdate();
this.list.setHeight(c + e);
this.list.alignTo(this.wrap, this.listAlign);
this.list.endUpdate()
},
onEmptyResults : function() {
this.collapse()
},
isExpanded : function() {
return this.list && this.list.isVisible()
},
selectByValue : function(a, c) {
if (!Ext.isEmpty(a, true)) {
var b = this.findRecord(this.valueField || this.displayField, a);
if (b) {
this.select(this.store.indexOf(b), c);
return true
}
}
return false
},
select : function(a, c) {
this.selectedIndex = a;
this.view.select(a);
if (c !== false) {
var b = this.view.getNode(a);
if (b) {
this.innerList.scrollChildIntoView(b, false)
}
}
},
selectNext : function() {
var a = this.store.getCount();
if (a > 0) {
if (this.selectedIndex == -1) {
this.select(0)
} else {
if (this.selectedIndex < a - 1) {
this.select(this.selectedIndex + 1)
}
}
}
},
selectPrev : function() {
var a = this.store.getCount();
if (a > 0) {
if (this.selectedIndex == -1) {
this.select(0)
} else {
if (this.selectedIndex !== 0) {
this.select(this.selectedIndex - 1)
}
}
}
},
validateBlur : function() {
return !this.list || !this.list.isVisible()
},
initQuery : function() {
this.doQuery(this.getRawValue())
},
doQuery : function(q, forceAll) {
if (q === undefined || q === null) {
q = '';
}
var qe = {
query : q,
forceAll : forceAll,
combo : this,
cancel : false
};
if (this.fireEvent('beforequery', qe) === false || qe.cancel) {
return false;
}
q = qe.query;
forceAll = qe.forceAll;
if (forceAll === true || (q.length >= this.minChars)) {
if (this.lastQuery !== q) {
this.lastQuery = q;
if (this.mode == 'local') {
this.selectedIndex = -1;
if (forceAll) {
this.store.clearFilter();
} else {
this.store.filter(this.displayField, q);
}
this.onLoad();
} else {
this.store.baseParams[this.queryParam] = q;
this.store.load({
params : this.getParams(q)
});
this.expand();
}
} else {
this.selectedIndex = -1;
this.onLoad();
}
}
},
getParams : function(a) {
var b = {};
if (this.pageSize) {
b.start = 0;
b.limit = this.pageSize
}
return b
},
collapse : function() {
if (!this.isExpanded()) {
return
}
this.list.hide();
Ext.getDoc().un("mousewheel", this.collapseIf, this);
Ext.getDoc().un("mousedown", this.collapseIf, this);
this.fireEvent("collapse", this)
},
collapseIf : function(a) {
if (!a.within(this.wrap) && !a.within(this.list)) {
this.collapse()
}
},
expand : function() {
if (this.isExpanded() || !this.hasFocus) {
return;
}
this.list.alignTo(this.wrap, this.listAlign);
this.list.show();
if (Ext.isGecko2) {
this.innerList.setOverflow('auto');
}
Ext.getDoc().on('mousewheel', this.collapseIf, this);
Ext.getDoc().on('mousedown', this.collapseIf, this);
this.fireEvent('expand', this);
},
//检验
validateValue : function(e) {
if(this.ntype == 1){
if (!Ext.form.ChangeField.superclass.validateValue
.call(this, e)) {
return false
}
if (e.length < 1) {
return true
}
e = String(e).replace(this.decimalSeparator, ".");
if (isNaN(e)) {
this.markInvalid(String.format(this.nanText, e));
return false
}
var a = this.parseValue(e);
if (a < this.minValue) {
this
.markInvalid(String.format(this.minText,
this.minValue));
return false
}
if (a > this.maxValue) {
this
.markInvalid(String.format(this.maxText,
this.maxValue));
return false
}
return true
}
else if(this.ntype == 2){
e = this.formatDate(e);
if (!Ext.form.ChangeField.superclass.validateValue.call(this, e)) {
return false
}
if (e.length < 1) {
return true
}
var c = e;
e = this.parseDate(e);
if (!e) {
this.markInvalid(String.format(this.invalidText, c, this.format));
return false
}
var g = e.getTime();
if (this.minValue && g < this.minValue.getTime()) {
this.markInvalid(String.format(this.minText, this
.formatDate(this.minValue)));
return false
}
if (this.maxValue && g > this.maxValue.getTime()) {
this.markInvalid(String.format(this.maxText, this
.formatDate(this.maxValue)));
return false
}
if (this.disabledDays) {
var a = e.getDay();
for (var b = 0; b < this.disabledDays.length; b++) {
if (a === this.disabledDays[b]) {
this.markInvalid(this.disabledDaysText);
return false
}
}
}
var d = this.formatDate(e);
if (this.disabledDatesRE && this.disabledDatesRE.test(d)) {
this.markInvalid(String.format(this.disabledDatesText, d));
return false
}
return true
}else{
return Ext.form.ChangeField.superclass.validateValue.call(this, e);
}
},validateBlur : function() {
if(this.ntype == 2)
return !this.menu || !this.menu.isVisible()
else if(this.ntype == 3)
return !this.list || !this.list.isVisible()
}
});
Ext.reg('changefield',Ext.form.ChangeField);
// 选择文本类型
var comboType_store = new Ext.data.SimpleStore({
fields : ['value', 'text'],
data : [['0', '文本框'], ['1', '数字框'], ['2', '日期框'], ['3', '选择框']]
});
var comboType = new Ext.form.ComboBox({
name : 'type',
fieldLabel : '文本类型',
store : comboType_store,
triggerAction : 'all',
listWidth : 55,
width : 60,
displayField : 'text',
valueField : 'value',
mode : 'local',
handleHeight : 5,
readOnly : true,
value : 2,
listeners : {
'select' : function(combo, r, index) {
if (r.data.value == 0) {
this.changeType.setNType(0);
} else if (r.data.value == 1) {
this.changeType.setNType(1);
} else if (r.data.value == 2) {
this.changeType.setNType(2);
} else if (r.data.value == 3) {
this.changeType.setNType(3);
}
},
'render' : function(combo) {
this.changeType.setNType(2);
},
scope : this
}
});
this.changeType = new Ext.form.ChangeField({
emptyText : '请输入内容',
format : 'Y-m-d',
hiddenName : "sex",
fieldLabel : "性别",
allowBlank : false,
// msgTarget : "under",
store : new Ext.data.SimpleStore({
// autoDestroy : true,
fields : ['id', 'sex'],
data : [['1', '男'], ['2', '女'], ['3', '保密']]
}),
typeAhead : true,
mode : 'local',
valueField : "id",
displayField : 'sex',
forceSelection : false,
triggerAction : 'all',
resizable : true,
lazyRender : true
});