23ed6960cbb13bdb799e3cb1e78592ae1ddbdf4b
[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         volumeTransfer: {
36             key: 'eg.cat.marked_volume_transfer_record',
37             current: null
38         }
39     };
40
41     @Input() set recordId(recId: number) {
42         this.recId = recId;
43         if (this.initDone) {
44             // Fire any record specific actions here
45         }
46     }
47
48     constructor(
49         private router: Router,
50         private store: StoreService,
51         private strings: StringService,
52         private toast: ToastService,
53         private cat: CatalogService,
54         private catUrl: CatalogUrlService,
55         private staffCat: StaffCatalogService,
56         private holdings: HoldingsService
57     ) {}
58
59     ngOnInit() {
60         this.initDone = true;
61
62         Object.keys(this.targets).forEach(name => {
63             const target = this.targets[name];
64             target.current = this.store.getLocalItem(target.key);
65         });
66     }
67
68     mark(name: string) {
69         const target = this.targets[name];
70         target.current = this.recId;
71         this.store.setLocalItem(target.key, this.recId);
72         this.strings.interpolate('catalog.record.toast.' + name)
73             .then(txt => this.toast.success(txt));
74     }
75
76     clearMarks() {
77         Object.keys(this.targets).forEach(name => {
78             const target = this.targets[name];
79             target.current = null;
80             this.store.removeLocalItem(target.key);
81         });
82         this.strings.interpolate('catalog.record.toast.cleared')
83             .then(txt => this.toast.success(txt));
84     }
85
86     // TODO: Support adding copies to existing volumes by getting
87     // selected volumes from the holdings grid.
88     // TODO: Support adding like volumes by getting selected
89     // volumes from the holdings grid.
90     addVolumes() {
91         this.holdings.spawnAddHoldingsUi(this.recId);
92     }
93
94 }
95
96