armisa-models
Version:
models of armisa!
104 lines (103 loc) • 4.54 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.LockUnLockViewBargeFactory = void 0;
class LockUnLockViewBargeFactory {
get isValid() {
return this.message === null;
}
constructor(viewBargeFactory, axiosData, id, yearId) {
this.viewBargeFactory = viewBargeFactory;
this.axiosData = axiosData;
this.message = null;
this.controllerPath = '';
this.actionLockPath = 'lock';
this.actionUnLockPath = 'unLock';
this.id = 0;
this.yearId = 0;
this.toggel = (fieldName) => {
if (!fieldName) {
this.viewBargeFactory.elementsOfForm.showInvalidArgumentMessageBox('Field Name did not pass correctlly!!!');
return;
}
const currentValue = this.viewBargeFactory.lastResponse.getProp(fieldName);
if (currentValue) {
this.unLock(fieldName);
}
else {
this.lock(fieldName);
}
};
this.lock = (fieldName) => {
if (!fieldName) {
this.viewBargeFactory.elementsOfForm.showInvalidArgumentMessageBox('Field Name did not pass correctlly!!!');
return;
}
if (this.isValid) {
this.lockUnLock(this.actionLockPath, () => {
this.viewBargeFactory.lastResponse.setProp(fieldName, true);
});
}
else {
this.viewBargeFactory.elementsOfForm.showInvalidArgumentMessageBox(this.message);
}
};
this.unLock = (fieldName) => {
if (!fieldName) {
this.viewBargeFactory.elementsOfForm.showInvalidArgumentMessageBox('Field Name did not pass correctlly!!!');
return;
}
if (this.isValid) {
this.lockUnLock(this.actionUnLockPath, () => {
this.viewBargeFactory.lastResponse.setProp(fieldName, false);
});
}
else {
this.viewBargeFactory.elementsOfForm.showInvalidArgumentMessageBox(this.message);
}
};
this.lockUnLock = (path, afterSuccessed) => {
if (!(this.axiosData)) {
this.viewBargeFactory.elementsOfForm.showInvalidArgumentMessageBox('تنظیمات به درستی انجام نشده است');
return;
}
this.viewBargeFactory.elementsOfForm.showWaitingFormSpinner();
this.axiosData.axios(this.controllerPath).post(`${path}/${this.id}/${this.yearId}`, {}, this.viewBargeFactory.mainStateManager.tokenInfo.headerOfAxios)
.then(response => {
if (response.data.isSuccess) {
afterSuccessed();
this.viewBargeFactory.elementsOfForm.closeWaitingFormSpinner();
this.viewBargeFactory.forceUpdate();
}
else {
this.viewBargeFactory.elementsOfForm.closeWaitingFormSpinner();
this.viewBargeFactory.elementsOfForm.showInvalidArgumentMessageBox(response.data.messageRoot);
}
})
.catch(e => {
this.viewBargeFactory.elementsOfForm.closeWaitingFormSpinner();
this.viewBargeFactory.elementsOfForm.showErrorMessageBox(e);
});
};
if (typeof id === 'number' && id > 0) {
this.id = id;
}
else {
this.message = 'شناسه برگه به درستی شناسایی نشده است ';
}
if (this.isValid && typeof yearId === 'number' && yearId > 0) {
this.yearId = yearId;
}
else {
this.message = 'دوره مالی برگه به درستی شناسایی نشده است ';
}
if (this.isValid && this.axiosData) {
this.controllerPath = this.axiosData.controllerLockUnLockPath || this.axiosData.controllerPath;
this.actionLockPath = this.axiosData.actionLockPath || 'lock';
this.actionUnLockPath = this.axiosData.actionUnLockPath || 'unLock';
}
else {
this.message = 'اطلاعات ارتباطی به درستی ثبت نشده است ';
}
}
}
exports.LockUnLockViewBargeFactory = LockUnLockViewBargeFactory;