]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/src/eg2/src/app/staff/share/holdings/holdings.service.ts
LP1818288 Ang staff catalog record detail holds tab/actions
[working/Evergreen.git] / Open-ILS / src / eg2 / src / app / staff / share / holdings / holdings.service.ts
1 /**
2  * Common code for mananging holdings
3  */
4 import {Injectable, EventEmitter} from '@angular/core';
5 import {NetService} from '@eg/core/net.service';
6 import {AnonCacheService} from '@eg/share/util/anon-cache.service';
7 import {AuthService} from '@eg/core/auth.service';
8 import {EventService} from '@eg/core/event.service';
9
10 interface NewVolumeData {
11     owner: number;
12     label?: string;
13 }
14
15 @Injectable()
16 export class HoldingsService {
17
18     constructor(
19         private net: NetService,
20         private auth: AuthService,
21         private evt: EventService,
22         private anonCache: AnonCacheService
23     ) {}
24
25     // Open the holdings editor UI in a new browser window/tab.
26     spawnAddHoldingsUi(
27         recordId: number,                   // Bib record ID
28         addToVols: number[] = [],           // Add copies to existing volumes
29         volumeData: NewVolumeData[] = []) { // Creating new volumes
30
31         const raw: any[] = [];
32
33         if (addToVols) {
34             addToVols.forEach(volId => raw.push({callnumber: volId}));
35         } else if (volumeData) {
36             volumeData.forEach(data => raw.push(data));
37         }
38
39         if (raw.length === 0) { raw.push({}); }
40
41         this.anonCache.setItem(null, 'edit-these-copies', {
42             record_id: recordId,
43             raw: raw,
44             hide_vols : false,
45             hide_copies : false
46         }).then(key => {
47             if (!key) {
48                 console.error('Could not create holds cache key!');
49                 return;
50             }
51             setTimeout(() => {
52                 const url = `/eg/staff/cat/volcopy/${key}`;
53                 window.open(url, '_blank');
54             });
55         });
56     }
57 }
58