1 import {Component, EventEmitter, Output, ViewChild} from '@angular/core';
2 import {switchMap} from 'rxjs/operators';
3 import {AuthService} from '@eg/core/auth.service';
4 import {NetService} from '@eg/core/net.service';
5 import {ToastService} from '@eg/share/toast/toast.service';
6 import {ConfirmDialogComponent} from '@eg/share/dialog/confirm.component';
9 selector: 'eg-cancel-reservation-dialog',
11 <eg-confirm-dialog #confirmCancelReservationDialog
12 i18n-dialogTitle i18n-dialogBody
13 dialogTitle="Confirm Cancelation"
14 [dialogBodyTemplate]="confirmMessage">
16 <ng-template #confirmMessage>
18 Are you sure you want to cancel
19 {reservations.length, plural, =1 {this reservation} other {these {{reservations.length}} reservations}}?
25 export class CancelReservationDialogComponent {
28 private auth: AuthService,
29 private net: NetService,
30 private toast: ToastService
34 reservations: number[];
36 @ViewChild('confirmCancelReservationDialog')
37 private cancelReservationDialog: ConfirmDialogComponent;
39 @Output() onSuccessfulCancel = new EventEmitter();
41 open(reservations: number[]) {
42 this.reservations = reservations;
43 this.cancelReservationDialog.open()
45 switchMap(() => this.net.request(
47 'open-ils.booking.reservations.cancel',
48 this.auth.token(), reservations))
53 this.toast.danger('Could not cancel reservation'); // TODO: needs i18n, pluralization
55 this.toast.success('Reservation successfully canceled'); // TODO: needs i18n, pluralization
56 this.onSuccessfulCancel.emit();