1 import {Component, OnInit, Input, ViewChild} from '@angular/core';
2 import {Observable, throwError} from 'rxjs';
3 import {NetService} from '@eg/core/net.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 marking items missing.
17 selector: 'eg-mark-missing-dialog',
18 templateUrl: 'mark-missing-dialog.component.html'
21 export class MarkMissingDialogComponent
22 extends DialogComponent implements OnInit {
24 @Input() copyIds: number[];
29 @ViewChild('successMsg', { static: true })
30 private successMsg: StringComponent;
32 @ViewChild('errorMsg', { static: true })
33 private errorMsg: StringComponent;
36 private modal: NgbModal, // required for passing to parent
37 private toast: ToastService,
38 private net: NetService,
39 private evt: EventService,
40 private auth: AuthService) {
41 super(modal); // required for subclassing
46 open(args: NgbModalOptions): Observable<boolean> {
47 this.numSucceeded = 0;
49 return super.open(args);
52 async markOneItemMissing(ids: number[]): Promise<any> {
53 if (ids.length === 0) {
54 return Promise.resolve();
59 return this.net.request(
61 'open-ils.circ.mark_item_missing',
63 ).toPromise().then(async(result) => {
64 if (Number(result) === 1) {
66 this.toast.success(await this.successMsg.current());
69 console.error('Mark missing failed ', this.evt.parse(result));
70 this.toast.warning(await this.errorMsg.current());
72 return this.markOneItemMissing(ids);
76 async markItemsMissing(): Promise<any> {
77 this.numSucceeded = 0;
79 const ids = [].concat(this.copyIds);
80 await this.markOneItemMissing(ids);
81 this.close(this.numSucceeded > 0);