]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/src/eg2/src/app/staff/acq/lineitem/detail.component.ts
LP1929741 ACQ Selection List & PO Angluar Port
[Evergreen.git] / Open-ILS / src / eg2 / src / app / staff / acq / lineitem / detail.component.ts
1 import {Component, OnInit, AfterViewInit, Input, Output, EventEmitter} from '@angular/core';
2 import {Router, ActivatedRoute, ParamMap} from '@angular/router';
3 import {tap} from 'rxjs/operators';
4 import {Pager} from '@eg/share/util/pager';
5 import {IdlObject} from '@eg/core/idl.service';
6 import {NetService} from '@eg/core/net.service';
7 import {AuthService} from '@eg/core/auth.service';
8 import {LineitemService, BatchLineitemStruct} from './lineitem.service';
9 import {ComboboxEntry} from '@eg/share/combobox/combobox.component';
10
11 @Component({
12   templateUrl: 'detail.component.html'
13 })
14 export class LineitemDetailComponent implements OnInit {
15
16     lineitemId: number;
17     lineitem: IdlObject;
18     tab: string;
19
20     constructor(
21         private route: ActivatedRoute,
22         private net: NetService,
23         private auth: AuthService,
24         private liService: LineitemService
25     ) {}
26
27     ngOnInit() {
28
29         this.route.paramMap.subscribe((params: ParamMap) => {
30             const id = +params.get('lineitemId');
31             if (id !== this.lineitemId) {
32                 this.lineitemId = id;
33                 if (id) { this.load(); }
34             }
35         });
36
37         this.liService.getLiAttrDefs();
38     }
39
40     load() {
41         this.lineitem = null;
42         // Avoid pulling from cache since li's do not have marc()
43         // fleshed by default.
44         return this.liService.getFleshedLineitems([this.lineitemId], {
45             toCache: true, // OK to cache with marc()
46             fleshMore: {clear_marc: false}
47         }).pipe(tap(liStruct => this.lineitem = liStruct.lineitem)).toPromise();
48     }
49
50     attrLabel(attr: IdlObject): string {
51         if (!this.liService.liAttrDefs) { return; }
52
53         const def = this.liService.liAttrDefs.filter(
54             d => d.id() === attr.definition())[0];
55
56         return def ? def.description() : '';
57     }
58
59     saveMarcChanges(changes) { // MarcSavedEvent
60         const xml = changes.marcXml;
61         this.lineitem.marc(xml);
62         this.liService.updateLineitems([this.lineitem]).toPromise()
63         .then(_ => this.load());
64     }
65 }
66
67