webgui/www/extras/extjs/package/form/form-debug.js

2697 lines
72 KiB
JavaScript

/*
* Ext JS Library 1.0.1
* Copyright(c) 2006-2007, Ext JS, LLC.
* licensing@extjs.com
*
* http://www.extjs.com/license
*/
Ext.form.Field = function(config){
Ext.form.Field.superclass.constructor.call(this, config);
this.addEvents({
focus : true,
blur : true,
specialkey : true,
change : true,
invalid : true,
valid : true
});
};
Ext.extend(Ext.form.Field, Ext.Component, {
invalidClass : "x-form-invalid",
invalidText : "The value in this field is invalid",
focusClass : "x-form-focus",
validationEvent : "keyup",
validateOnBlur : true,
validationDelay : 250,
defaultAutoCreate : {tag: "input", type: "text", size: "20", autocomplete: "off"},
fieldClass: "x-form-field",
msgTarget: 'qtip',
msgFx : 'normal',
inputType : undefined,
isFormField : true,
hasFocus : false,
value : undefined,
getName: function(){
return this.rendered && this.el.dom.name ? this.el.dom.name : (this.hiddenName || '');
},
applyTo : function(target){
this.target = target;
this.el = Ext.get(target);
this.render(this.el.dom.parentNode);
return this;
},
onRender : function(ct, position){
if(this.el){
this.el = Ext.get(this.el);
if(!this.target){
ct.dom.appendChild(this.el.dom);
}
}else {
var cfg = this.getAutoCreate();
if(!cfg.name){
cfg.name = this.name || this.id;
}
if(this.inputType){
cfg.type = this.inputType;
}
if(this.tabIndex !== undefined){
cfg.tabIndex = this.tabIndex;
}
this.el = ct.createChild(cfg, position);
}
var type = this.el.dom.type;
if(type){
if(type == 'password'){
type = 'text';
}
this.el.addClass('x-form-'+type);
}
if(!this.customSize && (this.width || this.height)){
this.setSize(this.width || "", this.height || "");
}
if(this.readOnly){
this.el.dom.readOnly = true;
}
this.el.addClass([this.fieldClass, this.cls]);
this.initValue();
},
initValue : function(){
if(this.value !== undefined){
this.setValue(this.value);
}else if(this.el.dom.value.length > 0){
this.setValue(this.el.dom.value);
}
},
afterRender : function(){
Ext.form.Field.superclass.afterRender.call(this);
this.initEvents();
},
fireKey : function(e){
if(e.isNavKeyPress()){
this.fireEvent("specialkey", this, e);
}
},
reset : function(){
this.setValue(this.originalValue);
this.clearInvalid();
},
initEvents : function(){
this.el.on(Ext.isIE ? "keydown" : "keypress", this.fireKey, this);
this.el.on("focus", this.onFocus, this);
this.el.on("blur", this.onBlur, this);
this.originalValue = this.getValue();
},
onFocus : function(){
if(!Ext.isOpera){ this.el.addClass(this.focusClass);
}
this.hasFocus = true;
this.startValue = this.getValue();
this.fireEvent("focus", this);
},
onBlur : function(){
this.el.removeClass(this.focusClass);
this.hasFocus = false;
if(this.validationEvent !== false && this.validateOnBlur && this.validationEvent != "blur"){
this.validate();
}
var v = this.getValue();
if(v != this.startValue){
this.fireEvent('change', this, v, this.startValue);
}
this.fireEvent("blur", this);
},
setSize : function(w, h){
if(!this.rendered || !this.el){
this.width = w;
this.height = h;
return;
}
if(w){
w = this.adjustWidth(this.el.dom.tagName, w);
this.el.setWidth(w);
}
if(h){
this.el.setHeight(h);
}
var h = this.el.dom.offsetHeight; },
isValid : function(preventMark){
if(this.disabled){
return true;
}
var restore = this.preventMark;
this.preventMark = preventMark === true;
var v = this.validateValue(this.getRawValue());
this.preventMark = restore;
return v;
},
validate : function(){
if(this.disabled || this.validateValue(this.getRawValue())){
this.clearInvalid();
return true;
}
return false;
},
validateValue : function(value){
return true;
},
markInvalid : function(msg){
if(!this.rendered || this.preventMark){ return;
}
this.el.addClass(this.invalidClass);
msg = msg || this.invalidText;
switch(this.msgTarget){
case 'qtip':
this.el.dom.qtip = msg;
this.el.dom.qclass = 'x-form-invalid-tip';
break;
case 'title':
this.el.dom.title = msg;
break;
case 'under':
if(!this.errorEl){
var elp = this.el.findParent('.x-form-element', 5, true);
this.errorEl = elp.createChild({cls:'x-form-invalid-msg'});
this.errorEl.setWidth(elp.getWidth(true)-20);
}
this.errorEl.update(msg);
Ext.form.Field.msgFx[this.msgFx].show(this.errorEl, this);
break;
case 'side':
if(!this.errorIcon){
var elp = this.el.findParent('.x-form-element', 5, true);
this.errorIcon = elp.createChild({cls:'x-form-invalid-icon'});
}
this.alignErrorIcon();
this.errorIcon.dom.qtip = msg;
this.errorIcon.dom.qclass = 'x-form-invalid-tip';
this.errorIcon.show();
break;
default:
var t = Ext.getDom(this.msgTarget);
t.innerHTML = msg;
t.style.display = this.msgDisplay;
break;
}
this.fireEvent('invalid', this, msg);
},
alignErrorIcon : function(){
this.errorIcon.alignTo(this.el, 'tl-tr', [2, 0]);
},
clearInvalid : function(){
if(!this.rendered || this.preventMark){ return;
}
this.el.removeClass(this.invalidClass);
switch(this.msgTarget){
case 'qtip':
this.el.dom.qtip = '';
break;
case 'title':
this.el.dom.title = '';
break;
case 'under':
if(this.errorEl){
Ext.form.Field.msgFx[this.msgFx].hide(this.errorEl, this);
}
break;
case 'side':
if(this.errorIcon){
this.errorIcon.dom.qtip = '';
this.errorIcon.hide();
}
break;
default:
var t = Ext.getDom(this.msgTarget);
t.innerHTML = '';
t.style.display = 'none';
break;
}
this.fireEvent('valid', this);
},
getRawValue : function(){
return this.el.getValue();
},
getValue : function(){
var v = this.el.getValue();
if(v == this.emptyText || v === undefined){
v = '';
}
return v;
},
setRawValue : function(v){
return this.el.dom.value = v;
},
setValue : function(v){
this.value = v;
if(this.rendered){
this.el.dom.value = v;
this.validate();
}
},
adjustWidth : function(tag, w){
tag = tag.toLowerCase();
if(typeof w == 'number' && Ext.isStrict && !Ext.isSafari){
if(Ext.isIE && (tag == 'input' || tag == 'textarea')){
if(tag == 'input'){
return w + 2;
}
if(tag = 'textarea'){
return w-2;
}
}else if(Ext.isGecko && tag == 'textarea'){
return w-6;
}else if(Ext.isOpera){
if(tag == 'input'){
return w + 2;
}
if(tag = 'textarea'){
return w-2;
}
}
}
return w;
}
});
Ext.form.Field.msgFx = {
normal : {
show: function(msgEl, f){
msgEl.setDisplayed('block');
},
hide : function(msgEl, f){
msgEl.setDisplayed(false).update('');
}
},
slide : {
show: function(msgEl, f){
msgEl.slideIn('t', {stopFx:true});
},
hide : function(msgEl, f){
msgEl.slideOut('t', {stopFx:true,useDisplay:true});
}
},
slideRight : {
show: function(msgEl, f){
msgEl.fixDisplay();
msgEl.alignTo(f.el, 'tl-tr');
msgEl.slideIn('l', {stopFx:true});
},
hide : function(msgEl, f){
msgEl.slideOut('l', {stopFx:true,useDisplay:true});
}
}
};
Ext.form.TextField = function(config){
Ext.form.TextField.superclass.constructor.call(this, config);
this.addEvents({
autosize : true
});
};
Ext.extend(Ext.form.TextField, Ext.form.Field, {
grow : false,
growMin : 30,
growMax : 800,
vtype : null,
maskRe : null,
disableKeyFilter : false,
allowBlank : true,
minLength : 0,
maxLength : Number.MAX_VALUE,
minLengthText : "The minimum length for this field is {0}",
maxLengthText : "The maximum length for this field is {0}",
selectOnFocus : false,
blankText : "This field is required",
validator : null,
regex : null,
regexText : "",
emptyText : null,
emptyClass : 'x-form-empty-field',
initEvents : function(){
Ext.form.TextField.superclass.initEvents.call(this);
if(this.validationEvent == 'keyup'){
this.validationTask = new Ext.util.DelayedTask(this.validate, this);
this.el.on('keyup', this.filterValidation, this);
}
else if(this.validationEvent !== false){
this.el.on(this.validationEvent, this.validate, this, {buffer: this.validationDelay});
}
if(this.selectOnFocus || this.emptyText){
this.on("focus", this.preFocus, this);
if(this.emptyText){
this.on('blur', this.postBlur, this);
this.applyEmptyText();
}
}
if(this.maskRe || (this.vtype && this.disableKeyFilter !== true && (this.maskRe = Ext.form.VTypes[this.vtype+'Mask']))){
this.el.on("keypress", this.filterKeys, this);
}
if(this.grow){
this.el.on("keyup", this.onKeyUp, this, {buffer:50});
this.el.on("click", this.autoSize, this);
}
},
filterValidation : function(e){
if(!e.isNavKeyPress()){
this.validationTask.delay(this.validationDelay);
}
},
onKeyUp : function(e){
if(!e.isNavKeyPress()){
this.autoSize();
}
},
reset : function(){
Ext.form.TextField.superclass.reset.call(this);
this.applyEmptyText();
},
applyEmptyText : function(){
if(this.rendered && this.emptyText && this.getRawValue().length < 1){
this.setRawValue(this.emptyText);
this.el.addClass(this.emptyClass);
}
},
preFocus : function(){
if(this.emptyText){
if(this.getRawValue() == this.emptyText){
this.setRawValue('');
}
this.el.removeClass(this.emptyClass);
}
if(this.selectOnFocus){
this.el.dom.select();
}
},
postBlur : function(){
this.applyEmptyText();
},
filterKeys : function(e){
var k = e.getKey();
if(!Ext.isIE && (e.isNavKeyPress() || k == e.BACKSPACE || (k == e.DELETE && e.button == -1))){
return;
}
var c = e.getCharCode();
if(!this.maskRe.test(String.fromCharCode(c) || '')){
e.stopEvent();
}
},
setValue : function(v){
if(this.emptyText && v !== undefined && v !== null && v !== ''){
this.el.removeClass(this.emptyClass);
}
Ext.form.TextField.superclass.setValue.apply(this, arguments);
},
validateValue : function(value){
if(value.length < 1 || value === this.emptyText){ if(this.allowBlank){
this.clearInvalid();
return true;
}else{
this.markInvalid(this.blankText);
return false;
}
}
if(value.length < this.minLength){
this.markInvalid(String.format(this.minLengthText, this.minLength));
return false;
}
if(value.length > this.maxLength){
this.markInvalid(String.format(this.maxLengthText, this.maxLength));
return false;
}
if(this.vtype){
var vt = Ext.form.VTypes;
if(!vt[this.vtype](value)){
this.markInvalid(this.vtypeText || vt[this.vtype +'Text']);
return false;
}
}
if(typeof this.validator == "function"){
var msg = this.validator(value);
if(msg !== true){
this.markInvalid(msg);
return false;
}
}
if(this.regex && !this.regex.test(value)){
this.markInvalid(this.regexText);
return false;
}
return true;
},
selectText : function(start, end){
var v = this.getRawValue();
if(v.length > 0){
start = start === undefined ? 0 : start;
end = end === undefined ? v.length : end;
var d = this.el.dom;
if(d.setSelectionRange){
d.setSelectionRange(start, end);
}else if(d.createTextRange){
var range = d.createTextRange();
range.moveStart("character", start);
range.moveEnd("character", v.length-end);
range.select();
}
}
},
autoSize : function(){
if(!this.grow || !this.rendered){
return;
}
if(!this.metrics){
this.metrics = Ext.util.TextMetrics.createInstance(this.el);
}
var el = this.el;
var v = el.dom.value + "&#160;";
var w = Math.min(this.growMax, Math.max(this.metrics.getWidth(v) + 10, this.growMin));
this.el.setWidth(w);
this.fireEvent("autosize", this, w);
}
});
Ext.form.TriggerField = function(config){
Ext.form.TriggerField.superclass.constructor.call(this, config);
this.mimicing = false;
this.on('disable', this.disableWrapper, this);
this.on('enable', this.enableWrapper, this);
};
Ext.extend(Ext.form.TriggerField, Ext.form.TextField, {
defaultAutoCreate : {tag: "input", type: "text", size: "16", autocomplete: "off"},
hideTrigger:false,
autoSize: Ext.emptyFn,
monitorTab : true,
customSize : true,
setSize : function(w, h){
if(!this.wrap){
this.width = w;
this.height = h;
return;
}
if(w){
var wrapWidth = w;
w = w - this.trigger.getWidth();
Ext.form.TriggerField.superclass.setSize.call(this, w, h);
this.wrap.setWidth(wrapWidth);
if(this.onResize){
this.onResize(wrapWidth, h);
}
}else{
Ext.form.TriggerField.superclass.setSize.call(this, w, h);
this.wrap.setWidth(this.el.getWidth()+this.trigger.getWidth());
}
},
alignErrorIcon : function(){
this.errorIcon.alignTo(this.wrap, 'tl-tr', [2, 0]);
},
onRender : function(ct, position){
Ext.form.TriggerField.superclass.onRender.call(this, ct, position);
this.wrap = this.el.wrap({cls: "x-form-field-wrap"});
this.trigger = this.wrap.createChild({
tag: "img", src: Ext.BLANK_IMAGE_URL, cls: "x-form-trigger "+this.triggerClass});
this.trigger.on("click", this.onTriggerClick, this, {preventDefault:true});
this.trigger.addClassOnOver('x-form-trigger-over');
this.trigger.addClassOnClick('x-form-trigger-click');
if(this.hideTrigger){
this.trigger.setDisplayed(false);
}
this.setSize(this.width||'', this.height||'');
},
onDestroy : function(){
if(this.trigger){
this.trigger.removeAllListeners();
this.trigger.remove();
}
if(this.wrap){
this.wrap.remove();
}
Ext.form.TriggerField.superclass.onDestroy.call(this);
},
onFocus : function(){
Ext.form.TriggerField.superclass.onFocus.call(this);
if(!this.mimicing){
this.mimicing = true;
Ext.get(Ext.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;
Ext.get(Ext.isIE ? document.body : document).un("mousedown", this.mimicBlur);
if(this.monitorTab){
this.el.un("keydown", this.checkTab, this);
}
Ext.form.TriggerField.superclass.onBlur.call(this);
},
validateBlur : function(e, t){
return true;
},
disableWrapper : function(){
if(this.wrap){
this.wrap.addClass('x-item-disabled');
}
},
enableWrapper : function(){
if(this.wrap){
this.wrap.removeClass('x-item-disabled');
}
},
onShow : function(){
if(this.wrap){
this.wrap.dom.style.display = '';
this.wrap.dom.style.visibility = 'visible';
}
},
onHide : function(){
this.wrap.dom.style.display = 'none';
},
onTriggerClick : Ext.emptyFn
});
Ext.form.TextArea = function(config){
Ext.form.TextArea.superclass.constructor.call(this, config);
if(this.minHeight !== undefined){
this.growMin = this.minHeight;
}
if(this.maxHeight !== undefined){
this.growMax = this.maxHeight;
}
};
Ext.extend(Ext.form.TextArea, Ext.form.TextField, {
growMin : 60,
growMax: 1000,
preventScrollbars: false,
onRender : function(ct, position){
if(!this.el){
this.defaultAutoCreate = {
tag: "textarea",
style:"width:300px;height:60px;",
autocomplete: "off"
};
}
Ext.form.TextArea.superclass.onRender.call(this, ct, position);
if(this.grow){
this.textSizeEl = Ext.DomHelper.append(document.body, {
tag: "pre", cls: "x-form-grow-sizer"
});
if(this.preventScrollbars){
this.el.setStyle("overflow", "hidden");
}
this.el.setHeight(this.growMin);
}
},
onKeyUp : function(e){
if(!e.isNavKeyPress() || e.getKey() == e.ENTER){
this.autoSize();
}
},
autoSize : function(){
if(!this.grow || !this.textSizeEl){
return;
}
var el = this.el;
var v = el.dom.value;
var ts = this.textSizeEl;
Ext.fly(ts).setWidth(this.el.getWidth());
if(v.length < 1){
v = "&#160;&#160;";
}else{
v += "&#160;\n&#160;";
}
if(Ext.isIE){
v = v.replace(/\n/g, '<br />');
}
ts.innerHTML = v;
var h = Math.min(this.growMax, Math.max(ts.offsetHeight, this.growMin));
if(h != this.lastHeight){
this.lastHeight = h;
this.el.setHeight(h);
this.fireEvent("autosize", this, h);
}
},
setValue : function(v){
Ext.form.TextArea.superclass.setValue.call(this, v);
this.autoSize();
}
});
Ext.form.NumberField = function(config){
Ext.form.NumberField.superclass.constructor.call(this, config);
};
Ext.extend(Ext.form.NumberField, Ext.form.TextField, {
fieldClass: "x-form-field x-form-num-field",
allowDecimals : true,
decimalSeparator : ".",
decimalPrecision : 2,
allowNegative : true,
minValue : Number.NEGATIVE_INFINITY,
maxValue : Number.MAX_VALUE,
minText : "The minimum value for this field is {0}",
maxText : "The maximum value for this field is {0}",
nanText : "{0} is not a valid number",
initEvents : function(){
Ext.form.NumberField.superclass.initEvents.call(this);
var allowed = "0123456789";
if(this.allowDecimals){
allowed += this.decimalSeparator;
}
if(this.allowNegative){
allowed += "-";
}
var keyPress = function(e){
var k = e.getKey();
if(!Ext.isIE && (e.isNavKeyPress() || k == e.BACKSPACE || (k == e.DELETE && e.button == -1))){
return;
}
var c = e.getCharCode();
if(allowed.indexOf(String.fromCharCode(c)) === -1){
e.stopEvent();
}
};
this.el.on("keypress", keyPress, this);
},
validateValue : function(value){
if(!Ext.form.NumberField.superclass.validateValue.call(this, value)){
return false;
}
if(value.length < 1){ return true;
}
value = String(value).replace(this.decimalSeparator, ".");
if(isNaN(value)){
this.markInvalid(String.format(this.nanText, value));
return false;
}
var num = this.parseValue(value);
if(num < this.minValue){
this.markInvalid(String.format(this.minText, this.minValue));
return false;
}
if(num > this.maxValue){
this.markInvalid(String.format(this.maxText, this.maxValue));
return false;
}
return true;
},
parseValue : function(value){
return parseFloat(String(value).replace(this.decimalSeparator, "."));
},
fixPrecision : function(value){
if(!this.allowDecimals || this.decimalPrecision == -1 || isNaN(value) || value == 0 || !value){
return value;
}
var scale = Math.pow(10, this.decimalPrecision+1);
var fixed = this.decimalPrecisionFcn(value * scale);
fixed = this.decimalPrecisionFcn(fixed/10);
return fixed / (scale/10);
},
decimalPrecisionFcn : function(v){
return Math.floor(v);
}
});
Ext.form.DateField = function(config){
Ext.form.DateField.superclass.constructor.call(this, config);
if(typeof this.minValue == "string") this.minValue = this.parseDate(this.minValue);
if(typeof this.maxValue == "string") this.maxValue = this.parseDate(this.maxValue);
this.ddMatch = null;
if(this.disabledDates){
var dd = this.disabledDates;
var re = "(?:";
for(var i = 0; i < dd.length; i++){
re += dd[i];
if(i != dd.length-1) re += "|";
}
this.ddMatch = new RegExp(re + ")");
}
};
Ext.extend(Ext.form.DateField, Ext.form.TriggerField, {
format : "m/d/y",
disabledDays : null,
disabledDaysText : "Disabled",
disabledDates : null,
disabledDatesText : "Disabled",
minValue : null,
maxValue : null,
minText : "The date in this field must be after {0}",
maxText : "The date in this field must be before {0}",
invalidText : "{0} is not a valid date - it must be in the format {1}",
triggerClass : 'x-form-date-trigger',
defaultAutoCreate : {tag: "input", type: "text", size: "10", autocomplete: "off"},
validateValue : function(value){
value = this.formatDate(value);
if(!Ext.form.DateField.superclass.validateValue.call(this, value)){
return false;
}
if(value.length < 1){ return true;
}
var svalue = value;
value = this.parseDate(value);
if(!value){
this.markInvalid(String.format(this.invalidText, svalue, this.format));
return false;
}
var time = value.getTime();
if(this.minValue && time < this.minValue.getTime()){
this.markInvalid(String.format(this.minText, this.formatDate(this.minValue)));
return false;
}
if(this.maxValue && time > this.maxValue.getTime()){
this.markInvalid(String.format(this.maxText, this.formatDate(this.maxValue)));
return false;
}
if(this.disabledDays){
var day = value.getDay();
for(var i = 0; i < this.disabledDays.length; i++) {
if(day === this.disabledDays[i]){
this.markInvalid(this.disabledDaysText);
return false;
}
}
}
var fvalue = this.formatDate(value);
if(this.ddMatch && this.ddMatch.test(fvalue)){
this.markInvalid(String.format(this.disabledDatesText, fvalue));
return false;
}
return true;
},
validateBlur : function(){
return !this.menu || !this.menu.isVisible();
},
getValue : function(){
return this.parseDate(Ext.form.DateField.superclass.getValue.call(this)) || "";
},
setValue : function(date){
Ext.form.DateField.superclass.setValue.call(this, this.formatDate(this.parseDate(date)));
},
parseDate : function(value){
return (!value || value instanceof Date) ?
value : Date.parseDate(value, this.format);
},
formatDate : function(date){
return (!date || !(date instanceof Date)) ?
date : date.dateFormat(this.format);
},
menuListeners : {
select: function(m, d){
this.setValue(d);
},
show : function(){ this.onFocus();
},
hide : function(){
this.focus();
var ml = this.menuListeners;
this.menu.un("select", ml.select, this);
this.menu.un("show", ml.show, this);
this.menu.un("hide", ml.hide, this);
}
},
onTriggerClick : function(){
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.ddMatch,
disabledDatesText : this.disabledDatesText,
disabledDays : this.disabledDays,
disabledDaysText : this.disabledDaysText,
format : this.format,
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?");
}
});
Ext.form.Checkbox = function(config){
Ext.form.Checkbox.superclass.constructor.call(this, config);
this.addEvents({
check : true
});
};
Ext.extend(Ext.form.Checkbox, Ext.form.Field, {
focusClass : "x-form-check-focus",
fieldClass: "x-form-field",
checked: false,
defaultAutoCreate : { tag: "input", type: 'checkbox', autocomplete: "off"},
boxLabel : undefined,
setSize : function(w, h){
if(!this.wrap){
this.width = w;
this.height = h;
return;
}
this.wrap.setSize(w, h);
if(!this.boxLabel){
this.el.alignTo(this.wrap, 'c-c');
}
},
initEvents : function(){
Ext.form.Checkbox.superclass.initEvents.call(this);
this.el.on("click", this.onClick, this);
this.el.on("change", this.onClick, this);
},
onRender : function(ct, position){
Ext.form.Checkbox.superclass.onRender.call(this, ct, position);
if(this.inputValue !== undefined){
this.el.dom.value = this.inputValue;
}
this.wrap = this.el.wrap({cls: "x-form-check-wrap"});
if(this.boxLabel){
this.wrap.createChild({tag: 'label', htmlFor: this.el.id, cls: 'x-form-cb-label', html: this.boxLabel});
}
if(this.checked){
this.setValue(true);
}
},
initValue : Ext.emptyFn,
getValue : function(){
if(this.rendered){
return this.el.dom.checked;
}
return false;
},
onClick : function(){
if(this.el.dom.checked != this.checked){
this.setValue(this.el.dom.checked);
}
},
setValue : function(v){
this.checked = (v === true || v === 'true' || v == '1');
if(this.el && this.el.dom){
this.el.dom.checked = this.checked;
}
this.fireEvent("check", this, this.checked);
}
});
Ext.form.Radio = function(){
Ext.form.Radio.superclass.constructor.apply(this, arguments);
};
Ext.extend(Ext.form.Radio, Ext.form.Checkbox, {
inputType: 'radio'
});
Ext.form.ComboBox = function(config){
Ext.form.ComboBox.superclass.constructor.call(this, config);
this.addEvents({
'expand' : true,
'collapse' : true,
'beforeselect' : true,
'select' : true,
'beforequery': true
});
if(this.transform){
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];
var value = (Ext.isIE ? o.getAttributeNode('value').specified : o.hasAttribute('value')) ? 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);
s.parentNode.removeChild(s); this.render(this.el.parentNode);
}else{
s.parentNode.removeChild(s); }
}
this.selectedIndex = -1;
if(this.mode == 'local'){
if(config.queryDelay === undefined){
this.queryDelay = 10;
}
if(config.minChars === undefined){
this.minChars = 0;
}
}
};
Ext.extend(Ext.form.ComboBox, Ext.form.TriggerField, {
defaultAutoCreate : {tag: "input", type: "text", size: "24", autocomplete: "off"},
listWidth: undefined,
displayField: undefined,
valueField: undefined,
hiddenName: undefined,
listClass: '',
selectedClass: 'x-combo-selected',
triggerClass : 'x-form-arrow-trigger',
shadow:'sides',
listAlign: 'tl-bl?',
maxHeight: 300,
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,
valueNotFoundText : undefined,
onRender : function(ct, position){
Ext.form.ComboBox.superclass.onRender.call(this, ct, position);
if(this.hiddenName){
this.hiddenField = this.el.insertSibling({tag:'input', type:'hidden', name: this.hiddenName, id: this.hiddenName},
'before', true);
this.hiddenField.value =
this.hiddenValue !== undefined ? this.hiddenValue :
this.value !== undefined ? this.value : '';
this.el.dom.removeAttribute('name');
}
if(Ext.isGecko){
this.el.dom.setAttribute('autocomplete', 'off');
}
var cls = 'x-combo-list';
this.list = new Ext.Layer({
shadow: this.shadow, cls: [cls, this.listClass].join(' '), constrain:false
});
this.list.setWidth(this.listWidth || Math.max(this.wrap.getWidth(), this.minListWidth));
this.list.swallowEvent('mousewheel');
this.assetHeight = 0;
if(this.title){
this.header = this.list.createChild({cls:cls+'-hd', html: this.title});
this.assetHeight += this.header.getHeight();
}
this.innerList = this.list.createChild({cls:cls+'-inner'});
this.innerList.on('mouseover', this.onViewOver, this);
this.innerList.on('mousemove', this.onViewMove, this);
if(this.pageSize){
this.footer = this.list.createChild({cls:cls+'-ft'});
this.pageTb = new Ext.PagingToolbar(this.footer, this.store,
{pageSize: this.pageSize});
this.assetHeight += this.footer.getHeight();
}
if(!this.tpl){
this.tpl = '<div class="'+cls+'-item">{' + this.displayField + '}</div>';
}
this.view = new Ext.View(this.innerList, this.tpl, {
singleSelect:true, store: this.store, selectedClass: this.selectedClass
});
this.view.on('click', this.onViewClick, this);
this.store.on('beforeload', this.onBeforeLoad, this);
this.store.on('load', this.onLoad, this);
this.store.on('loadexception', this.collapse, this);
if(this.resizable){
this.resizer = new Ext.Resizable(this.list, {
pinned:true, handles:'se'
});
this.resizer.on('resize', function(r, w, h){
this.maxHeight = h-this.handleHeight-this.list.getFrameWidth('tb')-this.assetHeight;
this.listWidth = w;
this.restrictHeight();
}, this);
this[this.pageSize?'footer':'innerList'].setStyle('margin-bottom', this.handleHeight+'px');
}
if(!this.editable){
this.editable = true;
this.setEditable(false);
}
},
initEvents : function(){
Ext.form.ComboBox.superclass.initEvents.call(this);
this.keyNav = new Ext.KeyNav(this.el, {
"up" : function(e){
this.inKeyMode = true;
this.selectPrev();
},
"down" : function(e){
if(!this.isExpanded()){
this.onTriggerClick();
}else{
this.inKeyMode = true;
this.selectNext();
}
},
"enter" : function(e){
this.onViewClick();
},
"esc" : function(e){
this.collapse();
},
"tab" : function(e){
this.onViewClick(false);
return true;
},
scope : this,
doRelay : function(foo, bar, hname){
if(hname == 'down' || this.scope.isExpanded()){
return Ext.KeyNav.prototype.doRelay.apply(this, arguments);
}
return true;
}
});
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.el.on("keyup", this.onKeyUp, this);
}
if(this.forceSelection){
this.on('blur', this.doForce, this);
}
},
onDestroy : function(){
if(this.view){
this.view.setStore(null);
this.view.el.removeAllListeners();
this.view.el.remove();
this.view.purgeListeners();
}
if(this.list){
this.list.destroy();
}
if(this.store){
this.store.un('beforeload', this.onBeforeLoad, this);
this.store.un('load', this.onLoad, this);
this.store.un('loadexception', this.collapse, this);
}
Ext.form.ComboBox.superclass.onDestroy.call(this);
},
fireKey : function(e){
if(e.isNavKeyPress() && !this.list.isVisible()){
this.fireEvent("specialkey", this, e);
}
},
onResize: function(w, h){
if(this.list && this.listWidth === undefined){
this.list.setWidth(Math.max(w, this.minListWidth));
}
},
setEditable : function(value){
if(value == this.editable){
return;
}
this.editable = value;
if(!value){
this.el.dom.setAttribute('readOnly', true);
this.el.on('mousedown', this.onTriggerClick, this);
this.el.addClass('x-combo-noedit');
}else{
this.el.dom.setAttribute('readOnly', false);
this.el.un('mousedown', this.onTriggerClick, this);
this.el.removeClass('x-combo-noedit');
}
},
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.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 r = this.store.getAt(0);
var newValue = r.data[this.displayField];
var len = newValue.length;
var selStart = this.getRawValue().length;
if(selStart != len){
this.setRawValue(newValue);
this.selectText(selStart, newValue.length);
}
}
},
onSelect : function(record, index){
if(this.fireEvent('beforeselect', this, record, index) !== false){
this.setValue(record.data[this.valueField || this.displayField]);
this.collapse();
this.fireEvent('select', this, record, index);
}
},
getValue : function(){
if(this.valueField){
return typeof this.value != 'undefined' ? this.value : '';
}else{
return Ext.form.ComboBox.superclass.getValue.call(this);
}
},
clearValue : function(){
if(this.hiddenField){
this.hiddenField.value = '';
}
this.setRawValue('');
this.lastSelectionText = '';
},
setValue : function(v){
var text = v;
if(this.valueField){
var r = this.findRecord(this.valueField, v);
if(r){
text = r.data[this.displayField];
}else if(this.valueNotFoundText){
text = this.valueNotFoundText;
}
}
this.lastSelectionText = text;
if(this.hiddenField){
this.hiddenField.value = v;
}
Ext.form.ComboBox.superclass.setValue.call(this, text);
this.value = v;
},
findRecord : function(prop, value){
var record;
if(this.store.getCount() > 0){
this.store.each(function(r){
if(r.data[prop] == value){
record = r;
return false;
}
});
}
return record;
},
onViewMove : function(e, t){
this.inKeyMode = false;
},
onViewOver : function(e, t){
if(this.inKeyMode){ return;
}
var item = this.view.findItemFromChild(t);
if(item){
var index = this.view.indexOf(item);
this.select(index, false);
}
},
onViewClick : function(doFocus){
var index = this.view.getSelectedIndexes()[0];
var r = this.store.getAt(index);
if(r){
this.onSelect(r, index);
}
if(doFocus !== false){
this.el.focus();
}
},
restrictHeight : function(){
this.innerList.dom.style.height = '';
var inner = this.innerList.dom;
var h = Math.max(inner.clientHeight, inner.offsetHeight, inner.scrollHeight);
this.innerList.setHeight(h < this.maxHeight ? 'auto' : this.maxHeight);
this.list.beginUpdate();
this.list.setHeight(this.innerList.getHeight()+this.list.getFrameWidth('tb')+(this.resizable?this.handleHeight:0)+this.assetHeight);
this.list.alignTo(this.el, this.listAlign);
this.list.endUpdate();
},
onEmptyResults : function(){
this.collapse();
},
isExpanded : function(){
return this.list.isVisible();
},
selectByValue : function(v, scrollIntoView){
if(v !== undefined && v !== null){
var r = this.findRecord(this.valueField || this.displayField, v);
if(r){
this.select(this.store.indexOf(r), scrollIntoView);
return true;
}
}
return false;
},
select : function(index, scrollIntoView){
this.selectedIndex = index;
this.view.select(index);
if(scrollIntoView !== false){
var el = this.view.getNode(index);
if(el){
this.innerList.scrollChildIntoView(el);
}
}
},
selectNext : function(){
var ct = this.store.getCount();
if(ct > 0){
if(this.selectedIndex == -1){
this.select(0);
}else if(this.selectedIndex < ct-1){
this.select(this.selectedIndex+1);
}
}
},
selectPrev : function(){
var ct = this.store.getCount();
if(ct > 0){
if(this.selectedIndex == -1){
this.select(0);
}else if(this.selectedIndex != 0){
this.select(this.selectedIndex-1);
}
}
},
onKeyUp : function(e){
if(this.editable !== false && !e.isSpecialKey()){
this.lastKey = e.getKey();
this.dqTask.delay(this.queryDelay);
}
},
validateBlur : function(){
return !this.list || !this.list.isVisible();
},
initQuery : function(){
this.doQuery(this.getRawValue());
},
doForce : function(){
if(this.el.dom.value.length > 0){
this.el.dom.value =
this.lastSelectionText === undefined ? '' : this.lastSelectionText;
this.applyEmptyText();
}
},
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(q){
var p = {};
if(this.pageSize){
p.start = 0;
p.limit = this.pageSize;
}
return p;
},
collapse : function(){
if(!this.isExpanded()){
return;
}
this.list.hide();
Ext.get(document).un('mousedown', this.collapseIf, this);
this.fireEvent('collapse', this);
},
collapseIf : function(e){
if(!e.within(this.wrap) && !e.within(this.list)){
this.collapse();
}
},
expand : function(){
if(this.isExpanded() || !this.hasFocus){
return;
}
this.list.alignTo(this.el, this.listAlign);
this.list.show();
Ext.get(document).on('mousedown', this.collapseIf, this);
this.fireEvent('expand', this);
},
onTriggerClick : function(){
if(this.disabled){
return;
}
if(this.isExpanded()){
this.collapse();
this.el.focus();
}else{
this.hasFocus = true;
this.doQuery(this.triggerAction == 'all' ?
this.doQuery(this.allQuery, true) : this.doQuery(this.getRawValue()));
this.el.focus();
}
}
});
Ext.Editor = function(field, config){
Ext.Editor.superclass.constructor.call(this, config);
this.field = field;
this.addEvents({
"beforestartedit" : true,
"startedit" : true,
"beforecomplete" : true,
"complete" : true,
"specialkey" : true
});
};
Ext.extend(Ext.Editor, Ext.Component, {
value : "",
alignment: "c-c?",
shadow : "frame",
updateEl : false,
onRender : function(ct, position){
this.el = new Ext.Layer({
shadow: this.shadow,
cls: "x-editor",
parentEl : ct,
shim : this.shim,
shadowOffset:3,
id: this.id
});
this.el.setStyle("overflow", Ext.isGecko ? "auto" : "hidden");
this.field.render(this.el);
if(Ext.isGecko){
this.field.el.dom.setAttribute('autocomplete', 'off');
}
this.field.show();
this.field.on("blur", this.onBlur, this);
this.relayEvents(this.field, ["specialkey"]);
if(this.field.grow){
this.field.on("autosize", this.el.sync, this.el, {delay:1});
}
},
startEdit : function(el, value){
if(this.editing){
this.completeEdit();
}
this.boundEl = Ext.get(el);
var v = value !== undefined ? value : this.boundEl.dom.innerHTML;
if(!this.rendered){
this.render(this.parentEl || document.body);
}
if(this.fireEvent("beforestartedit", this, this.boundEl, v) === false){
return;
}
this.startValue = v;
this.field.setValue(v);
if(this.autoSize){
var sz = this.boundEl.getSize();
switch(this.autoSize){
case "width":
this.setSize(sz.width, "");
break;
case "height":
this.setSize("", sz.height);
break;
default:
this.setSize(sz.width, sz.height);
}
}
this.el.alignTo(this.boundEl, this.alignment);
this.editing = true;
if(Ext.QuickTips){
Ext.QuickTips.disable();
}
this.show();
},
setSize : function(w, h){
this.field.setSize(w, h);
if(this.el){
this.el.sync();
}
},
realign : function(){
this.el.alignTo(this.boundEl, this.alignment);
},
completeEdit : function(remainVisible){
if(!this.editing){
return;
}
var v = this.getValue();
if(this.revertInvalid !== false && !this.field.isValid()){
v = this.startValue;
this.cancelEdit(true);
}
if(String(v) == String(this.startValue) && this.ignoreNoChange){
this.editing = false;
this.hide();
return;
}
if(this.fireEvent("beforecomplete", this, v, this.startValue) !== false){
this.editing = false;
if(this.updateEl && this.boundEl){
this.boundEl.update(v);
}
if(remainVisible !== true){
this.hide();
}
this.fireEvent("complete", this, v, this.startValue);
}
},
onShow : function(){
this.el.show();
if(this.hideEl !== false){
this.boundEl.hide();
}
this.field.show();
this.field.focus();
this.fireEvent("startedit", this.boundEl, this.startValue);
},
cancelEdit : function(remainVisible){
if(this.editing){
this.setValue(this.startValue);
if(remainVisible !== true){
this.hide();
}
}
},
onBlur : function(){
if(this.allowBlur !== true && this.editing){
this.completeEdit();
}
},
onHide : function(){
if(this.editing){
this.completeEdit();
return;
}
this.field.blur();
if(this.field.collapse){
this.field.collapse();
}
this.el.hide();
if(this.hideEl !== false){
this.boundEl.show();
}
if(Ext.QuickTips){
Ext.QuickTips.enable();
}
},
setValue : function(v){
this.field.setValue(v);
},
getValue : function(){
return this.field.getValue();
}
});
Ext.form.BasicForm = function(el, config){
Ext.apply(this, config);
this.items = new Ext.util.MixedCollection(false, function(o){
return o.id || (o.id = Ext.id());
});
this.addEvents({
beforeaction: true,
actionfailed : true,
actioncomplete : true
});
if(el){
this.initEl(el);
}
Ext.form.BasicForm.superclass.constructor.call(this);
};
Ext.extend(Ext.form.BasicForm, Ext.util.Observable, {
timeout: 30,
activeAction : null,
waitMsgTarget : undefined,
initEl : function(el){
this.el = Ext.get(el);
this.id = this.el.id || Ext.id();
this.el.on('submit', this.onSubmit, this);
this.el.addClass('x-form');
},
onSubmit : function(e){
e.stopEvent();
},
isValid : function(){
var valid = true;
this.items.each(function(f){
if(!f.validate()){
valid = false;
}
});
return valid;
},
doAction : function(action, options){
if(typeof action == 'string'){
action = new Ext.form.Action.ACTION_TYPES[action](this, options);
}
if(this.fireEvent('beforeaction', this, action) !== false){
this.beforeAction(action);
action.run.defer(100, action);
}
},
submit : function(options){
this.doAction('submit', options);
},
load : function(options){
this.doAction('load', options);
},
updateRecord : function(record){
record.beginEdit();
var fs = record.fields;
fs.each(function(f){
var field = this.findField(f.name);
if(field){
record.set(f.name, field.getValue());
}
}, this);
record.endEdit();
},
beforeAction : function(action){
var o = action.options;
if(o.waitMsg){
if(this.waitMsgTarget === true){
this.el.mask(o.waitMsg, 'x-mask-loading');
}else if(this.waitMsgTarget){
this.waitMsgTarget = Ext.get(this.waitMsgTarget);
this.waitMsgTarget.mask(o.waitMsg, 'x-mask-loading');
}else{
Ext.MessageBox.wait(o.waitMsg, o.waitTitle || this.waitTitle || 'Please Wait...');
}
}
},
afterAction : function(action, success){
this.activeAction = null;
var o = action.options;
if(o.waitMsg){
if(this.waitMsgTarget === true){
this.el.unmask();
}else if(this.waitMsgTarget){
this.waitMsgTarget.unmask();
}else{
Ext.MessageBox.updateProgress(1);
Ext.MessageBox.hide();
}
}
if(success){
if(o.reset){
this.reset();
}
Ext.callback(o.success, o.scope, [this, action]);
this.fireEvent('actioncomplete', this, action);
}else{
Ext.callback(o.failure, o.scope, [this, action]);
this.fireEvent('actionfailed', this, action);
}
},
findField : function(id){
var field = this.items.get(id);
if(!field){
this.items.each(function(f){
if(f.isFormField && (f.dataIndex == id || f.id == id || f.getName() == id)){
field = f;
return false;
}
});
}
return field || null;
},
markInvalid : function(errors){
if(errors instanceof Array){
for(var i = 0, len = errors.length; i < len; i++){
var fieldError = errors[i];
var f = this.findField(fieldError.id);
if(f){
f.markInvalid(fieldError.msg);
}
}
}else{
var field, id;
for(id in errors){
if(typeof errors[id] != 'function' && (field = this.findField(id))){
field.markInvalid(errors[id]);
}
}
}
},
setValues : function(values){
if(values instanceof Array){ for(var i = 0, len = values.length; i < len; i++){
var v = values[i];
var f = this.findField(v.id);
if(f){
f.setValue(v.value);
}
}
}else{ var field, id;
for(id in values){
if(typeof values[id] != 'function' && (field = this.findField(id))){
field.setValue(values[id]);
}
}
}
},
getValues : function(asString){
var fs = Ext.lib.Ajax.serializeForm(this.el.dom);
if(asString === true){
return fs;
}
return Ext.urlDecode(fs);
},
clearInvalid : function(){
this.items.each(function(f){
f.clearInvalid();
});
},
reset : function(){
this.items.each(function(f){
f.reset();
});
},
add : function(){
this.items.addAll(Array.prototype.slice.call(arguments, 0));
},
remove : function(field){
this.items.remove(field);
},
render : function(){
this.items.each(function(f){
if(f.isFormField && !f.rendered && document.getElementById(f.id)){ f.applyTo(f.id);
}
});
},
applyToFields : function(o){
this.items.each(function(f){
Ext.apply(f, o);
});
},
applyIfToFields : function(o){
this.items.each(function(f){
Ext.applyIf(f, o);
});
}
});
Ext.BasicForm = Ext.form.BasicForm;
Ext.form.Form = function(config){
Ext.form.Form.superclass.constructor.call(this, null, config);
this.url = this.url || this.action;
if(!this.root){
this.root = new Ext.form.Layout(Ext.applyIf({
id: Ext.id()
}, config));
}
this.active = this.root;
this.buttons = [];
this.addEvents({
clientvalidation: true
});
};
Ext.extend(Ext.form.Form, Ext.form.BasicForm, {
buttonAlign:'center',
minButtonWidth:75,
labelAlign:'left',
monitorValid : false,
monitorPoll : 200,
column : function(c){
var col = new Ext.form.Column(c);
this.start(col);
if(arguments.length > 1){ this.add.apply(this, Array.prototype.slice.call(arguments, 1));
this.end();
}
return col;
},
fieldset : function(c){
var fs = new Ext.form.FieldSet(c);
this.start(fs);
if(arguments.length > 1){ this.add.apply(this, Array.prototype.slice.call(arguments, 1));
this.end();
}
return fs;
},
container : function(c){
var l = new Ext.form.Layout(c);
this.start(l);
if(arguments.length > 1){ this.add.apply(this, Array.prototype.slice.call(arguments, 1));
this.end();
}
return l;
},
start : function(c){
Ext.applyIf(c, {'labelAlign': this.active.labelAlign, 'labelWidth': this.active.labelWidth, 'itemCls': this.active.itemCls});
this.active.stack.push(c);
c.ownerCt = this.active;
this.active = c;
return this;
},
end : function(){
if(this.active == this.root){
return this;
}
this.active = this.active.ownerCt;
return this;
},
add : function(){
this.active.stack.push.apply(this.active.stack, arguments);
var r = [];
for(var i = 0, a = arguments, len = a.length; i < len; i++) {
if(a[i].isFormField){
r.push(a[i]);
}
}
if(r.length > 0){
Ext.form.Form.superclass.add.apply(this, r);
}
return this;
},
render : function(ct){
ct = Ext.get(ct);
var o = this.autoCreate || {
tag: 'form',
method : this.method || 'POST',
id : this.id || Ext.id()
};
this.initEl(ct.createChild(o));
this.root.render(this.el);
this.items.each(function(f){
f.render('x-form-el-'+f.id);
});
if(this.buttons.length > 0){
var tb = this.el.createChild({cls:'x-form-btns-ct', cn: {
cls:"x-form-btns x-form-btns-"+this.buttonAlign,
html:'<table cellspacing="0"><tbody><tr></tr></tbody></table><div class="x-clear"></div>'
}}, null, true);
var tr = tb.getElementsByTagName('tr')[0];
for(var i = 0, len = this.buttons.length; i < len; i++) {
var b = this.buttons[i];
var td = document.createElement('td');
td.className = 'x-form-btn-td';
b.render(tr.appendChild(td));
}
}
if(this.monitorValid){ this.startMonitoring();
}
return this;
},
addButton : function(config, handler, scope){
var bc = {
handler: handler,
scope: scope,
minWidth: this.minButtonWidth,
hideParent:true
};
if(typeof config == "string"){
bc.text = config;
}else{
Ext.apply(bc, config);
}
var btn = new Ext.Button(null, bc);
this.buttons.push(btn);
return btn;
},
startMonitoring : function(){
if(!this.bound){
this.bound = true;
Ext.TaskMgr.start({
run : this.bindHandler,
interval : this.monitorPoll || 200,
scope: this
});
}
},
stopMonitoring : function(){
this.bound = false;
},
bindHandler : function(){
if(!this.bound){
return false; }
var valid = true;
this.items.each(function(f){
if(!f.isValid(true)){
valid = false;
return false;
}
});
for(var i = 0, len = this.buttons.length; i < len; i++){
var btn = this.buttons[i];
if(btn.formBind === true && btn.disabled === valid){
btn.setDisabled(!valid);
}
}
this.fireEvent('clientvalidation', this, valid);
}
});
Ext.Form = Ext.form.Form;
Ext.form.Action = function(form, options){
this.form = form;
this.options = options || {};
};
Ext.form.Action.CLIENT_INVALID = 'client';
Ext.form.Action.SERVER_INVALID = 'server';
Ext.form.Action.CONNECT_FAILURE = 'connect';
Ext.form.Action.LOAD_FAILURE = 'load';
Ext.form.Action.prototype = {
type : 'default',
failureType : undefined,
response : undefined,
result : undefined,
run : function(options){
},
success : function(response){
},
handleResponse : function(response){
},
failure : function(response){
this.response = response;
this.failureType = Ext.form.Action.CONNECT_FAILURE;
this.form.afterAction(this, false);
},
processResponse : function(response){
this.response = response;
if(!response.responseText){
return true;
}
this.result = this.handleResponse(response);
return this.result;
},
getUrl : function(appendParams){
var url = this.options.url || this.form.url || this.form.el.dom.action;
if(appendParams){
var p = this.getParams();
if(p){
url += (url.indexOf('?') != -1 ? '&' : '?') + p;
}
}
return url;
},
getMethod : function(){
return (this.options.method || this.form.method || this.form.el.dom.method || 'POST').toUpperCase();
},
getParams : function(){
var bp = this.form.baseParams;
var p = this.options.params;
if(p){
if(typeof p == "object"){
p = Ext.urlEncode(Ext.applyIf(p, bp));
}else if(typeof p == 'string' && bp){
p += '&' + Ext.urlEncode(bp);
}
}else if(bp){
p = Ext.urlEncode(bp);
}
return p;
},
createCallback : function(){
return {
success: this.success,
failure: this.failure,
scope: this,
timeout: (this.form.timeout*1000),
upload: this.form.fileUpload ? this.success : undefined
};
}
};
Ext.form.Action.Submit = function(form, options){
Ext.form.Action.Submit.superclass.constructor.call(this, form, options);
};
Ext.extend(Ext.form.Action.Submit, Ext.form.Action, {
type : 'submit',
run : function(){
var o = this.options;
var isPost = this.getMethod() == 'POST';
if(o.clientValidation === false || this.form.isValid()){
Ext.lib.Ajax.formRequest(
this.form.el.dom,
this.getUrl(!isPost),
this.createCallback(),
isPost ? this.getParams() : null, this.form.fileUpload, Ext.SSL_SECURE_URL);
}else if (o.clientValidation !== false){ this.failureType = Ext.form.Action.CLIENT_INVALID;
this.form.afterAction(this, false);
}
},
success : function(response){
var result = this.processResponse(response);
if(result === true || result.success){
this.form.afterAction(this, true);
return;
}
if(result.errors){
this.form.markInvalid(result.errors);
this.failureType = Ext.form.Action.SERVER_INVALID;
}
this.form.afterAction(this, false);
},
handleResponse : function(response){
if(this.form.errorReader){
var rs = this.form.errorReader.read(response);
var errors = [];
if(rs.records){
for(var i = 0, len = rs.records.length; i < len; i++) {
var r = rs.records[i];
errors[i] = r.data;
}
}
if(errors.length < 1){
errors = null;
}
return {
success : rs.success,
errors : errors
};
}
return Ext.decode(response.responseText);
}
});
Ext.form.Action.Load = function(form, options){
Ext.form.Action.Load.superclass.constructor.call(this, form, options);
this.reader = this.form.reader;
};
Ext.extend(Ext.form.Action.Load, Ext.form.Action, {
type : 'load',
run : function(){
Ext.lib.Ajax.request(
this.getMethod(),
this.getUrl(false),
this.createCallback(),
this.getParams());
},
success : function(response){
var result = this.processResponse(response);
if(result === true || !result.success || !result.data){
this.failureType = Ext.form.Action.LOAD_FAILURE;
this.form.afterAction(this, false);
return;
}
this.form.clearInvalid();
this.form.setValues(result.data);
this.form.afterAction(this, true);
},
handleResponse : function(response){
if(this.form.reader){
var rs = this.form.reader.read(response);
var data = rs.records && rs.records[0] ? rs.records[0].data : null;
return {
success : rs.success,
data : data
};
}
return Ext.decode(response.responseText);
}
});
Ext.form.Action.ACTION_TYPES = {
'load' : Ext.form.Action.Load,
'submit' : Ext.form.Action.Submit
};
Ext.form.Layout = function(config){
Ext.form.Layout.superclass.constructor.call(this, config);
this.stack = [];
};
Ext.extend(Ext.form.Layout, Ext.Component, {
clear : true,
labelSeparator : ':',
hideLabels : false,
defaultAutoCreate : {tag: 'div', cls: 'x-form-ct'},
onRender : function(ct, position){
if(this.el){ this.el = Ext.get(this.el);
}else { var cfg = this.getAutoCreate();
this.el = ct.createChild(cfg, position);
}
if(this.style){
this.el.applyStyles(this.style);
}
if(this.labelAlign){
this.el.addClass('x-form-label-'+this.labelAlign);
}
if(this.hideLabels){
this.labelStyle = "display:none";
this.elementStyle = "padding-left:0;";
}else{
if(typeof this.labelWidth == 'number'){
this.labelStyle = "width:"+this.labelWidth+"px;";
this.elementStyle = "padding-left:"+((this.labelWidth+(typeof this.labelPad == 'number' ? this.labelPad : 5))+'px')+";";
}
if(this.labelAlign == 'top'){
this.labelStyle = "width:auto;";
this.elementStyle = "padding-left:0;";
}
}
var stack = this.stack;
var slen = stack.length;
if(slen > 0){
if(!this.fieldTpl){
var t = new Ext.Template(
'<div class="x-form-item {5}">',
'<label for="{0}" style="{2}">{1}{4}</label>',
'<div class="x-form-element" id="x-form-el-{0}" style="{3}">',
'</div>',
'</div><div class="x-form-clear-left"></div>'
);
t.disableFormats = true;
t.compile();
Ext.form.Layout.prototype.fieldTpl = t;
}
for(var i = 0; i < slen; i++) {
if(stack[i].isFormField){
this.renderField(stack[i]);
}else{
this.renderComponent(stack[i]);
}
}
}
if(this.clear){
this.el.createChild({cls:'x-form-clear'});
}
},
renderField : function(f){
this.fieldTpl.append(this.el, [
f.id, f.fieldLabel,
f.labelStyle||this.labelStyle||'',
this.elementStyle||'',
typeof f.labelSeparator == 'undefined' ? this.labelSeparator : f.labelSeparator,
f.itemCls||this.itemCls||''
]);
},
renderComponent : function(c){
c.render(this.el);
}
});
Ext.form.Column = function(config){
Ext.form.Column.superclass.constructor.call(this, config);
};
Ext.extend(Ext.form.Column, Ext.form.Layout, {
defaultAutoCreate : {tag: 'div', cls: 'x-form-ct x-form-column'},
onRender : function(ct, position){
Ext.form.Column.superclass.onRender.call(this, ct, position);
if(this.width){
this.el.setWidth(this.width);
}
}
});
Ext.form.FieldSet = function(config){
Ext.form.FieldSet.superclass.constructor.call(this, config);
};
Ext.extend(Ext.form.FieldSet, Ext.form.Layout, {
defaultAutoCreate : {tag: 'fieldset', cn: {tag:'legend'}},
onRender : function(ct, position){
Ext.form.FieldSet.superclass.onRender.call(this, ct, position);
if(this.legend){
this.setLegend(this.legend);
}
},
setLegend : function(text){
if(this.rendered){
this.el.child('legend').update(text);
}
}
});
Ext.form.VTypes = function(){
var alpha = /^[a-zA-Z_]+$/;
var alphanum = /^[a-zA-Z0-9_]+$/;
var email = /^([\w]+)(.[\w]+)*@([\w-]+\.){1,5}([A-Za-z]){2,4}$/;
var url = /(((https?)|(ftp)):\/\/([\-\w]+\.)+\w{2,3}(\/[%\-\w]+(\.\w{2,})?)*(([\w\-\.\?\\\/+@&#;`~=%!]*)(\.\w{2,})?)*\/?)/i;
return {
'email' : function(v){
return email.test(v);
},
'emailText' : 'This field should be an e-mail address in the format "user@domain.com"',
'emailMask' : /[a-z0-9_\.\-@]/i,
'url' : function(v){
return url.test(v);
},
'urlText' : 'This field should be a URL in the format "http:/'+'/www.domain.com"',
'alpha' : function(v){
return alpha.test(v);
},
'alphaText' : 'This field should only contain letters and _',
'alphaMask' : /[a-z_]/i,
'alphanum' : function(v){
return alphanum.test(v);
},
'alphanumText' : 'This field should only contain letters, numbers and _',
'alphanumMask' : /[a-z0-9_]/i
};
}();