import * as widgets from "oasi-widgets"; import { FolderInfo, FileRestService, FileOldSystemRestService } from 'isogd-file-rest'; import { DocumentIsogd, DocumentRestService, DocumentIsogdWrapper } from "isogd-document-rest"; import { NsiRestService } from "oasi-nsi-rest"; class FilesEditController { static $inject = ['$state', 'documentRestService', '$timeout', 'blockUI', '$uibModal', 'fileRestService', 'fileOldSystemRestService', 'nsiRestService']; private loadingStatus: widgets.LoadingStatus = widgets.LoadingStatus.LOADING; private document: DocumentIsogd; private folder: FolderInfo; private code: string; private isOld: boolean; private registry: any; private extensions = ['pdf', 'tiff', 'tif', 'jpg', 'jpeg', 'doc', 'docx']; constructor(private $state: any, private documentRestService: DocumentRestService, private $timeout: any, private blockUI: any, private $uibModal: any, private fileRestService: FileRestService, private fileOldSystemRestService: FileOldSystemRestService, private nsiRestService: NsiRestService) { } $onInit() { this.loadingStatus = widgets.LoadingStatus.LOADING; this.nsiRestService.getBy("OldChapters", { nickAttr: "chapterCode", values: [this.document.reestr] }).then(response => { this.registry = response[0]; if (this.document.folderID) { this.isOld = false; } else { if (this.document.oldFolderID) { this.isOld = true; } else { this.isOld = undefined; } } let promise: ng.IPromise; if (this.isOld !== undefined) { if (!this.isOld) { promise = this.fileRestService.filesTree(this.document.folderID, "1level"); } else { promise = this.fileOldSystemRestService.filesTreeOld(this.document.oldFolderID, "1levels"); } promise.then(response => { this.folder = response; this.loadingStatus = widgets.LoadingStatus.SUCCESS; }).catch(error => { this.loadingStatus = widgets.LoadingStatus.ERROR; console.log(error); }); } else { this.loadingStatus = widgets.LoadingStatus.SUCCESS; } }); } createFolder() { let modalInstance = this.$uibModal.open({ template: require('../common/confirmation.html'), controller: 'ConfirmController as ctrl', size: "md", backdrop: 'static', keyboard: false, windowClass: "delete-file-modal", resolve: { title: () => { return "Создание каталога" }, message: () => { return "Создать каталог {" + this.document.documentID + "} в FileNet?" }, btnOk: () => { return "Создать" } } }); modalInstance.result.then((result: any) => { this.$timeout(1500).then(response => { let params = { folderName: this.document.documentID, parentGuid: this.registry.folderID, folderType: this.registry.folderClass, folderAttrs: [] }; return this.fileRestService.createFolder(params); }).then((response) => { this.document.folderID = response.guid; return this.$timeout(1500); }).then(response => { return this.documentRestService.getDocument(this.document.documentID); }).then((response: DocumentIsogdWrapper) => { response.document.folderID = this.document.folderID; return this.documentRestService.update(this.document.documentID, { document: response.document }); }).then(response => { this.$state.reload(); }).catch((error) => { console.log(error); }); }).catch(error => { }); } } export const FilesEditComponent: angular.IComponentOptions = { controller: FilesEditController, template: require('./files-edit.html'), bindings: { document: '<' } };