1 import {Component, OnInit, Input, ViewChild, Renderer2} from '@angular/core';
2 import {Observable, throwError} from 'rxjs';
3 import {IdlObject} from '@eg/core/idl.service';
4 import {NetService} from '@eg/core/net.service';
5 import {EventService} from '@eg/core/event.service';
6 import {PcrudService} from '@eg/core/pcrud.service';
7 import {ToastService} from '@eg/share/toast/toast.service';
8 import {AuthService} from '@eg/core/auth.service';
9 import {NgbModal, NgbModalOptions} from '@ng-bootstrap/ng-bootstrap';
10 import {DialogComponent} from '@eg/share/dialog/dialog.component';
11 import {StringComponent} from '@eg/share/string/string.component';
15 * Dialog that confirms, then deletes items and call numbers
19 selector: 'eg-delete-holding-dialog',
20 templateUrl: 'delete-volcopy-dialog.component.html'
23 export class DeleteHoldingDialogComponent
24 extends DialogComponent implements OnInit {
26 // List of "acn" objects which may contain copies.
27 // Objects of either type marked "isdeleted" will be deleted.
28 @Input() callNums: IdlObject[];
30 // If true, just ask the server to delete all attached copies
31 // for any deleted call numbers.
32 // Note if this is true and a call number is provided that does not
33 // contain its fleshed copies, the number of copies to delete will not be
34 // reported correctly.
35 @Input() forceDeleteCopies: boolean;
42 @ViewChild('successMsg', { static: true })
43 private successMsg: StringComponent;
45 @ViewChild('errorMsg', { static: true })
46 private errorMsg: StringComponent;
49 private modal: NgbModal, // required for passing to parent
50 private toast: ToastService,
51 private net: NetService,
52 private pcrud: PcrudService,
53 private evt: EventService,
54 private renderer: Renderer2,
55 private auth: AuthService) {
56 super(modal); // required for subclassing
61 open(args: NgbModalOptions): Observable<boolean> {
64 this.numSucceeded = 0;
67 this.callNums.forEach(callNum => {
68 if (callNum.isdeleted()) {
71 if (Array.isArray(callNum.copies())) {
72 callNum.copies().forEach(c => {
73 if (c.isdeleted() || this.forceDeleteCopies) {
74 // Marking copies deleted in forceDeleteCopies mode
75 // is not required, but we do it here so we can
76 // report the number of copies to be deleted.
84 if (this.numCallNums === 0 && this.numCopies === 0) {
85 console.debug('Holdings delete called with no usable data');
86 return throwError(false);
89 return super.open(args);
95 force_delete_copies: this.forceDeleteCopies
100 'open-ils.cat.asset.volume.fleshed.batch.update.override',
101 this.auth.token(), this.callNums, 1, flags
104 const evt = this.evt.parse(result);
107 this.errorMsg.current().then(msg => this.toast.warning(msg));
111 this.close(this.numSucceeded > 0);
116 this.errorMsg.current().then(msg => this.toast.warning(msg));