import {PrecatCheckoutDialogComponent} from './precat-dialog.component';
import {AudioService} from '@eg/share/util/audio.service';
import {CopyAlertsDialogComponent} from '@eg/staff/share/holdings/copy-alerts-dialog.component';
+import {BarcodeSelectComponent} from '@eg/staff/share/barcodes/barcode-select.component';
const SESSION_DUE_DATE = 'eg.circ.checkout.is_until_logout';
private precatDialog: PrecatCheckoutDialogComponent;
@ViewChild('copyAlertsDialog')
private copyAlertsDialog: CopyAlertsDialogComponent;
+ @ViewChild('barcodeSelect')
+ private barcodeSelect: BarcodeSelectComponent;
constructor(
private store: StoreService,
} else if (this.checkoutBarcode) {
- params.copy_barcode = this.checkoutBarcode;
if (this.dueDateOptions > 0) { params.due_date = this.dueDate; }
- return Promise.resolve(params);
+
+ return this.barcodeSelect.getBarcode('asset', this.checkoutBarcode)
+ .then(barcode => {
+ if (barcode) {
+ params.copy_barcode = barcode;
+ return params;
+ } else {
+ return null;
+ }
+ });
}
return Promise.resolve(null);
--- /dev/null
+
+<ng-template #dialogContent>
+ <div class="modal-header bg-info">
+ <h4 class="modal-title">
+ <span i18n>Select Barcode</span>
+ </h4>
+ <button type="button" class="close"
+ i18n-aria-label aria-label="Close" (click)="close()">
+ <span aria-hidden="true">×</span>
+ </button>
+ </div>
+ <div class="modal-body">
+ <ng-container *ngFor="let barcode of barcodes">
+ <div class="form-check">
+ <input class="form-check-input" type="checkbox" value=""
+ id="barcode-check-{{barcode}}" [(ngModel)]="inputs[barcode]"
+ (ngModelChange)="selectionChanged()">
+ <label class="form-check-label" for="barcode-check-{{barcode}}">
+ {{barcode}}
+ </label>
+ </div>
+ </ng-container>
+ </div>
+ <div class="modal-footer">
+ <button type="button" class="btn btn-success" [disabled]="!selectedBarcode"
+ (click)="close(selectedBarcode)" i18n>Apply</button>
+ <button type="button" class="btn btn-warning"
+ (click)="close()" i18n>Cancel</button>
+ </div>
+</ng-template>
+
--- /dev/null
+import {Component, Input, Output, OnInit, ViewChild} from '@angular/core';
+import {Observable} from 'rxjs';
+import {map, mergeMap} from 'rxjs/operators';
+import {IdlObject} from '@eg/core/idl.service';
+import {NetService} from '@eg/core/net.service';
+import {OrgService} from '@eg/core/org.service';
+import {AuthService} from '@eg/core/auth.service';
+import {PcrudService} from '@eg/core/pcrud.service';
+import {EventService, EgEvent} from '@eg/core/event.service';
+import {NgbModal, NgbModalOptions} from '@ng-bootstrap/ng-bootstrap';
+import {DialogComponent} from '@eg/share/dialog/dialog.component';
+
+/* Suppor barcode completion for asset/actor/serial/booking data */
+
+@Component({
+ selector: 'eg-barcode-select',
+ templateUrl: './barcode-select.component.html',
+})
+
+export class BarcodeSelectComponent
+ extends DialogComponent implements OnInit {
+
+ selectedBarcode: string;
+ barcodes: string[];
+ inputs: {[barcode: string]: boolean};
+
+ constructor(
+ private modal: NgbModal,
+ private evt: EventService,
+ private org: OrgService,
+ private net: NetService,
+ private pcrud: PcrudService,
+ private auth: AuthService
+ ) { super(modal); }
+
+ ngOnInit() {
+ }
+
+ selectionChanged() {
+ this.selectedBarcode = Object.keys(this.inputs)
+ .filter(barcode => this.inputs[barcode] === true)[0];
+ }
+
+ // Returns promise of barcode
+ // When multiple barcodes match, the user is asked to select one.
+ // Returns promise of null if no match is found or the user cancels
+ // the selection process.
+ getBarcode(class_: 'asset' | 'actor', barcode: string): Promise<string> {
+ this.barcodes = [];
+ this.inputs = {};
+
+ let promise = this.net.request(
+ 'open-ils.actor',
+ 'open-ils.actor.get_barcodes',
+ this.auth.token(), this.auth.user().ws_ou(),
+ class_, barcode.trim()
+ ).toPromise();
+
+ promise = promise.then(results => {
+
+ if (!results) { return null; }
+
+ results.forEach(result => {
+ if (!this.evt.parse(result)) {
+ this.barcodes.push(result.barcode);
+ }
+ });
+
+ if (this.barcodes.length === 0) {
+ return null;
+ } else if (this.barcodes.length === 1) {
+ return this.barcodes[0];
+ } else {
+ return this.open().toPromise();
+ }
+ });
+
+ return promise;
+ }
+}
+