1 import {Component, OnInit, Input, ViewChild} from '@angular/core';
2 import {NetService} from '@eg/core/net.service';
3 import {StoreService} from '@eg/core/store.service';
4 import {EventService} from '@eg/core/event.service';
5 import {ToastService} from '@eg/share/toast/toast.service';
6 import {AuthService} from '@eg/core/auth.service';
7 import {DialogComponent} from '@eg/share/dialog/dialog.component';
8 import {NgbModal, NgbModalOptions} from '@ng-bootstrap/ng-bootstrap';
9 import {StringComponent} from '@eg/share/string/string.component';
13 * Dialog for transferring holds.
17 selector: 'eg-hold-transfer-dialog',
18 templateUrl: 'transfer-dialog.component.html'
21 export class HoldTransferDialogComponent
22 extends DialogComponent implements OnInit {
24 @Input() holdIds: number | number[];
26 @ViewChild('successMsg') private successMsg: StringComponent;
27 @ViewChild('errorMsg') private errorMsg: StringComponent;
28 @ViewChild('targetNeeded') private targetNeeded: StringComponent;
30 transferTarget: number;
31 changesApplied: boolean;
36 private modal: NgbModal, // required for passing to parent
37 private toast: ToastService,
38 private store: StoreService,
39 private net: NetService,
40 private evt: EventService,
41 private auth: AuthService) {
42 super(modal); // required for subclassing
47 async open(args: NgbModalOptions): Promise<boolean> {
48 this.holdIds = [].concat(this.holdIds); // array-ify ints
51 this.store.getLocalItem('eg.circ.hold.title_transfer_target');
53 if (!this.transferTarget) {
54 this.toast.warning(await this.targetNeeded.current());
55 return Promise.reject('Transfer Target Required');
58 return super.open(args);
61 async transferHolds(): Promise<any> {
62 return this.net.request(
64 'open-ils.circ.hold.change_title.specific_holds',
65 this.auth.token(), this.transferTarget, this.holdIds
66 ).toPromise().then(async(result) => {
67 if (Number(result) === 1) {
69 this.toast.success(await this.successMsg.current());
72 console.error('Retarget Failed', this.evt.parse(result));
73 this.toast.warning(await this.errorMsg.current());
78 async transferBatch(): Promise<any> {
79 this.numSucceeded = 0;
81 await this.transferHolds();
82 this.close(this.numSucceeded > 0);