armisa-models
Version:
models of armisa!
153 lines (152 loc) • 7.36 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 _SelectCustomerFactory_code, _SelectCustomerFactory_text;
Object.defineProperty(exports, "__esModule", { value: true });
exports.SelectCustomerFactory = void 0;
const enums_1 = require("../enums");
const ElementFactory_1 = require("../Page/ElementsOfFormFactory/ElementFactory");
const Cach_1 = require("./Cach");
class SelectCustomerFactory extends ElementFactory_1.ElementFactory {
get any() {
return this;
}
get text() {
return __classPrivateFieldGet(this, _SelectCustomerFactory_text, "f") || '';
}
setText(text) {
__classPrivateFieldSet(this, _SelectCustomerFactory_text, text, "f");
this.setCachedData();
this.forceUpdate();
}
get value() {
return __classPrivateFieldGet(this, _SelectCustomerFactory_code, "f");
}
get code() {
return __classPrivateFieldGet(this, _SelectCustomerFactory_code, "f") || '';
}
setValue(code) {
__classPrivateFieldSet(this, _SelectCustomerFactory_code, code, "f");
this.setCachedData();
this.forceUpdate();
}
constructor(_mainStateFactory, _fieldName, _dispose, useCaseType, required, onlyLastLevel, caption, structrulCodeFactory, axiosData, showHasChangeFlag, tabIndex, payLoadKey, responseKey, onChange) {
super(_mainStateFactory, _fieldName, _dispose, payLoadKey, responseKey);
this.useCaseType = useCaseType;
this.required = required;
this.onlyLastLevel = onlyLastLevel;
this.caption = caption;
this.structrulCodeFactory = structrulCodeFactory;
this.axiosData = axiosData;
this.showHasChangeFlag = showHasChangeFlag;
this.tabIndex = tabIndex;
this.onChange = onChange;
this.forceUpdate = () => { };
this.swapTypeOfCode = () => {
this.clearData();
if (this.typeOfCode === 'actually') {
this.typeOfCode = 'potential';
}
else {
this.typeOfCode = 'actually';
}
};
this.focusToElement = () => {
this.mainStateFactory.elementsOfForm.focuseToThisElement(this);
this.element?.focus();
};
this.setCachedData = () => {
Cach_1.Cach.setValue(this, {
fullName: this.fullName,
childCount: this.childCount,
name: this.name,
typeOfCode: this.typeOfCode,
id: this.id,
codeValueState: this.codeValueState,
code: this.code,
text: this.text
});
};
this.clearData = () => {
Cach_1.Cach.clear(this);
__classPrivateFieldSet(this, _SelectCustomerFactory_code, null, "f");
__classPrivateFieldSet(this, _SelectCustomerFactory_text, null, "f");
this._defaultValue = null;
this.fullName = [];
this.name = '';
this.codeValueState = 'clear';
this.childCount = 0;
this.validation = true;
};
this.id = null;
this.fullName = [];
this.name = '';
this.typeOfCode = 'potential';
///state that get from server data
this.codeValueState = 'clear';
this.childCount = 0;
this.validate = () => {
if (this.required && !this.code) {
// 'namingNotImplement'
this.validation = [`${this.caption} وارد نشده است`, enums_1.EnumValidateState.empty];
return this.validation;
}
else if (this.codeValueState === 'dirty') {
this.validation = [`طول ${this.caption} وارد شده معتبر نیست`, enums_1.EnumValidateState.invalidLength];
return this.validation;
}
else if (this.codeValueState === 'withoutParent') {
this.validation = [`${this.caption} وارد شده سرفصل بالاتر ندارد`, enums_1.EnumValidateState.withoutParent];
return this.validation;
}
else if (this.onlyLastLevel && this.codeValueState === 'newCode') {
this.validation = [`${this.caption} وارد شده وجود ندارد`, enums_1.EnumValidateState.withoutParent];
return this.validation;
}
else if (this.onlyLastLevel && this.childCount > 0) {
this.validation = [`${this.caption} وارد شده سرفصل جزء دارد`, enums_1.EnumValidateState.hasChildren];
return this.validation;
}
this.validation = true;
return this.validation;
};
_SelectCustomerFactory_code.set(this, null);
_SelectCustomerFactory_text.set(this, null);
this.deseriallize = (e) => { };
this._defaultValue = null;
this.restartDefaultValue = () => {
this._defaultValue = this.code;
this.refreshHasChange();
};
this.refreshHasChange = () => {
if (this.showHasChangeFlag) {
this._hasChange = this._defaultValue !== __classPrivateFieldGet(this, _SelectCustomerFactory_code, "f");
}
};
this.forceUpdateSpinner = () => { };
if (Cach_1.Cach.isCached(this)) {
const cach = Cach_1.Cach.getCached(this);
this.name = cach.value.name;
this.typeOfCode = cach.value.typeOfCode;
this.fullName = cach.value.fullName;
this.childCount = cach.value.childCount;
this.id = cach.value.id;
this.codeValueState = cach.value.codeValueState;
__classPrivateFieldSet(this, _SelectCustomerFactory_code, cach.value.code, "f");
__classPrivateFieldSet(this, _SelectCustomerFactory_text, cach.value.text, "f");
this.validation = cach.validation;
this._hasChange = cach.hasChange;
}
}
}
exports.SelectCustomerFactory = SelectCustomerFactory;
_SelectCustomerFactory_code = new WeakMap(), _SelectCustomerFactory_text = new WeakMap();