Ext.form.TextField.prototype.setReadOnly = function(isReadOnly){
  if (isReadOnly){
    Ext.fly(this.el).addClass("x-form-field-readonly");
    Ext.form.fieldReadOnlyFocusEl(this.el.dom);
  } else {
    Ext.fly(this.el).removeClass("x-form-field-readonly");
  }
  this.el.dom.readOnly = isReadOnly;
};
Ext.form.TextField.prototype.isReadOnly = function() {
  return this.el.dom.readOnly;
};
Ext.form.NumberField.prototype.setReadOnly = function(isReadOnly){
  this.el.dom.readOnly = isReadOnly;
  if (isReadOnly){
    Ext.fly(this.el).addClass("x-form-field-readonly");
    Ext.form.fieldReadOnlyFocusEl(this.el.dom);
  } else {
    Ext.fly(this.el).removeClass("x-form-field-readonly");
  }
};

Ext.form.NumberField.prototype.isReadOnly = function() {
  return this.el.dom.readOnly;
};
Ext.form.TextArea.prototype.setReadOnly = function(isReadOnly){
  this.el.dom.readOnly = isReadOnly;
  if (isReadOnly){
    Ext.fly(this.el).addClass("x-form-field-readonly");
    Ext.form.fieldReadOnlyFocusEl(this.el.dom);
  } else {
    Ext.fly(this.el).removeClass("x-form-field-readonly");
  }
}

Ext.form.TextArea.prototype.isReadOnly = function() {
  return this.el.dom.readOnly;
};
Ext.form.checkboxReadOnlyCtrl = function() {
	event.srcElement.checked = !event.srcElement.checked;
};

Ext.form.fieldReadOnlyCtrl = function() {
  event.srcElement.disabled = true;
};

Ext.form.fieldReadOnlyFocusEl = function(elObject){
  if (document.activeElement!==elObject){
    return false;
  }
  var newElementId = "__ID007A9D674AB6485493451B5BAF4C0D32";
  var inputEL = document.getElementById(newElementId);
  if (!inputEL){
    var inputEL = document.createElement("INPUT");
    inputEL.name = newElementId;
    inputEL.id = newElementId;
    document.body.insertAdjacentElement('afterBegin',inputEL);
    inputEL.style.position="absolute";
    inputEL.style.top="-40px";
    inputEL.onblur=Ext.form.fieldReadOnlyCtrl;
  }
  inputEL.disabled = false;
  inputEL.focus();
};
Ext.form.Checkbox.prototype.setReadOnly = function(isReadOnly){
  var el = this.el.dom.parentNode;
  if (isReadOnly){
    //this.disable();
    this.el.un("click", this.onClick,  this);
    this.el.un("change", this.onClick,  this);
    this.el.dom.onclick = Ext.form.checkboxReadOnlyCtrl;
    Ext.fly(this.el).addClass("x-form-checkbox-readonly");
    Ext.form.fieldReadOnlyFocusEl(this.el.dom);
  } else {
    //this.enable();
    this.el.dom.onclick = null;
    this.el.on("click", this.onClick,  this);
    this.el.on("change", this.onClick,  this);
    Ext.fly(this.el).removeClass("x-form-checkbox-readonly");
  }
};
Ext.form.Checkbox.prototype.isReadOnly = function() {
  return this.el.dom.readOnly;
};
Ext.form.Checkbox.prototype.setBoxLabel = function(labelText) {
  if (this.boxLabel) {
    var boxLabelDom = this.wrap.child("label",true);
    boxLabelDom.innerText = labelText;
  } else {
    Ext.Msg.alert("信息","初始化配置中没有属性，不能调用函数setBoxLabel");
    return false;
  }
};
Ext.form.ComboBox.prototype.setReadOnly = function(isReadOnly){
  if (!isReadOnly){
    if (this.editable){
      this.el.dom.readOnly = isReadOnly;
    }
  } else {
    this.el.dom.readOnly = isReadOnly;
  }
  this.disabled=isReadOnly;
  if (isReadOnly){
    Ext.fly(this.el).addClass("x-form-field-readonly");
    Ext.form.fieldReadOnlyFocusEl(this.el.dom);
  } else {
    Ext.fly(this.el).removeClass("x-form-field-readonly");
  }
};
Ext.form.ComboBox.prototype.isReadOnly = function() {
  return this.el.dom.readOnly;
};
Ext.form.DateField.prototype.setReadOnly = function(isReadOnly){
  if (!isReadOnly && this.editable){
    this.el.dom.readOnly = isReadOnly;
  } else {
    this.el.dom.readOnly = isReadOnly;
  }
  this.disabled=isReadOnly;
  if (isReadOnly){
    Ext.fly(this.el).addClass("x-form-field-readonly");
    Ext.form.fieldReadOnlyFocusEl(this.el.dom);
  } else {
    Ext.fly(this.el).removeClass("x-form-field-readonly");
  }
};
Ext.form.DateField.prototype.isReadOnly = function() {
  return this.el.dom.readOnly;
};
Ext.form.TriggerField.prototype.setReadOnly = function(isReadOnly){
  if (!isReadOnly && this.editable){
    this.el.dom.readOnly = isReadOnly;
  } else {
    this.el.dom.readOnly = isReadOnly;
  }
  this.disabled=isReadOnly;
  if (isReadOnly){
    Ext.fly(this.el).addClass("x-form-field-readonly");
    Ext.form.fieldReadOnlyFocusEl(this.el.dom);
  } else {
    Ext.fly(this.el).removeClass("x-form-field-readonly");
  }
};

Ext.form.TriggerField.prototype.isReadOnly = function() {
  return this.el.dom.readOnly;
};

Ext.Button.prototype.setState = function(enable) {
  if (enable===true) {
    this.enable();
  } else {
    this.disable();
  }
  return enable===true;
};
