UNPKG

armisa-models

Version:
130 lines (129 loc) 6.69 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 _PercentBoxFactory_value, _PercentBoxFactory_defaultValue; Object.defineProperty(exports, "__esModule", { value: true }); exports.PercentBoxFactory = void 0; const nums2persian_1 = require("nums2persian"); const chainOfResponsibility_1 = require("../chainOfResponsibility"); const enums_1 = require("../enums"); const ElementFactory_1 = require("../Page/ElementsOfFormFactory/ElementFactory"); const Cach_1 = require("./Cach"); class PercentBoxFactory extends ElementFactory_1.ElementFactory { get value() { return __classPrivateFieldGet(this, _PercentBoxFactory_value, "f"); } get text() { if (typeof __classPrivateFieldGet(this, _PercentBoxFactory_value, "f") === 'number') { return __classPrivateFieldGet(this, _PercentBoxFactory_value, "f").toString(); } return ''; } get defaultValue() { return __classPrivateFieldGet(this, _PercentBoxFactory_defaultValue, "f"); } constructor(_mainStateFactory, _fieldName, _dispose, caption, disabled, readonly, required, showHasChangeFlag, tabIndex, initialValue, payLoadKey, responseKey, history) { super(_mainStateFactory, _fieldName, _dispose, payLoadKey, responseKey, history); this.caption = caption; this.disabled = disabled; this.readonly = readonly; this.required = required; this.showHasChangeFlag = showHasChangeFlag; this.tabIndex = tabIndex; this.forceUpdate = () => { }; _PercentBoxFactory_value.set(this, void 0); this.setValue = (value) => { if (value) { const newValue = (0, nums2persian_1.persianStringToEnglishString)(value); __classPrivateFieldSet(this, _PercentBoxFactory_value, +newValue, "f"); } else { __classPrivateFieldSet(this, _PercentBoxFactory_value, null, "f"); } this.refreshHasChange(); Cach_1.Cach.setValue(this, __classPrivateFieldGet(this, _PercentBoxFactory_value, "f")); this.forceUpdate(); }; this.deseriallize = (e) => { this.clearData(); if (e === null) { //do nothing } else if (e === undefined) { //do nothing } else { __classPrivateFieldSet(this, _PercentBoxFactory_value, e, "f"); __classPrivateFieldSet(this, _PercentBoxFactory_defaultValue, __classPrivateFieldGet(this, _PercentBoxFactory_value, "f"), "f"); } Cach_1.Cach.setValue(this, __classPrivateFieldGet(this, _PercentBoxFactory_value, "f")); }; this.clearData = () => { Cach_1.Cach.clear(this); __classPrivateFieldSet(this, _PercentBoxFactory_value, null, "f"); __classPrivateFieldSet(this, _PercentBoxFactory_defaultValue, null, "f"); this.validation = true; this._hasChange = false; }; _PercentBoxFactory_defaultValue.set(this, void 0); this.focusToElement = () => { this.mainStateFactory.elementsOfForm.focuseToThisElement(this); }; this.restartDefaultValue = () => { __classPrivateFieldSet(this, _PercentBoxFactory_defaultValue, this.value, "f"); this.refreshHasChange(); }; this.refreshHasChange = () => { if (this.showHasChangeFlag) { this._hasChange = this.defaultValue !== __classPrivateFieldGet(this, _PercentBoxFactory_value, "f"); } }; 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 __classPrivateFieldGet(this, _PercentBoxFactory_value, "f") === 'string' && __classPrivateFieldGet(this, _PercentBoxFactory_value, "f") !== ''; }; this.isValueNotEmpty = () => { return !this.isValueEmpty(); }; if (typeof initialValue === 'number') { __classPrivateFieldSet(this, _PercentBoxFactory_defaultValue, initialValue, "f"); __classPrivateFieldSet(this, _PercentBoxFactory_value, initialValue, "f"); } else { __classPrivateFieldSet(this, _PercentBoxFactory_defaultValue, null, "f"); __classPrivateFieldSet(this, _PercentBoxFactory_value, null, "f"); } if (Cach_1.Cach.isCached(this)) { const cach = Cach_1.Cach.getCached(this); __classPrivateFieldSet(this, _PercentBoxFactory_value, cach.value, "f"); this.validation = cach.validation; this._hasChange = cach.hasChange; } } } exports.PercentBoxFactory = PercentBoxFactory; _PercentBoxFactory_value = new WeakMap(), _PercentBoxFactory_defaultValue = new WeakMap();