]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/src/eg2/src/app/staff/catalog/record/actions.component.ts
LP1892077 Staff catalog Holdings grid more columns
[Evergreen.git] / Open-ILS / src / eg2 / src / app / staff / catalog / record / actions.component.ts
1 import {Component, OnInit, Input, Output, EventEmitter} from '@angular/core';
2 import {Router} from '@angular/router';
3 import {StoreService} from '@eg/core/store.service';
4 import {CatalogService} from '@eg/share/catalog/catalog.service';
5 import {CatalogSearchContext} from '@eg/share/catalog/search-context';
6 import {CatalogUrlService} from '@eg/share/catalog/catalog-url.service';
7 import {StaffCatalogService} from '../catalog.service';
8 import {StringService} from '@eg/share/string/string.service';
9 import {ToastService} from '@eg/share/toast/toast.service';
10 import {HoldingsService} from '@eg/staff/share/holdings/holdings.service';
11
12 @Component({
13   selector: 'eg-catalog-record-actions',
14   templateUrl: 'actions.component.html'
15 })
16 export class RecordActionsComponent implements OnInit {
17
18     @Output() addHoldingsRequested: EventEmitter<void>
19         = new EventEmitter<void>();
20
21     recId: number;
22     initDone = false;
23     searchContext: CatalogSearchContext;
24
25     targets = {
26         conjoined: {
27           key: 'eg.cat.marked_conjoined_record',
28           current: null
29         },
30         overlay: {
31             key: 'eg.cat.marked_overlay_record',
32             current: null
33         },
34         holdTransfer: {
35             key: 'eg.circ.hold.title_transfer_target',
36             current: null
37         },
38         holdingTransfer: {
39             key: 'eg.cat.transfer_target_record',
40             current: null,
41             clear: [ // Clear these values on mark.
42               'eg.cat.transfer_target_lib',
43               'eg.cat.transfer_target_vol'
44             ]
45         }
46     };
47
48     @Input() set recordId(recId: number) {
49         this.recId = recId;
50         if (this.initDone) {
51             // Fire any record specific actions here
52         }
53     }
54
55     constructor(
56         private router: Router,
57         private store: StoreService,
58         private strings: StringService,
59         private toast: ToastService,
60         private cat: CatalogService,
61         private catUrl: CatalogUrlService,
62         private staffCat: StaffCatalogService,
63         private holdings: HoldingsService
64     ) {}
65
66     ngOnInit() {
67         this.initDone = true;
68
69         Object.keys(this.targets).forEach(name => {
70             const target = this.targets[name];
71             target.current = this.store.getLocalItem(target.key);
72         });
73     }
74
75     mark(name: string) {
76         const target = this.targets[name];
77         target.current = this.recId;
78         this.store.setLocalItem(target.key, this.recId);
79
80         if (target.clear) {
81             // Some marks require clearing other marks.
82             target.clear.forEach(key => this.store.removeLocalItem(key));
83         }
84
85         this.strings.interpolate('catalog.record.toast.' + name)
86             .then(txt => this.toast.success(txt));
87     }
88
89     clearMarks() {
90         Object.keys(this.targets).forEach(name => {
91             const target = this.targets[name];
92             target.current = null;
93             this.store.removeLocalItem(target.key);
94         });
95         this.strings.interpolate('catalog.record.toast.cleared')
96             .then(txt => this.toast.success(txt));
97     }
98
99     addHoldings() {
100         this.addHoldingsRequested.emit();
101     }
102 }
103
104