]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/src/eg2/src/app/staff/catalog/record/actions.component.ts
LP1868354 Angular catalog item/call number transfer
[Evergreen.git] / Open-ILS / src / eg2 / src / app / staff / catalog / record / actions.component.ts
1 import {Component, OnInit, Input} 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     recId: number;
19     initDone = false;
20     searchContext: CatalogSearchContext;
21
22     targets = {
23         conjoined: {
24           key: 'eg.cat.marked_conjoined_record',
25           current: null
26         },
27         overlay: {
28             key: 'eg.cat.marked_overlay_record',
29             current: null
30         },
31         holdTransfer: {
32             key: 'eg.circ.hold.title_transfer_target',
33             current: null
34         },
35         holdingTransfer: {
36             key: 'eg.cat.transfer_target_record',
37             current: null,
38             clear: [ // Clear these values on mark.
39               'eg.cat.transfer_target_lib',
40               'eg.cat.transfer_target_vol'
41             ]
42         }
43     };
44
45     @Input() set recordId(recId: number) {
46         this.recId = recId;
47         if (this.initDone) {
48             // Fire any record specific actions here
49         }
50     }
51
52     constructor(
53         private router: Router,
54         private store: StoreService,
55         private strings: StringService,
56         private toast: ToastService,
57         private cat: CatalogService,
58         private catUrl: CatalogUrlService,
59         private staffCat: StaffCatalogService,
60         private holdings: HoldingsService
61     ) {}
62
63     ngOnInit() {
64         this.initDone = true;
65
66         Object.keys(this.targets).forEach(name => {
67             const target = this.targets[name];
68             target.current = this.store.getLocalItem(target.key);
69         });
70     }
71
72     mark(name: string) {
73         const target = this.targets[name];
74         target.current = this.recId;
75         this.store.setLocalItem(target.key, this.recId);
76
77         if (target.clear) {
78             // Some marks require clearing other marks.
79             target.clear.forEach(key => this.store.removeLocalItem(key));
80         }
81
82         this.strings.interpolate('catalog.record.toast.' + name)
83             .then(txt => this.toast.success(txt));
84     }
85
86     clearMarks() {
87         Object.keys(this.targets).forEach(name => {
88             const target = this.targets[name];
89             target.current = null;
90             this.store.removeLocalItem(target.key);
91         });
92         this.strings.interpolate('catalog.record.toast.cleared')
93             .then(txt => this.toast.success(txt));
94     }
95
96     // TODO: Support adding copies to existing call numbers by getting
97     // selected call numbers from the holdings grid.
98     // TODO: Support adding like call numbers by getting selected
99     // call numbers from the holdings grid.
100     addHoldings() {
101         this.holdings.spawnAddHoldingsUi(this.recId);
102     }
103
104 }
105
106