UNPKG

armisa-models

Version:
185 lines (184 loc) 9.1 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 _SimpleCodeFactory_defaultValue, _SimpleCodeFactory_code, _SimpleCodeFactory_text; Object.defineProperty(exports, "__esModule", { value: true }); exports.SimpleCodeFactory = void 0; const nums2persian_1 = require("nums2persian"); const enums_1 = require("../../enums"); const ElementFactory_1 = require("../../Page/ElementsOfFormFactory/ElementFactory"); const Cach_1 = require("../Cach"); const TokenInfo_1 = require("../../AmisaAuth/Models/StorageManager/TokenInfo"); class SimpleCodeFactory extends ElementFactory_1.ElementFactory { get any() { return this; } refreshAllfromOfMainCode(_data) { // if (this.isMainCodeOfPage) { // this.pageData.ValidatingControl.controls.forEach((property) => { // const control = this.pageData.selfState[property.propertyName]; // if (control.keyOfJSON && // control.propertyName && // control !== this) { // // deserializeFormControlFromMainCodeNew(data, control, this.pageData.selfState); // if (control.onChangePropertyName) { // const onChangePropertyName = control[control.onChangePropertyName]; // onChangePropertyName && onChangePropertyName(control); // } // } // }); // this.pageData.TouchingControl.resetAllTouched(); // this.pageData.ChangingControl.resetAllChangeNew(); // this.pageData.Eventing.trigger('change'); // } } get text() { return __classPrivateFieldGet(this, _SimpleCodeFactory_text, "f") || ''; } setText(text) { __classPrivateFieldSet(this, _SimpleCodeFactory_text, text, "f"); this.forceUpdate(); } get value() { return __classPrivateFieldGet(this, _SimpleCodeFactory_code, "f"); } get code() { return __classPrivateFieldGet(this, _SimpleCodeFactory_code, "f") || 0; } setValue(code) { __classPrivateFieldSet(this, _SimpleCodeFactory_code, code, "f"); Cach_1.Cach.setValue(this, { name: this.name, id: this.id, codeValueState: this.codeValueState, code: this.code, text: this.text }); this.forceUpdate(); } constructor(_mainStateFactory, _fieldName, _dispose, urls, isMainCodeOfPage, required, caption, showHasChangeFlag, tabIndex, payLoadKey, responseKey, history) { super(_mainStateFactory, _fieldName, _dispose, payLoadKey, responseKey, history); this.isMainCodeOfPage = isMainCodeOfPage; this.required = required; this.caption = caption; this.showHasChangeFlag = showHasChangeFlag; this.tabIndex = tabIndex; this.forceUpdate = () => { }; this.focusToElement = () => { this.mainStateFactory.elementsOfForm.focuseToThisElement(this); }; this.name = ''; this.id = null; this.setValidationState = (result) => { this.codeValueState = result === null ? 'ok' : result === 0 ? 'newCode' : 'clear'; }; this.codeWaitForLoad = null; this.timerForLoad = null; this.clearTimerForLoad = () => { if (this.timerForLoad) { clearTimeout(this.timerForLoad); } }; this.getCodeData = () => { this.clearTimerForLoad(); this.timerForLoad = setTimeout(() => { this.codeWaitForLoad = this.text; this.getCodeDataAxios(); }, 500); }; this.getCodeDataAxios = () => { if (this.codeWaitForLoad === '') { this.clearData(); return; } this.forceUpdateSpinner(); this.apiAxios.get(`${this.urls.get}/${this.codeWaitForLoad}`) .then((response) => { if (response.data.isSuccess) { this.name = response.data.data.name; this.id = response.data.data.id; this.setValidationState(response.data.result); // this.pageData.Eventing.trigger('form.GetNewCodeSuccessFull', response.data.data); this.validate(); Cach_1.Cach.setValue(this, { name: this.name, id: this.id, codeValueState: this.codeValueState, code: this.code, text: this.text }); this.refreshAllfromOfMainCode(response.data.data); this.codeWaitForLoad = null; this.forceUpdate(); } else { console.error('some thing went wrong'); this.forceUpdate(); } }) .catch((error) => { console.error('some thing went wrong : ', error); this.forceUpdate(); }); }; ///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; } this.validation = true; return this.validation; }; _SimpleCodeFactory_defaultValue.set(this, null); this.restartDefaultValue = () => { __classPrivateFieldSet(this, _SimpleCodeFactory_defaultValue, this.code, "f"); this.refreshHasChange(); }; this.refreshHasChange = () => { if (this.showHasChangeFlag) { this._hasChange = __classPrivateFieldGet(this, _SimpleCodeFactory_defaultValue, "f") !== __classPrivateFieldGet(this, _SimpleCodeFactory_code, "f"); } }; _SimpleCodeFactory_code.set(this, null); _SimpleCodeFactory_text.set(this, null); this.deseriallize = (e) => { }; this.clearData = () => { Cach_1.Cach.clear(this); __classPrivateFieldSet(this, _SimpleCodeFactory_code, null, "f"); __classPrivateFieldSet(this, _SimpleCodeFactory_text, '', "f"); __classPrivateFieldSet(this, _SimpleCodeFactory_defaultValue, null, "f"); this.validation = true; this._hasChange = false; this.codeValueState = 'clear'; this.childCount = 0; this.forceUpdate(); }; this.forceUpdateSpinner = () => { }; this.onChangeHandlerElement = (element) => { const valueNotPersian = element.value; this.onChangeHandlerCode(valueNotPersian); }; this.onChangeHandlerCode = (code) => { const value = (0, nums2persian_1.persianStringToEnglishString)(code, false); __classPrivateFieldSet(this, _SimpleCodeFactory_code, +value, "f"); this.setText(value); }; this.urls = urls; this.apiAxios = (0, TokenInfo_1.useAxios)(this.urls); if (Cach_1.Cach.isCached(this)) { const cach = Cach_1.Cach.getCached(this); this.name = cach.value.name; this.id = cach.value.id; this.codeValueState = cach.value.codeValueState; __classPrivateFieldSet(this, _SimpleCodeFactory_code, cach.value.code, "f"); __classPrivateFieldSet(this, _SimpleCodeFactory_text, cach.value.text, "f"); this.validation = cach.validation; this._hasChange = cach.hasChange; } } } exports.SimpleCodeFactory = SimpleCodeFactory; _SimpleCodeFactory_defaultValue = new WeakMap(), _SimpleCodeFactory_code = new WeakMap(), _SimpleCodeFactory_text = new WeakMap();