1 import {Component, OnInit, Input, ViewChild, Renderer2} from '@angular/core';
2 import {IdlObject} from '@eg/core/idl.service';
3 import {NetService} from '@eg/core/net.service';
4 import {EventService} from '@eg/core/event.service';
5 import {PcrudService} from '@eg/core/pcrud.service';
6 import {ToastService} from '@eg/share/toast/toast.service';
7 import {AuthService} from '@eg/core/auth.service';
8 import {NgbModal, NgbModalOptions} from '@ng-bootstrap/ng-bootstrap';
9 import {DialogComponent} from '@eg/share/dialog/dialog.component';
10 import {StringComponent} from '@eg/share/string/string.component';
14 * Dialog for marking items missing.
18 selector: 'eg-delete-volcopy-dialog',
19 templateUrl: 'delete-volcopy-dialog.component.html'
22 export class DeleteVolcopyDialogComponent
23 extends DialogComponent implements OnInit {
25 // List of "acn" objects which may contain copies.
26 // Objects of either type marked "isdeleted" will be deleted.
27 @Input() volumes: IdlObject[];
29 // If true, just ask the server to delete all attached copies
30 // for any deleted call numbers.
31 // Note if this is true and a volume is provided that does not contain
32 // of its fleshed copies, the number of copies to delete will not be
33 // reported correctly.
34 @Input() forceDeleteCopies: boolean;
41 @ViewChild('successMsg')
42 private successMsg: StringComponent;
44 @ViewChild('errorMsg')
45 private errorMsg: StringComponent;
48 private modal: NgbModal, // required for passing to parent
49 private toast: ToastService,
50 private net: NetService,
51 private pcrud: PcrudService,
52 private evt: EventService,
53 private renderer: Renderer2,
54 private auth: AuthService) {
55 super(modal); // required for subclassing
60 async open(args: NgbModalOptions): Promise<boolean> {
63 this.numSucceeded = 0;
66 this.volumes.forEach(vol => {
67 if (vol.isdeleted()) {
70 if (Array.isArray(vol.copies())) {
71 vol.copies().forEach(c => {
72 if (c.isdeleted() || this.forceDeleteCopies) {
73 // Marking copies deleted in forceDeleteCopies mode
74 // is not required, but we do it here so we can
75 // report the number of copies to be deleted.
83 if (this.numVols === 0 && this.numCopies === 0) {
84 console.debug('Volcopy delete called with no usable data');
85 return Promise.resolve(false);
88 return super.open(args);
94 force_delete_copies: this.forceDeleteCopies
99 'open-ils.cat.asset.volume.fleshed.batch.update.override',
100 this.auth.token(), this.volumes, 1, flags
103 const evt = this.evt.parse(result);
106 this.errorMsg.current().then(msg => this.toast.warning(msg));
110 this.close(this.numSucceeded > 0);
115 this.errorMsg.current().then(msg => this.toast.warning(msg));