import * as _ from "lodash"; import { DocumentIsogd, TEP } from "isogd-document-rest"; class DocumentTepEditController { private document: DocumentIsogd; private teps: any[]; tepCodeChanged(tep: any) { if (tep.tepCode) { let dictTep = this.getTepByCode(tep.tepCode); tep.tepName = dictTep.tepName; } else { tep.tepName = ''; } } tepValueChanged(idx, value) { if (!this.hasEmptyTep()) { this.addNewTep(); } if (value === "") { this.document.teps this.document.teps.splice(idx, 1); } } getTepByCode(code): any { return _.find(this.teps, tep => { return tep.tepCode == code; }); } addNewTep() { let newTep: TEP = new TEP(); this.document.teps.push(newTep); } hasEmptyTep() { return _.some(this.document.teps, tep => { return tep.tepValue === ""; }); } } export const DocumentTepEditComponent: angular.IComponentOptions = { controller: DocumentTepEditController, template: require('./documentTepEdit.html'), bindings: { document: "<", teps: "<" } };