UNPKG

armisa-models

Version:
99 lines (98 loc) 4.59 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 _SelfTime_value; Object.defineProperty(exports, "__esModule", { value: true }); exports.SelfTime = void 0; const BaseSelfControl_1 = require("./BaseSelfControl"); const chainOfResponsibility_1 = require("../chainOfResponsibility"); const enums_1 = require("../enums"); class SelfTime extends BaseSelfControl_1.BaseSelfControl { get value() { return __classPrivateFieldGet(this, _SelfTime_value, "f"); } set value(value) { } constructor(value) { super(); this.validateNormal = (eventArgs) => { }; this.validateRequired = (eventArgs) => { if (this.required) { if (typeof this.value !== 'number') { eventArgs.error = 'اطلاعاتی وارد نشده است'; eventArgs.state = enums_1.EnumValidateState.empty; eventArgs.cancel = true; } } }; this.validateMinValue = (eventArgs) => { if (this.minValue) { if (typeof this.value !== 'number') { eventArgs.error = `هیچ مقداری وارد نشده است. حداقل مقدار مجاز: ${this.minValue}`; eventArgs.state = enums_1.EnumValidateState.minValue; eventArgs.cancel = true; } } }; this.validateMaxValue = (eventArgs) => { if (this.maxValue) { } }; this.isValueEmpty = () => { return typeof __classPrivateFieldGet(this, _SelfTime_value, "f") === 'string' && this.value !== ''; }; this.isValueNotEmpty = () => { return !this.isValueEmpty(); }; this.validate = () => { var validationChain = new chainOfResponsibility_1.ValidationChain(); validationChain.validators.add(this.validateNormal); validationChain.validators.add(this.validateRequired); validationChain.validators.add(this.validateMinValue); validationChain.validators.add(this.validateMaxValue); this.validation = validationChain.validate(); }; this.cleaningClassInitializer = () => { this.hasChange = false; this.defaultValue = undefined; this.initializeListener = false; this.validation = true; }; this.refreshHasChange = () => { if (this.showHasChangeFlag) { this.hasChange = this.defaultValue !== __classPrivateFieldGet(this, _SelfTime_value, "f"); } }; this.restartDefaultValue = () => { this.defaultValue = this.value; this.refreshHasChange(); }; _SelfTime_value.set(this, void 0); this.setValue = (value) => { __classPrivateFieldSet(this, _SelfTime_value, value, "f"); this.refreshHasChange(); }; this.deserialize = (value) => { __classPrivateFieldSet(this, _SelfTime_value, value, "f"); this.restartDefaultValue(); }; __classPrivateFieldSet(this, _SelfTime_value, value, "f"); this.restartDefaultValue(); } static empty() { return new SelfTime(''); } static deserialize(value) { return new SelfTime(value || ''); } } exports.SelfTime = SelfTime; _SelfTime_value = new WeakMap();