2017-07-30 15:55:24 +02:00
|
|
|
// vim: set tw=80 ts=2 sw=2 sts=2:
|
2017-08-13 12:28:10 +02:00
|
|
|
import { Component, Input, ViewChild } from '@angular/core';
|
2017-07-30 15:55:24 +02:00
|
|
|
|
|
|
|
import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap';
|
|
|
|
|
|
|
|
import { Operation } from './operation';
|
2017-08-13 12:28:10 +02:00
|
|
|
import { OperationFormComponent } from './operationForm.component';
|
2017-07-30 15:55:24 +02:00
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'operation-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-08-13 12:28:10 +02:00
|
|
|
<operation-form [operation]="operation" (submit)="submit()" #operationForm="operationForm"></operation-form>
|
2017-07-30 15:55:24 +02:00
|
|
|
</div>
|
|
|
|
|
|
|
|
<div class="modal-footer">
|
2017-08-13 12:28:10 +02:00
|
|
|
<button class="btn btn-primary" [disabled]="!operationForm.form.valid" (click)="submit()">
|
2017-07-30 15:55:24 +02:00
|
|
|
Save
|
|
|
|
</button>
|
|
|
|
|
|
|
|
<button class="btn btn-default" (click)="cancel()">
|
|
|
|
Cancel
|
|
|
|
</button>
|
|
|
|
</div>
|
|
|
|
`
|
|
|
|
})
|
|
|
|
export class OperationEditModalComponent {
|
|
|
|
@Input() operation: Operation;
|
2017-08-13 12:28:10 +02:00
|
|
|
@ViewChild('operationForm') operationForm: OperationFormComponent;
|
2017-07-30 15:55:24 +02:00
|
|
|
|
|
|
|
valid: boolean = false;
|
|
|
|
|
|
|
|
constructor(private activeModal: NgbActiveModal) {}
|
|
|
|
|
|
|
|
title(): string {
|
|
|
|
if(this.operation.id) {
|
|
|
|
return "Operation #" + this.operation.id;
|
|
|
|
} else {
|
|
|
|
return "New operation";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
submit(): void {
|
2017-08-13 12:28:10 +02:00
|
|
|
let formModel = this.operationForm.form.value;
|
|
|
|
let operation = Object.assign({}, this.operation);
|
|
|
|
|
|
|
|
operation.id = this.operation.id;
|
|
|
|
operation.operation_date = formModel.operationDate;
|
|
|
|
operation.label = formModel.label;
|
|
|
|
operation.value = formModel.value;
|
|
|
|
operation.category = formModel.category;
|
|
|
|
|
|
|
|
this.activeModal.close(operation);
|
2017-07-30 15:55:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
cancel(): void {
|
|
|
|
this.activeModal.dismiss("closed");
|
|
|
|
}
|
|
|
|
}
|