From 1c18d93d137479aa30caaef73a0bd6a74a8a80e1 Mon Sep 17 00:00:00 2001 From: Alexis Lahouze Date: Sun, 30 Jul 2017 16:15:22 +0200 Subject: [PATCH] Use Operation Edit form to edit operation in Operation Row component. --- src/operations/operationRow.component.ts | 34 ++++++++---------------- 1 file changed, 11 insertions(+), 23 deletions(-) diff --git a/src/operations/operationRow.component.ts b/src/operations/operationRow.component.ts index 0b9da73..6991a4d 100644 --- a/src/operations/operationRow.component.ts +++ b/src/operations/operationRow.component.ts @@ -5,12 +5,11 @@ import { Component, Inject, Input, Output, EventEmitter } from '@angular/core'; import { NgbModal } from '@ng-bootstrap/ng-bootstrap'; import { ToastrService } from 'ngx-toastr'; -var operationFormTmpl = require('./operation.form.tmpl.html'); - import { Account } from '../accounts/account'; import { Operation } from './operation'; import { OperationService } from './operation.service'; import { OperationDeleteModalComponent } from './operationDeleteModal.component'; +import { OperationEditModalComponent } from './operationEditModal.component'; @Component({ selector: 'tr[operation-row]', @@ -81,8 +80,7 @@ export class OperationRowComponent { constructor( private operationService: OperationService, private toastrService: ToastrService, - private modal: NgbModal, - @Inject('$modal') private $modal, + private ngbModal: NgbModal, ) {} togglePointed(operation, rowform) { @@ -112,7 +110,7 @@ export class OperationRowComponent { } confirmDelete(operation) { - const modal = this.modal.open(OperationDeleteModalComponent); + const modal = this.ngbModal.open(OperationDeleteModalComponent); modal.componentInstance.operation = this.operation; @@ -141,25 +139,15 @@ export class OperationRowComponent { modify(operation) { // FIXME Alexis Lahouze 2017-06-15 i18n - var title = "Modify operation #" + operation.id; + const modal = this.ngbModal.open(OperationEditModalComponent, { + windowClass: 'in' + }); - this.$modal({ - templateUrl: operationFormTmpl, - controller: function($scope, title, operation, $save) { - $scope.title = title; - $scope.operation = operation; - $scope.$save = () => { - $scope.$hide(); - $save($scope.operation); - }; - }, - locals: { - title: title, - operation: operation, - $save: (operation: Operation) => { - this.save(operation); - } - } + modal.componentInstance.operation = operation; + + modal.result.then((operation: Operation) => { + this.save(operation); + }, (reason) => { }); }; }