UNPKG

armisa-models

Version:
115 lines (114 loc) 5.16 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 _SelfCheckedIDs_value; Object.defineProperty(exports, "__esModule", { value: true }); exports.SelfCheckedIDs = void 0; const BaseSelfControl_1 = require("./BaseSelfControl"); const enums_1 = require("../enums"); const chainOfResponsibility_1 = require("../chainOfResponsibility"); class SelfCheckedIDs extends BaseSelfControl_1.BaseSelfControl { validateNormal(eventArgs) { } get value() { return __classPrivateFieldGet(this, _SelfCheckedIDs_value, "f"); } set value(value) { } constructor() { super(); this.onlyLastLevel = false; this.validateRequired = (eventArgs) => { if (this.required) { if (!this.value || this.value.length === 0) { eventArgs.cancel = true; eventArgs.state = enums_1.EnumValidateState.empty; eventArgs.error = 'هیچ کدی انتخاب نشده است'; } } }; this.isValueEmpty = () => { return __classPrivateFieldGet(this, _SelfCheckedIDs_value, "f") instanceof Array && __classPrivateFieldGet(this, _SelfCheckedIDs_value, "f").length > 0; }; this.isValueNotEmpty = () => { return !this.isValueEmpty(); }; this.validate = () => { var validationChain = new chainOfResponsibility_1.ValidationChain(); validationChain.validators.add(this.validateNormal); validationChain.validators.add(this.validateRequired); this.validation = validationChain.validate(); }; this.cleaningClassInitializer = () => { this.hasChange = false; this.defaultValue = undefined; this.initializeListener = false; this.initializeProperties = false; this.validation = true; }; this.checkStates = []; this.refreshHasChange = () => { if (this.showHasChangeFlag) { this.hasChange = this.defaultValue !== __classPrivateFieldGet(this, _SelfCheckedIDs_value, "f").toString(); } }; this.restartDefaultValue = () => { this.defaultValue = this.value.toString(); this.refreshHasChange(); }; _SelfCheckedIDs_value.set(this, void 0); this.setValue = (ids) => { __classPrivateFieldSet(this, _SelfCheckedIDs_value, ids, "f"); this.refreshHasChange(); }; this.setcheckStates = (ids, states) => { __classPrivateFieldSet(this, _SelfCheckedIDs_value, ids, "f"); this.checkStates = states; this.refreshHasChange(); }; this.deserialize = (value, checkStates) => { this.setcheckStates(value, checkStates); this.restartDefaultValue(); }; __classPrivateFieldSet(this, _SelfCheckedIDs_value, [], "f"); this.restartDefaultValue(); } static empty() { return new SelfCheckedIDs(); } static deserialize(value) { if (value) { const des = new SelfCheckedIDs(); value.forEach((i) => { const selfCheckTree = { id: i.id, isFromChild: i.isFromChild ? i.isFromChild : false, isFromParent: false, code: i, }; if (!selfCheckTree.isFromChild) { __classPrivateFieldGet(des, _SelfCheckedIDs_value, "f").push(i.id); } des.checkStates.push({ id: i.id, isFromParent: false, isFromChild: selfCheckTree.isFromChild, code: i, }); }); return des; } else { return SelfCheckedIDs.empty(); } } } exports.SelfCheckedIDs = SelfCheckedIDs; _SelfCheckedIDs_value = new WeakMap();