1 import {Component, Input, AfterViewInit, ViewChild} from '@angular/core';
2 import {Router, ActivatedRoute, ParamMap} from '@angular/router';
3 import {IdlObject} from '@eg/core/idl.service';
4 import {PcrudService} from '@eg/core/pcrud.service';
5 import {AuthService} from '@eg/core/auth.service';
6 import {NetService} from '@eg/core/net.service';
7 import {PrintService} from '@eg/share/print/print.service';
8 import {HoldingsService} from '@eg/staff/share/holdings/holdings.service';
9 import {EventService} from '@eg/core/event.service';
10 import {PatronPenaltyDialogComponent} from '@eg/staff/share/patron/penalty-dialog.component';
13 templateUrl: 'missing-pieces.component.html'
15 export class MarkItemMissingPiecesComponent implements AfterViewInit {
24 itemProcessed = false;
26 @ViewChild('penaltyDialog', {static: false})
27 penaltyDialog: PatronPenaltyDialogComponent;
30 private route: ActivatedRoute,
31 private net: NetService,
32 private printer: PrintService,
33 private pcrud: PcrudService,
34 private auth: AuthService,
35 private evt: EventService,
36 private holdings: HoldingsService
38 this.itemId = +this.route.snapshot.paramMap.get('id');
42 if (this.itemId) { this.getItemById(); }
46 getItemByBarcode(): Promise<any> {
50 if (!this.itemBarcode) { return Promise.resolve(); }
52 // Submitting a new barcode resets the form.
53 const bc = this.itemBarcode;
55 this.itemBarcode = bc;
57 return this.holdings.getItemIdFromBarcode(this.itemBarcode)
59 this.noSuchItem = (id === null);
61 return this.getItemById();
67 const node: HTMLInputElement =
68 document.getElementById('item-barcode-input') as HTMLInputElement;
69 if (node) { node.select(); }
73 getItemById(): Promise<any> {
74 this.circNotFound = false;
78 return Promise.resolve();
86 bre: ['flat_display_entries']
90 return this.pcrud.retrieve('acp', this.itemId, flesh)
91 .toPromise().then(item => {
93 this.itemId = item.id();
94 this.itemBarcode = item.barcode();
99 display(field: string): string {
100 if (!this.item) { return ''; }
102 const entry = this.item.call_number().record()
103 .flat_display_entries()
104 .filter(fde => fde.name() === field)[0];
106 return entry ? entry.value() : '';
113 this.itemBarcode = null;
114 this.circNotFound = false;
115 this.itemProcessed = false;
119 this.circNotFound = false;
120 this.itemProcessed = false;
122 if (!this.item) { return; }
124 this.processing = true;
128 'open-ils.circ.mark_item_missing_pieces',
129 this.auth.token(), this.itemId
130 ).subscribe(resp => {
131 const evt = this.evt.parse(resp); // always returns event
132 this.processing = false;
133 this.itemProcessed = true;
135 if (evt.textcode === 'ACTION_CIRCULATION_NOT_FOUND') {
136 this.circNotFound = true;
141 const payload = evt.payload;
143 if (payload.letter) {
144 this.letter = payload.letter.template_output().data();
149 printContext: 'default',
150 contentType: 'text/html',
151 text: payload.slip.template_output().data()
156 this.penaltyDialog.patronId = payload.circ.usr();
157 this.penaltyDialog.open().subscribe(
158 penId => console.debug('Applied penalty ', penId),
160 () => this.selectInput()
170 printContext: 'default',
171 contentType: 'text/plain',
176 letterRowCount(): number {
177 return this.letter ? this.letter.split(/\n/).length + 2 : 20;