UNPKG

armisa-models

Version:
91 lines (90 loc) 3.25 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.SelectPersonFactory = void 0; const enums_1 = require("../enums"); const ElementFactory_1 = require("../Page/ElementsOfFormFactory/ElementFactory"); const Cach_1 = require("./Cach"); class SelectPersonFactory extends ElementFactory_1.ElementFactory { get any() { return this; } constructor(_mainStateFactory, _fieldName, _dispose, required, caption, showHasChangeFlag, axiosData, tabIndex, payLoadKey, responseKey, defaultValue, onChange) { super(_mainStateFactory, _fieldName, _dispose, payLoadKey, responseKey); this.required = required; this.caption = caption; this.showHasChangeFlag = showHasChangeFlag; this.axiosData = axiosData; this.tabIndex = tabIndex; this.payLoadKey = payLoadKey; this.onChange = onChange; this.items = []; 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; return this.validation; }; this.defaultValue = null; this.restartDefaultValue = () => { this.defaultValue = this._value; this.refreshHasChange(); }; this.refreshHasChange = () => { if (this.showHasChangeFlag) { this._hasChange = this.defaultValue !== this._value; } }; this._value = null; 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 = null; this.defaultValue = null; this.validation = true; this._hasChange = false; }; if (typeof defaultValue === 'number') { 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.SelectPersonFactory = SelectPersonFactory;