import { ITreeViewItemChecked } from "oasi-widgets"; import { DocumentIsogd, DocumentObject } from "isogd-document-rest"; class DocumentObjectEditController { static $inject = ['$uibModal']; private document: DocumentIsogd; private finance: any[]; private selectedFinance: any; private fnos: any[]; private notFoundFinance: string[]; constructor(private $uibModal: ng.ui.bootstrap.IModalService) { } onObjectFinanceChange() { this.document.object.objectFinanceCode = this.selectedFinance.financeCode; this.document.object.objectFinanceValue = this.selectedFinance.financeName; } clearFNO() { delete this.document.object.objectTypeCode; delete this.document.object.objectTypeName; } chooseFNO() { let tree = this.buildSelectedTree(this.fnos); this.$uibModal.open({ component: 'dictionary-modal', size: 'lg', resolve: { name: () => { return 'Выбор функционального назначения (306-ПП)'; }, multiple: () => { return false; }, tree: () => { return tree; }, selectedItems: () => { let object = this.document.object; return object ? [object.objectTypeCode] : []; } } }).result.then((result: string[]) => { if (result && result.length > 0) { let fno = this.findInDictByCode(this.fnos, result[0]); this.document.object = new DocumentObject(this.document.object); this.document.object.objectTypeCode = fno.fnoCode; this.document.object.objectTypeName = fno.fnoName; } }); } findInDictByCode(dict: any[], code: string): any { let result: any = null; dict.forEach(d => { if (d.fnoCode === code) { result = d; } if (d.children !== undefined && d.children !== null) { let r = this.findInDictByCode(d.children, code); if (r !== null) { result = r; } } }); return result; } buildSelectedTree(dict: any[]): ITreeViewItemChecked[] { let tree: ITreeViewItemChecked[] = null; dict.forEach(item => { if (tree === null) { tree = []; } let children: ITreeViewItemChecked[] = (item.children === undefined || item.children === null) ? null : this.buildSelectedTree(item.children); let template = item.fnoName + ' [' + item.fnoCode + ']'; let result: ITreeViewItemChecked = { parent: null, id: item.fnoCode, template: template, children: children, expanded: false, checked: false, disabled: false, selectable: true }; if (children) { children.forEach(ch => { ch.parent = result; }) } tree.push(result); }); return tree; } } export const DocumentObjectEditComponent: angular.IComponentOptions = { controller: DocumentObjectEditController, template: require('./documentObjectEdit.html'), bindings: { document: "<", finance: "<", selectedFinance: "<", fnos: "<", notFoundFinance: "<" } };