1 import {Component, OnInit, Input, ViewChild} from '@angular/core';
2 import {NetService} from '@eg/core/net.service';
3 import {EventService} from '@eg/core/event.service';
4 import {ToastService} from '@eg/share/toast/toast.service';
5 import {AuthService} from '@eg/core/auth.service';
6 import {DialogComponent} from '@eg/share/dialog/dialog.component';
7 import {NgbModal} from '@ng-bootstrap/ng-bootstrap';
8 import {StringComponent} from '@eg/share/string/string.component';
12 * Dialog for marking items missing.
16 selector: 'eg-mark-missing-dialog',
17 templateUrl: 'mark-missing-dialog.component.html'
20 export class MarkMissingDialogComponent
21 extends DialogComponent implements OnInit {
23 @Input() copyIds: number[];
28 @ViewChild('successMsg')
29 private successMsg: StringComponent;
31 @ViewChild('errorMsg')
32 private errorMsg: StringComponent;
35 private modal: NgbModal, // required for passing to parent
36 private toast: ToastService,
37 private net: NetService,
38 private evt: EventService,
39 private auth: AuthService) {
40 super(modal); // required for subclassing
45 async markOneItemMissing(ids: number[]): Promise<any> {
46 if (ids.length === 0) {
47 return Promise.resolve();
52 return this.net.request(
54 'open-ils.circ.mark_item_missing',
56 ).toPromise().then(async(result) => {
57 if (Number(result) === 1) {
59 this.toast.success(await this.successMsg.current());
62 console.error('Mark missing failed ', this.evt.parse(result));
63 this.toast.warning(await this.errorMsg.current());
65 return this.markOneItemMissing(ids);
69 async markItemsMissing(): Promise<any> {
70 this.numSucceeded = 0;
72 const ids = [].concat(this.copyIds);
73 await this.markOneItemMissing(ids);
74 this.close(this.numSucceeded > 0);