armisa-models
Version:
models of armisa!
136 lines (135 loc) • 4.94 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.MultiSelectIdFactory = void 0;
const chainOfResponsibility_1 = require("../chainOfResponsibility");
const enums_1 = require("../enums");
const ElementFactory_1 = require("../Page/ElementsOfFormFactory/ElementFactory");
const Cach_1 = require("./Cach");
class MultiSelectIdFactory extends ElementFactory_1.ElementFactory {
get value() {
return this._value;
}
get defaultValue() {
return this._defaultValue;
}
constructor(_mainStateFactory, _fieldName, _dispose, caption, disabled, readonly, required, showHasChangeFlag, dirLeftToRight, placeHolder, tabIndex, initialValue, payLoadKey, responseKey) {
super(_mainStateFactory, _fieldName, _dispose, payLoadKey, responseKey);
this.caption = caption;
this.disabled = disabled;
this.readonly = readonly;
this.required = required;
this.showHasChangeFlag = showHasChangeFlag;
this.dirLeftToRight = dirLeftToRight;
this.placeHolder = placeHolder;
this.tabIndex = tabIndex;
this.forceUpdate = () => { };
this.setValue = (value) => {
this._value = value;
this.refreshHasChange();
Cach_1.Cach.setValue(this, this._value);
this.forceUpdate();
};
this.deseriallize = (e) => {
this.clearData();
if (e === null) {
//do nothing
}
else if (e === undefined) {
//do nothing
}
else if (typeof e === 'object') {
this._value = e;
this._defaultValue = this._value;
}
else {
this._value = e;
this._defaultValue = this._value;
}
Cach_1.Cach.setValue(this, this._value);
};
this.clearData = () => {
Cach_1.Cach.clear(this);
this._value = null;
this._defaultValue = null;
this.validation = true;
this._hasChange = false;
};
this.toggle = (id) => {
if (!this._value) {
this._value = [];
}
if (this._value.some(i => i === id)) {
this._value = this._value.filter(i => i !== id);
}
else {
this._value.push(id);
}
this.forceUpdate();
};
this.isSelected = (arg) => {
let id;
if (typeof arg === 'number') {
id = arg;
}
else {
id = arg.id;
}
if (!this._value) {
return false;
}
if (this._value.some(i => i === id)) {
return true;
}
return false;
};
this.focusToElement = () => {
this.mainStateFactory.elementsOfForm.focuseToThisElement(this);
};
this.restartDefaultValue = () => {
this._defaultValue = this.value;
this.refreshHasChange();
};
this.refreshHasChange = () => {
if (this.showHasChangeFlag) {
this._hasChange = this.defaultValue !== this._value;
}
};
this.validate = () => {
var validationChain = new chainOfResponsibility_1.ValidationChain();
validationChain.validators.add(this.validateNormal);
validationChain.validators.add(this.validateRequired);
this.validation = validationChain.validate();
};
this.validateNormal = (_eventArgs) => { };
this.validateRequired = (eventArgs) => {
if (this.required) {
if (!this.value) {
eventArgs.error = 'اطلاعاتی وارد نشده است';
eventArgs.state = enums_1.EnumValidateState.empty;
eventArgs.cancel = true;
}
}
};
this.isValueEmpty = () => {
return typeof this._value === 'string' && this._value !== '';
};
this.isValueNotEmpty = () => {
return !this.isValueEmpty();
};
if (initialValue && initialValue instanceof Array) {
this._defaultValue = initialValue;
this._value = initialValue;
}
else {
this._defaultValue = null;
this._value = null;
}
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;
}
}
}
exports.MultiSelectIdFactory = MultiSelectIdFactory;