armisa-models
Version:
models of armisa!
161 lines (160 loc) • 8.46 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 _NumberBoxFactory_value, _NumberBoxFactory_defaultValue;
Object.defineProperty(exports, "__esModule", { value: true });
exports.NumberBoxFactory = 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 NumberBoxFactory extends ElementFactory_1.ElementFactory {
get value() {
return __classPrivateFieldGet(this, _NumberBoxFactory_value, "f");
}
get text() {
if (typeof __classPrivateFieldGet(this, _NumberBoxFactory_value, "f") === 'number') {
return (0, nums2persian_1.formatNumberShowZero)(__classPrivateFieldGet(this, _NumberBoxFactory_value, "f")).replace(',', ' , ');
}
return '';
}
get defaultValue() {
return __classPrivateFieldGet(this, _NumberBoxFactory_defaultValue, "f");
}
constructor(_mainStateFactory, _fieldName, _dispose, caption, disabled, readonly, required, minLength, maxLength, showHasChangeFlag, dirLeftToRight, placeHolder, 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.minLength = minLength;
this.maxLength = maxLength;
this.showHasChangeFlag = showHasChangeFlag;
this.dirLeftToRight = dirLeftToRight;
this.placeHolder = placeHolder;
this.tabIndex = tabIndex;
this.forceUpdate = () => { };
_NumberBoxFactory_value.set(this, void 0);
this.setValue = (value) => {
if (value) {
const newValue = (0, nums2persian_1.persianStringToEnglishString)(value);
__classPrivateFieldSet(this, _NumberBoxFactory_value, +newValue, "f");
}
else {
__classPrivateFieldSet(this, _NumberBoxFactory_value, null, "f");
}
this.refreshHasChange();
Cach_1.Cach.setValue(this, __classPrivateFieldGet(this, _NumberBoxFactory_value, "f"));
this.forceUpdate();
};
this.deseriallize = (e) => {
this.clearData();
if (e === null) {
//do nothing
}
else if (e === undefined) {
//do nothing
}
else {
__classPrivateFieldSet(this, _NumberBoxFactory_value, e, "f");
__classPrivateFieldSet(this, _NumberBoxFactory_defaultValue, __classPrivateFieldGet(this, _NumberBoxFactory_value, "f"), "f");
}
Cach_1.Cach.setValue(this, __classPrivateFieldGet(this, _NumberBoxFactory_value, "f"));
};
this.clearData = () => {
Cach_1.Cach.clear(this);
__classPrivateFieldSet(this, _NumberBoxFactory_value, null, "f");
__classPrivateFieldSet(this, _NumberBoxFactory_defaultValue, null, "f");
this.validation = true;
this._hasChange = false;
};
_NumberBoxFactory_defaultValue.set(this, void 0);
this.focusToElement = () => {
this.mainStateFactory.elementsOfForm.focuseToThisElement(this);
};
this.restartDefaultValue = () => {
__classPrivateFieldSet(this, _NumberBoxFactory_defaultValue, this.value, "f");
this.refreshHasChange();
};
this.refreshHasChange = () => {
if (this.showHasChangeFlag) {
this._hasChange = this.defaultValue !== __classPrivateFieldGet(this, _NumberBoxFactory_value, "f");
}
};
this.validate = () => {
var validationChain = new chainOfResponsibility_1.ValidationChain();
validationChain.validators.add(this.validateNormal);
validationChain.validators.add(this.validateRequired);
validationChain.validators.add(this.validateMinLength);
validationChain.validators.add(this.validateMaxLength);
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.validateMinLength = (eventArgs) => {
if (this.minLength) {
if (typeof this.value !== 'string' || this.value === '') {
if (this.required) {
eventArgs.error = `اطلاعاتی وارد نشده است. حداقل طول مجاز: ${this.minLength}`;
eventArgs.state = enums_1.EnumValidateState.maxLength;
eventArgs.cancel = true;
}
}
else if (this.value < this.minLength) {
eventArgs.error = `طول مقدار وارد شده کمتر از مقدار مجاز میباشد. حداقل طول مجاز: ${this.minLength}`;
eventArgs.state = enums_1.EnumValidateState.maxLength;
eventArgs.cancel = true;
}
}
};
this.validateMaxLength = (eventArgs) => {
if (this.maxLength) {
if (this.value && this.value > this.maxLength) {
eventArgs.error = `طول مقدار وارد شده بیشتر از مقدار مجاز میباشد. حداکثر طول مجاز: ${this.maxLength}`;
eventArgs.state = enums_1.EnumValidateState.maxLength;
eventArgs.cancel = true;
}
}
};
this.isValueEmpty = () => {
return typeof __classPrivateFieldGet(this, _NumberBoxFactory_value, "f") === 'string' && __classPrivateFieldGet(this, _NumberBoxFactory_value, "f") !== '';
};
this.isValueNotEmpty = () => {
return !this.isValueEmpty();
};
if (typeof initialValue === 'number') {
__classPrivateFieldSet(this, _NumberBoxFactory_defaultValue, initialValue, "f");
__classPrivateFieldSet(this, _NumberBoxFactory_value, initialValue, "f");
}
else {
__classPrivateFieldSet(this, _NumberBoxFactory_defaultValue, null, "f");
__classPrivateFieldSet(this, _NumberBoxFactory_value, null, "f");
}
if (Cach_1.Cach.isCached(this)) {
const cach = Cach_1.Cach.getCached(this);
__classPrivateFieldSet(this, _NumberBoxFactory_value, cach.value, "f");
this.validation = cach.validation;
this._hasChange = cach.hasChange;
}
}
}
exports.NumberBoxFactory = NumberBoxFactory;
_NumberBoxFactory_value = new WeakMap(), _NumberBoxFactory_defaultValue = new WeakMap();