-import {Component, Input, AfterViewInit, ViewChild, Renderer2} from '@angular/core';
+import {Component, Input, AfterViewInit, ViewChild} from '@angular/core';
import {Router, ActivatedRoute, ParamMap} from '@angular/router';
import {IdlObject} from '@eg/core/idl.service';
import {PcrudService} from '@eg/core/pcrud.service';
circNotFound = false;
processing = false;
noSuchItem = false;
+ itemProcessed = false;
@ViewChild('penaltyDialog', {static: false})
penaltyDialog: PatronPenaltyDialogComponent;
constructor(
private route: ActivatedRoute,
- private renderer: Renderer2,
private net: NetService,
private printer: PrintService,
private pcrud: PcrudService,
ngAfterViewInit() {
if (this.itemId) { this.getItemById(); }
- this.renderer.selectRootElement('#item-barcode-input').focus();
+ this.selectInput();
}
getItemByBarcode(): Promise<any> {
if (!this.itemBarcode) { return Promise.resolve(); }
+ // Submitting a new barcode resets the form.
+ const bc = this.itemBarcode;
+ this.reset();
+ this.itemBarcode = bc;
+
return this.holdings.getItemIdFromBarcode(this.itemBarcode)
.then(id => {
this.noSuchItem = (id === null);
}
selectInput() {
- setTimeout(() =>
- this.renderer.selectRootElement('#item-barcode-input').select());
+ setTimeout(() => {
+ const node: HTMLInputElement =
+ document.getElementById('item-barcode-input') as HTMLInputElement;
+ if (node) { node.select(); }
+ });
}
getItemById(): Promise<any> {
reset() {
this.item = null;
this.itemId = null;
+ this.letter = null;
this.itemBarcode = null;
this.circNotFound = false;
+ this.itemProcessed = false;
}
processItem() {
this.circNotFound = false;
+ this.itemProcessed = false;
if (!this.item) { return; }
).subscribe(resp => {
const evt = this.evt.parse(resp); // always returns event
this.processing = false;
+ this.itemProcessed = true;
if (evt.textcode === 'ACTION_CIRCULATION_NOT_FOUND') {
this.circNotFound = true;
+ this.selectInput();
return;
}
if (payload.circ) {
this.penaltyDialog.patronId = payload.circ.usr();
this.penaltyDialog.open().subscribe(
- penId => console.debug('Applied penalty ', penId));
+ penId => console.debug('Applied penalty ', penId),
+ err => {},
+ () => this.selectInput()
+ );
+ } else {
+ this.selectInput();
}
});
}