Use Operation Delete Modal in List Component.

This commit is contained in:
Alexis Lahouze 2017-07-30 15:35:26 +02:00
parent 162d98add7
commit bc4a69b64c

View File

@ -2,14 +2,15 @@
import { CurrencyPipe } from '@angular/common'; import { CurrencyPipe } from '@angular/common';
import { Component, Inject, Input, Output, EventEmitter } from '@angular/core'; import { Component, Inject, Input, Output, EventEmitter } from '@angular/core';
import { NgbModal } from '@ng-bootstrap/ng-bootstrap';
import { ToastrService } from 'ngx-toastr'; import { ToastrService } from 'ngx-toastr';
var operationFormTmpl = require('./operation.form.tmpl.html'), var operationFormTmpl = require('./operation.form.tmpl.html');
operationDeleteTmpl = require('./operation.delete.tmpl.html');
import { Account } from '../accounts/account'; import { Account } from '../accounts/account';
import { Operation } from './operation'; import { Operation } from './operation';
import { OperationService } from './operation.service'; import { OperationService } from './operation.service';
import { OperationDeleteModalComponent } from './operationDeleteModal.component';
@Component({ @Component({
selector: 'tr[operation-row]', selector: 'tr[operation-row]',
@ -80,6 +81,7 @@ export class OperationRowComponent {
constructor( constructor(
private operationService: OperationService, private operationService: OperationService,
private toastrService: ToastrService, private toastrService: ToastrService,
private modal: NgbModal,
@Inject('$modal') private $modal, @Inject('$modal') private $modal,
) {} ) {}
@ -110,26 +112,16 @@ export class OperationRowComponent {
} }
confirmDelete(operation) { confirmDelete(operation) {
var title = "Delete operation #" + operation.id; const modal = this.modal.open(OperationDeleteModalComponent);
this.$modal({ modal.componentInstance.operation = this.operation;
templateUrl: operationDeleteTmpl,
controller: function($scope, title, operation, $delete) { var id = operation.id;
$scope.title = title;
$scope.operation = operation; modal.result.then((operation: Operation) => {
$scope.$delete = () => {
$scope.$hide();
$delete($scope.operation);
};
},
locals: {
title: title,
operation: operation,
$delete: (operation: Operation) => {
this.delete(operation); this.delete(operation);
} }, (reason) => {
} })
});
}; };
delete(operation) { delete(operation) {