UNPKG

armisa-models

Version:
111 lines (110 loc) 5.08 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 _AttachedFilesFactory_files; Object.defineProperty(exports, "__esModule", { value: true }); exports.AttachedFile = exports.AttachedFilesFactory = void 0; const ElementFactory_1 = require("../Page/ElementsOfFormFactory/ElementFactory"); const FileDownload_1 = require("./FileDownload"); class AttachedFilesFactory extends ElementFactory_1.ElementFactory { get value() { return this.files?.length || 0; } get tokenInfo() { return this.mainStateManager.tokenInfo; } get selectElement() { return document.getElementById('input-attach-file-selector'); } ; get hasChange() { return false; } get files() { return __classPrivateFieldGet(this, _AttachedFilesFactory_files, "f"); } clearFiles() { __classPrivateFieldSet(this, _AttachedFilesFactory_files, [], "f"); this.forceUpdate(); } constructor(mainStateFactory, fieldName, dispose, axiosData, caption, maxLength, maxSize, placeHolder, tabIndex, payLoadKey, responseKey) { super(mainStateFactory, fieldName, dispose, payLoadKey, responseKey); this.axiosData = axiosData; this.caption = caption; this.maxLength = maxLength; this.maxSize = maxSize; this.placeHolder = placeHolder; this.tabIndex = tabIndex; this.restartDefaultValue = () => { }; this.refreshHasChange = () => { }; this.deseriallize = (jsonValue) => { }; this.clearData = () => { }; this.forceUpdate = () => { }; this.validation = true; this.validate = () => { }; _AttachedFilesFactory_files.set(this, []); this.addFiles = (file) => { const attached = new AttachedFile(file.name, file.size, '', file); __classPrivateFieldGet(this, _AttachedFilesFactory_files, "f").push(attached); }; this.save = (id) => { const header = this.tokenInfo.headerOfAxios.headers; header["content-type"] = "multipart/fom-data"; const formData = new FormData(); this.files.filter(i => i.file !== undefined).forEach(file => formData.append(file.name, file.file, file.name)); return this.axiosData.axios(this.axiosData.controllerPath).post(`${this.axiosData.actionUploadPath}/${id}`, formData, { headers: header }); }; this.download = (id, fileName) => { const header = { responseType: 'blob', headers: { Authorization: `token ${this.tokenInfo.token}` } }; this.axiosData.axios(this.axiosData.controllerPath).get(`${this.axiosData.actionDownloadPath}/${id}`, header) .then((res) => { (0, FileDownload_1.FileDownload)(res.data, fileName); }).catch(error => { this.mainStateFactory.elementsOfForm.showErrorMessageBox(error); }); }; this.mainStateManager = this.mainStateFactory.mainStateManager; } } exports.AttachedFilesFactory = AttachedFilesFactory; _AttachedFilesFactory_files = new WeakMap(); class AttachedFile { constructor(name, size, tozihat, file, id) { this.name = name; this.size = size; this.tozihat = tozihat; this.file = file; this.id = id; if (name.includes('.sheet')) { this.type = 'excel'; } else if (name.includes('.doc')) { this.type = 'doc'; } else if (name.includes('imag')) { this.type = 'image'; } else if (name.includes('pdf')) { this.type = 'pdf'; } else if (name.includes('txt')) { this.type = 'txt'; } else if (name.includes('rar') || name.includes('zip')) { this.type = 'zip'; } else { this.type = 'others'; } } } exports.AttachedFile = AttachedFile;