1 import {Component, OnInit, ViewChild} from '@angular/core';
2 import {BasketService} from '@eg/share/catalog/basket.service';
3 import {Subscription} from 'rxjs';
4 import {Router} from '@angular/router';
5 import {NetService} from '@eg/core/net.service';
6 import {AuthService} from '@eg/core/auth.service';
7 import {PrintService} from '@eg/share/print/print.service';
8 import {RecordBucketDialogComponent
9 } from '@eg/staff/share/buckets/record-bucket-dialog.component';
12 selector: 'eg-catalog-basket-actions',
13 templateUrl: 'basket-actions.component.html'
15 export class BasketActionsComponent implements OnInit {
19 @ViewChild('addBasketToBucketDialog')
20 addToBucketDialog: RecordBucketDialogComponent;
23 private router: Router,
24 private net: NetService,
25 private auth: AuthService,
26 private printer: PrintService,
27 private basket: BasketService
29 this.basketAction = '';
35 basketCount(): number {
36 return this.basket.recordCount();
39 // TODO: confirmation dialogs?
42 console.debug('Performing basket action', this.basketAction);
44 switch (this.basketAction) {
46 // This does not propagate search params -- unclear if needed.
47 this.router.navigate(['/staff/catalog/search'],
48 {queryParams: {showBasket: true}});
52 this.basket.removeAllRecordIds();
56 this.basket.getRecordIds().then(ids => {
57 this.router.navigate(['/staff/catalog/hold/T'],
58 {queryParams: {target: ids}});
63 this.basket.getRecordIds().then(ids => {
66 'open-ils.search.biblio.record.print', ids
70 const html = at_event.template_output().data();
73 printContext: 'default'
81 this.basket.getRecordIds().then(ids => {
84 'open-ils.search.biblio.record.email',
85 this.auth.token(), ids
86 ).toPromise(); // fire-and-forget
91 this.basket.getRecordIds().then(ids => {
92 this.addToBucketDialog.recordId = ids;
93 this.addToBucketDialog.open({size: 'lg'});
99 // Resetting basketAction inside its onchange handler
100 // prevents the new value from propagating to Angular
101 // Reset after the current thread.
102 setTimeout(() => this.basketAction = ''); // reset