Bootstrap new operation page.
This commit is contained in:
parent
d3e73ba739
commit
f3d71fd081
@ -48,9 +48,9 @@ import { OperationEditModalComponent } from './operationEditModal.component';
|
|||||||
<tbody>
|
<tbody>
|
||||||
<tr>
|
<tr>
|
||||||
<td colspan="6">
|
<td colspan="6">
|
||||||
<button class="btn btn-success" (click)="add()">
|
<a class="btn btn-success" routerLink="/account/{{account.id}}/operations/new">
|
||||||
Ajouter
|
Ajouter
|
||||||
</button>
|
</a>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
|
||||||
|
@ -1,19 +1,83 @@
|
|||||||
// vim: set tw=80 ts=2 sw=2 sts=2 :
|
// vim: set tw=80 ts=2 sw=2 sts=2 :
|
||||||
|
|
||||||
import { Component, OnInit } from '@angular/core';
|
import { Location } from '@angular/common';
|
||||||
|
import { Component, ViewChild } from '@angular/core';
|
||||||
import { ActivatedRoute, Router } from '@angular/router';
|
import { ActivatedRoute, Router } from '@angular/router';
|
||||||
|
|
||||||
|
import { Logger } from '@nsalaun/ng-logger';
|
||||||
|
import { ToastrService } from 'ngx-toastr';
|
||||||
|
|
||||||
|
import { Operation } from './operation';
|
||||||
|
import { OperationService } from './operation.service';
|
||||||
|
import { OperationFormComponent } from './operationForm.component';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'operation-new',
|
selector: 'operation-new',
|
||||||
template: `
|
template: `
|
||||||
<div>
|
<div>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
|
<operation-form (submit)="submit()" #operationForm="operationForm">
|
||||||
|
</operation-form>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="row">
|
||||||
|
<button class="btn btn-primary" [disabled]="!operationForm.form.valid" (click)="submit()">
|
||||||
|
Save
|
||||||
|
</button>
|
||||||
|
|
||||||
|
<button class="btn btn-default" (click)="cancel()">
|
||||||
|
Cancel
|
||||||
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
`
|
`
|
||||||
})
|
})
|
||||||
export class OperationNewComponent implements OnInit {
|
export class OperationNewComponent {
|
||||||
ngOnInit(): void {
|
@ViewChild('operationForm') operationForm: OperationFormComponent;
|
||||||
|
|
||||||
|
constructor(
|
||||||
|
private location: Location,
|
||||||
|
private router: Router,
|
||||||
|
private activatedRoute: ActivatedRoute,
|
||||||
|
private logger: Logger,
|
||||||
|
private toastrService: ToastrService,
|
||||||
|
private operationService: OperationService
|
||||||
|
) {}
|
||||||
|
|
||||||
|
submit(): void {
|
||||||
|
let accountId = this.activatedRoute.snapshot.paramMap.get('accountId');
|
||||||
|
let formModel = this.operationForm.form.value;
|
||||||
|
let operation = new Operation();
|
||||||
|
|
||||||
|
operation.account_id = +accountId;
|
||||||
|
operation.operation_date = formModel.operationDate;
|
||||||
|
operation.label = formModel.label;
|
||||||
|
operation.value = formModel.value;
|
||||||
|
operation.category = formModel.category;
|
||||||
|
|
||||||
|
this.save(operation);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Save an operation and return a promise.
|
||||||
|
*/
|
||||||
|
save(operation) {
|
||||||
|
operation.confirmed = true;
|
||||||
|
|
||||||
|
return this.operationService.create(operation).subscribe(
|
||||||
|
(operation) => {
|
||||||
|
this.toastrService.success('Operation #' + operation.id + ' saved.');
|
||||||
|
|
||||||
|
this.location.back();
|
||||||
|
}, (result) => {
|
||||||
|
this.toastrService.error(
|
||||||
|
'Error while saving operation: ' + result.message
|
||||||
|
);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
cancel(): void {
|
||||||
|
this.location.back();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user