UNPKG

armisa-models

Version:
170 lines (169 loc) 8.82 kB
"use strict"; var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) { if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter"); if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it"); return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver); }; var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) { if (kind === "m") throw new TypeError("Private method is not writable"); if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter"); if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it"); return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value; }; var _TextBoxFactory_value, _TextBoxFactory_defaultValue; Object.defineProperty(exports, "__esModule", { value: true }); exports.TextBoxFactory = 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 TextBoxFactory extends ElementFactory_1.ElementFactory { get value() { return __classPrivateFieldGet(this, _TextBoxFactory_value, "f"); } get defaultValue() { return __classPrivateFieldGet(this, _TextBoxFactory_defaultValue, "f"); } constructor(_mainStateFactory, _fieldName, _dispose, caption, disabled, readonly, required, minLength, maxLength, showHasChangeFlag, dirLeftToRight, placeHolder, tabIndex, delyOnChange, initialValue, payLoadKey, responseKey, history) { super(_mainStateFactory, _fieldName, _dispose, payLoadKey, responseKey, history); this.caption = caption; this.disabled = disabled; this.readonly = readonly; this.required = required; this.minLength = minLength; this.maxLength = maxLength; this.showHasChangeFlag = showHasChangeFlag; this.dirLeftToRight = dirLeftToRight; this.placeHolder = placeHolder; this.tabIndex = tabIndex; this.delyOnChange = delyOnChange; this.forceUpdate = () => { }; this.timerForLoad = null; this.clearTimerForLoad = () => { if (this.timerForLoad) { clearTimeout(this.timerForLoad); } }; this.onChangeDely = (onChange) => { //if dely equl 999999 ignore any onchange if (this.delyOnChange === 999999) { return; } this.clearTimerForLoad(); this.timerForLoad = setTimeout(() => { onChange(__classPrivateFieldGet(this, _TextBoxFactory_value, "f") || ''); }, this.delyOnChange); }; _TextBoxFactory_value.set(this, void 0); this.setValue = (value) => { __classPrivateFieldSet(this, _TextBoxFactory_value, value, "f"); this.refreshHasChange(); Cach_1.Cach.setValue(this, __classPrivateFieldGet(this, _TextBoxFactory_value, "f")); this.forceUpdate(); }; this.deseriallize = (e) => { this.clearData(); if (e === null) { //do nothing } else if (e === undefined) { //do nothing } else if (typeof e === 'object') { __classPrivateFieldSet(this, _TextBoxFactory_value, JSON.stringify(e), "f"); __classPrivateFieldSet(this, _TextBoxFactory_defaultValue, __classPrivateFieldGet(this, _TextBoxFactory_value, "f"), "f"); } else { __classPrivateFieldSet(this, _TextBoxFactory_value, e, "f"); __classPrivateFieldSet(this, _TextBoxFactory_defaultValue, __classPrivateFieldGet(this, _TextBoxFactory_value, "f"), "f"); } Cach_1.Cach.setValue(this, __classPrivateFieldGet(this, _TextBoxFactory_value, "f")); }; this.clearData = () => { Cach_1.Cach.clear(this); this.clearTimerForLoad(); __classPrivateFieldSet(this, _TextBoxFactory_value, null, "f"); __classPrivateFieldSet(this, _TextBoxFactory_defaultValue, null, "f"); this.validation = true; this._hasChange = false; }; _TextBoxFactory_defaultValue.set(this, void 0); this.focusToElement = () => { this.mainStateFactory.elementsOfForm.focuseToThisElement(this); }; this.restartDefaultValue = () => { __classPrivateFieldSet(this, _TextBoxFactory_defaultValue, this.value, "f"); this.refreshHasChange(); }; this.refreshHasChange = () => { if (this.showHasChangeFlag) { this._hasChange = this.defaultValue !== __classPrivateFieldGet(this, _TextBoxFactory_value, "f"); } }; this.validate = () => { var validationChain = new chainOfResponsibility_1.ValidationChain(); validationChain.validators.add(this.validateNormal); validationChain.validators.add(this.validateRequired); validationChain.validators.add(this.validateMinLength); validationChain.validators.add(this.validateMaxLength); 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.validateMinLength = (eventArgs) => { if (this.minLength) { if (typeof this.value !== 'string' || this.value === '') { if (this.required) { eventArgs.error = `اطلاعاتی وارد نشده است. حداقل طول مجاز: ${this.minLength}`; eventArgs.state = enums_1.EnumValidateState.maxLength; eventArgs.cancel = true; } } else if (this.value.length < this.minLength) { eventArgs.error = `طول مقدار وارد شده کمتر از مقدار مجاز میباشد. حداقل طول مجاز: ${this.minLength}`; eventArgs.state = enums_1.EnumValidateState.maxLength; eventArgs.cancel = true; } } }; this.validateMaxLength = (eventArgs) => { if (this.maxLength) { if (this.value && this.value.length > this.maxLength) { eventArgs.error = `طول مقدار وارد شده بیشتر از مقدار مجاز میباشد. حداکثر طول مجاز: ${this.maxLength}`; eventArgs.state = enums_1.EnumValidateState.maxLength; eventArgs.cancel = true; } } }; this.isValueEmpty = () => { return typeof __classPrivateFieldGet(this, _TextBoxFactory_value, "f") === 'string' && __classPrivateFieldGet(this, _TextBoxFactory_value, "f") !== ''; }; this.isValueNotEmpty = () => { return !this.isValueEmpty(); }; if (typeof initialValue === 'string') { __classPrivateFieldSet(this, _TextBoxFactory_defaultValue, initialValue, "f"); __classPrivateFieldSet(this, _TextBoxFactory_value, initialValue, "f"); } else { __classPrivateFieldSet(this, _TextBoxFactory_defaultValue, null, "f"); __classPrivateFieldSet(this, _TextBoxFactory_value, null, "f"); } if (Cach_1.Cach.isCached(this)) { const cach = Cach_1.Cach.getCached(this); __classPrivateFieldSet(this, _TextBoxFactory_value, cach.value, "f"); this.validation = cach.validation; this._hasChange = cach.hasChange; } } } exports.TextBoxFactory = TextBoxFactory; _TextBoxFactory_value = new WeakMap(), _TextBoxFactory_defaultValue = new WeakMap();