]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/src/eg2/src/app/staff/acq/picklist/summary.component.ts
LP1929741 ACQ Selection List & PO Angluar Port
[Evergreen.git] / Open-ILS / src / eg2 / src / app / staff / acq / picklist / summary.component.ts
1 import {Component, Input, OnInit, AfterViewInit, ViewChild} from '@angular/core';
2 import {of, Observable} from 'rxjs';
3 import {tap, take, map} from 'rxjs/operators';
4 import {IdlObject, IdlService} from '@eg/core/idl.service';
5 import {NetService} from '@eg/core/net.service';
6 import {FormatService} from '@eg/core/format.service';
7 import {AuthService} from '@eg/core/auth.service';
8 import {OrgService} from '@eg/core/org.service';
9 import {PcrudService} from '@eg/core/pcrud.service';
10 import {StoreService} from '@eg/core/store.service';
11 import {ServerStoreService} from '@eg/core/server-store.service';
12 import {ComboboxEntry, ComboboxComponent} from '@eg/share/combobox/combobox.component';
13 import {ProgressDialogComponent} from '@eg/share/dialog/progress.component';
14 import {EventService} from '@eg/core/event.service';
15 import {HoldingsService} from '@eg/staff/share/holdings/holdings.service';
16 import {ConfirmDialogComponent} from '@eg/share/dialog/confirm.component';
17 import {BroadcastService} from '@eg/share/util/broadcast.service';
18
19
20 @Component({
21   templateUrl: 'summary.component.html',
22   selector: 'eg-acq-picklist-summary'
23 })
24 export class PicklistSummaryComponent implements OnInit, AfterViewInit {
25
26     private _picklistId: number;
27     @Input() set picklistId(id: number) {
28         if (id !== this._picklistId) {
29             this._picklistId = id;
30             if (this.initDone) {
31                 this.load();
32             }
33         }
34     }
35
36     get picklistId(): number {
37         return this._picklistId;
38     }
39
40     picklist: IdlObject;
41     newPlName: string;
42     editPlName = false;
43     initDone = false;
44
45     constructor(
46         private idl: IdlService,
47         private net: NetService,
48         private format: FormatService,
49         private evt: EventService,
50         private org: OrgService,
51         private pcrud: PcrudService,
52         private auth: AuthService,
53         private store: StoreService,
54         private serverStore: ServerStoreService,
55         private broadcaster: BroadcastService,
56         private holdingSvc: HoldingsService
57     ) {}
58
59     ngOnInit() {
60         this.load().then(_ => this.initDone = true);
61     }
62
63     ngAfterViewInit() {
64     }
65
66     load(): Promise<any> {
67         this.picklist = null;
68         if (!this.picklistId) { return Promise.resolve(); }
69
70         return this.net.request(
71             'open-ils.acq',
72             'open-ils.acq.picklist.retrieve.authoritative',
73             this.auth.token(), this.picklistId,
74             {flesh_lineitem_count: true, flesh_owner: true}
75         ).toPromise().then(list => {
76
77             const evt = this.evt.parse(list);
78             if (evt) {
79                 console.error('API returned ', evt);
80                 return Promise.reject();
81             }
82
83             this.picklist = list;
84         });
85     }
86
87     toggleNameEdit() {
88         this.editPlName = !this.editPlName;
89
90         if (this.editPlName) {
91             this.newPlName = this.picklist.name();
92             setTimeout(() => {
93                 const node =
94                     document.getElementById('pl-name-input') as HTMLInputElement;
95                 if (node) { node.select(); }
96             });
97
98         } else if (this.newPlName && this.newPlName !== this.picklist.name()) {
99
100             const prevName = this.picklist.name();
101             this.picklist.name(this.newPlName);
102             this.newPlName = null;
103
104             this.net.request(
105                 'open-ils.acq',
106                 'open-ils.acq.picklist.update',
107                 this.auth.token(), this.picklist
108             ).subscribe(resp => {
109                 const evt = this.evt.parse(resp);
110                 if (evt) {
111                     alert(evt);
112                     this.picklist.name(prevName);
113                 }
114             });
115         }
116     }
117 }