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