accountant-ui/src/accounts/accountEditModal.component.ts

54 lines
1.2 KiB
TypeScript
Raw Normal View History

2017-07-20 10:32:05 +02:00
// vim: set tw=80 ts=2 sw=2 sts=2:
import { Component, Input } from '@angular/core';
2017-07-20 22:52:33 +02:00
import { NgForm } from '@angular/forms';
2017-07-20 10:32:05 +02:00
import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap';
import { Account } from './account';
@Component({
selector: 'account-edit-modal',
template: `
<div class="modal-header">
<h3 class="modal-title" id="modal-title">{{ title() }}</h3>
</div>
<div class="modal-body" id="modal-body">
2017-07-20 22:52:33 +02:00
<account-form [(account)]="account" (onFormChanged)="accountForm = $event"></account-form>
2017-07-20 10:32:05 +02:00
</div>
<div class="modal-footer">
2017-07-20 22:52:33 +02:00
<button class="btn btn-primary" [disabled]="!accountForm?.form.valid" (click)="submit()">
2017-07-20 10:32:05 +02:00
Save
</button>
<button class="btn btn-default" (click)="cancel()">
Cancel
</button>
</div>
`
})
export class AccountEditModalComponent {
2017-07-20 22:52:33 +02:00
@Input() account: Account;
accountForm: NgForm;
2017-07-20 10:32:05 +02:00
constructor(public activeModal: NgbActiveModal) {}
title(): string {
if(this.account.id) {
return "Account #" + this.account.id;
} else {
return "New account";
}
}
submit(): void {
this.activeModal.close(this.account);
}
cancel(): void {
this.activeModal.dismiss("closed");
}
}