armisa-models
Version:
models of armisa!
88 lines (87 loc) • 3.18 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ComboBoxFactory = void 0;
const enums_1 = require("../enums");
const ElementFactory_1 = require("../Page/ElementsOfFormFactory/ElementFactory");
const Cach_1 = require("./Cach");
class ComboBoxFactory extends ElementFactory_1.ElementFactory {
get any() {
return this;
}
constructor(_mainStateFactory, _fieldName, _dispose, required, caption, showHasChangeFlag, tabIndex, payLoadKey, responseKey, defaultValue, onChange) {
super(_mainStateFactory, _fieldName, _dispose, payLoadKey, responseKey);
this.required = required;
this.caption = caption;
this.showHasChangeFlag = showHasChangeFlag;
this.tabIndex = tabIndex;
this.payLoadKey = payLoadKey;
this.onChange = onChange;
this.forceUpdate = () => { };
this.focusToElement = () => {
this.mainStateFactory.elementsOfForm.focuseToThisElement(this);
};
this.validate = () => {
if (this.required && !this._value) {
// 'namingNotImplement'
this.validation = [`${this.caption} وارد نشده است`, enums_1.EnumValidateState.empty];
return this.validation;
}
this.validation = true;
};
this.defaultValue = undefined;
this.restartDefaultValue = () => {
this.defaultValue = this._value;
this.refreshHasChange();
};
this.refreshHasChange = () => {
if (this.showHasChangeFlag) {
this._hasChange = this.defaultValue !== this._value;
}
};
this._value = undefined;
this.deseriallize = (e) => {
this.clearData();
if (e === null) {
//do nothing
}
else if (e === undefined) {
//do nothing
}
else {
this._value = e;
this.defaultValue = this._value;
}
};
this.clearData = () => {
Cach_1.Cach.clear(this);
this._value = undefined;
this.defaultValue = undefined;
this.validation = true;
this._hasChange = false;
};
if (typeof defaultValue === 'number' || typeof defaultValue === 'string') {
this.defaultValue = defaultValue;
this._value = defaultValue;
}
if (Cach_1.Cach.isCached(this)) {
const cach = Cach_1.Cach.getCached(this);
this._value = cach.value;
this.validation = cach.validation;
this._hasChange = cach.hasChange;
}
}
get value() {
return this._value;
}
setValue(value) {
this._value = value;
Cach_1.Cach.setValue(this, value);
this.forceUpdate();
if (this.onChange) {
setTimeout(() => {
this.onChange && this.onChange(this);
}, 10);
}
}
}
exports.ComboBoxFactory = ComboBoxFactory;