Use Operation Edit form to add new operation in Operation List component.

This commit is contained in:
Alexis Lahouze 2017-07-30 16:11:47 +02:00
parent f6bcdcfc2b
commit 6da1861139
1 changed files with 14 additions and 22 deletions

View File

@ -1,14 +1,15 @@
import { Component, Inject, OnInit } from '@angular/core';
import { Observable } from 'rxjs/Rx';
import { Logger } from '@nsalaun/ng-logger';
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 { AccountService } from '../accounts/account.service';
import { Operation } from './operation';
import { OperationService } from './operation.service';
import { OperationEditModalComponent } from './operationEditModal.component';
@Component({
selector: 'operation-list',
@ -68,11 +69,12 @@ export class OperationListComponent implements OnInit {
private operations: Operation[];
constructor(
@Inject("$modal") private $modal,
@Inject("accountIdService") private accountIdService,
private toastrService: ToastrService,
private operationService: OperationService,
private accountService: AccountService
private accountService: AccountService,
private logger: Logger,
private ngbModal: NgbModal,
) {}
ngOnInit() {
@ -136,25 +138,15 @@ export class OperationListComponent implements OnInit {
modify(operation) {
// FIXME Alexis Lahouze 2017-06-15 i18n
var title = "New operation";
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) => {
});
};