armisa-models
Version:
models of armisa!
91 lines (90 loc) • 4.44 kB
JavaScript
"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 _SelfObjectArray_value;
Object.defineProperty(exports, "__esModule", { value: true });
exports.SelfObjectArray = void 0;
const BaseSelfControl_1 = require("./BaseSelfControl");
const chainOfResponsibility_1 = require("../chainOfResponsibility");
const enums_1 = require("../enums");
class SelfObjectArray extends BaseSelfControl_1.BaseSelfControl {
get value() {
return __classPrivateFieldGet(this, _SelfObjectArray_value, "f");
}
set value(value) { }
get ids() {
return this.value.map(i => i.id);
}
constructor(_deserialize, value) {
super();
this._deserialize = _deserialize;
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, _SelfObjectArray_value, "f") === 'string' && __classPrivateFieldGet(this, _SelfObjectArray_value, "f") !== '';
};
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.initializeProperties = false;
this.initializeListener = false;
this.validation = true;
this.multiItemTimer && clearTimeout(this.multiItemTimer);
delete this.multiItemId;
this.isTypedIncorrectChar = false;
};
this.refreshHasChange = () => {
if (this.showHasChangeFlag) {
this.hasChange = this.defaultValue !== __classPrivateFieldGet(this, _SelfObjectArray_value, "f").join('');
}
};
this.restartDefaultValue = () => {
this.defaultValue = __classPrivateFieldGet(this, _SelfObjectArray_value, "f").join('');
this.refreshHasChange();
};
_SelfObjectArray_value.set(this, void 0);
this.setValue = (value) => {
__classPrivateFieldSet(this, _SelfObjectArray_value, value, "f");
this.refreshHasChange();
};
this.deserialize = (jsons) => {
__classPrivateFieldSet(this, _SelfObjectArray_value, jsons.map(i => this._deserialize(i)), "f");
this.restartDefaultValue();
};
this.useAsFilter = false;
__classPrivateFieldSet(this, _SelfObjectArray_value, value, "f");
this.restartDefaultValue();
}
static empty(deserialize) {
return new SelfObjectArray(deserialize, []);
}
}
exports.SelfObjectArray = SelfObjectArray;
_SelfObjectArray_value = new WeakMap();