import { DocumentLinkRestService } from "isogd-document-link-rest"; import { IParcelDossierWrapper, DossierRestService, DossierLinkRestService } from "isogd-dossier-rest"; import * as _ from "lodash"; import { LinkedDocumentService } from "../../services/LinkedDocumentService"; import { DocumentIsogd, DocumentRestService } from "isogd-document-rest"; import { NsiRestService } from "oasi-nsi-rest"; interface INewDossier { reason: string; cadastral: string; district: any; prefect: any; address: string; } class NewDossierController { static $inject = ['linkedDocumentService', 'toastr', '$timeout', 'documentLinkRestService', 'blockUI', 'nsiRestService', '$q', 'dossierRestService', 'dossierLinkRestService', 'documentRestService']; private document: DocumentIsogd; private newDossier: INewDossier = { reason: "cad", cadastral: "", district: null, prefect: null, address: "" }; private districts: any[]; private prefects: any[]; private chapters: any[]; private onUpdate: () => void; private myBlockUI: any; constructor(private linkedDocumentService: LinkedDocumentService, private toastr: Toastr, private $timeout: ng.ITimeoutService, private documentLinkRestService: DocumentLinkRestService, private blockUI: any, private nsiRestService: NsiRestService, private $q: ng.IQService, private dossierRestService: DossierRestService, private dossierLinkRestService: DossierLinkRestService, private documentRestService: DocumentRestService) { } $onInit() { if (this.document.object && this.document.object.objectAddress) { this.newDossier.address = this.document.object.objectAddress; } this.newDossier.address = this.newDossier.address.trim(); this.myBlockUI = this.blockUI.instances.get("newDossier"); } $onDestroy() { this.myBlockUI.reset(); } create() { this.myBlockUI.start(); this.$timeout(1500).then(response => { this.dossierRestService.findDossierByCadastralNumber(this.newDossier.cadastral).then(response => { if (response) { this.myBlockUI.stop(); this.toastr.warning("Дело с таким кадастровым номером уже существует!"); } else { let params: IParcelDossierWrapper = { parcelDossier: { cadastralNumber: this.newDossier.cadastral, address: this.newDossier.address } }; if (this.newDossier.reason === "cad" && this.newDossier.cadastral !== "") { params.parcelDossier.cadastralNumber = this.newDossier.cadastral; } if (this.newDossier.prefect) { params.parcelDossier.area = { areaName: this.newDossier.prefect.name, areaCode: this.newDossier.prefect.code }; } if (this.newDossier.district) { params.parcelDossier.district = { districtName: this.newDossier.district.name, districtCode: this.newDossier.district.code }; } this.dossierRestService.createDossier(params).then(response => { this.toastr.success("Новое дело успешно создано!"); this.dossierLinkRestService.create({ dossierId: response.parcelDossier.dossierId, docId: this.document.documentID }).then(response => { this.myBlockUI.stop(); this.toastr.success("Связь дела и документа установлена!"); this.onUpdate(); }).catch(error => { this.myBlockUI.stop(); this.toastr.error("Ошибка при связывании дела и документа!"); }); }).catch(error => { this.myBlockUI.stop(); this.toastr.error("Ошибка при создании нового дела!"); }); } }).catch(error => { this.myBlockUI.stop(); this.toastr.warning("Ошибка при создании нового дела!"); console.log(error); }); }); } } export const NewDossierComponent: angular.IComponentOptions = { controller: NewDossierController, template: require('./newDossier.html'), bindings: { document: '<', districts: '<', prefects: '<', chapters: '<', onUpdate: "&" } };