]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/src/eg2/src/app/staff/acq/po/notes.component.ts
LP1929741 ACQ Selection List & PO Angluar Port
[Evergreen.git] / Open-ILS / src / eg2 / src / app / staff / acq / po / notes.component.ts
1 import {Component, OnInit, AfterViewInit, Input, Output, EventEmitter} from '@angular/core';
2 import {Observable} from 'rxjs';
3 import {IdlObject, IdlService} from '@eg/core/idl.service';
4 import {NetService} from '@eg/core/net.service';
5 import {OrgService} from '@eg/core/org.service';
6 import {AuthService} from '@eg/core/auth.service';
7 import {ComboboxEntry} from '@eg/share/combobox/combobox.component';
8
9 @Component({
10   templateUrl: 'notes.component.html',
11   selector: 'eg-po-notes'
12 })
13 export class PoNotesComponent implements OnInit, AfterViewInit {
14
15     @Input() po: IdlObject;
16     noteText: string;
17     vendorPublic = false;
18
19     @Output() closeRequested: EventEmitter<void> = new EventEmitter<void>();
20
21     constructor(
22         private idl: IdlService,
23         private org: OrgService,
24         private auth: AuthService,
25         private net: NetService
26     ) {}
27
28     ngOnInit() {
29     }
30
31     ngAfterViewInit() {
32         const node = document.getElementById('note-text-input');
33         if (node) { node.focus(); }
34     }
35
36     orgSn(id: number): string {
37         return this.org.get(id).shortname();
38     }
39
40     close() {
41         this.closeRequested.emit();
42     }
43
44     newNote() {
45         const note = this.idl.create('acqpon');
46         note.isnew(true);
47         note.purchase_order(this.po.id());
48         note.value(this.noteText || '');
49         note.vendor_public(this.vendorPublic ? 't' : 'f');
50
51         this.modifyNotes(note).subscribe(resp => {
52             if (resp.note) {
53                 this.po.notes().unshift(resp.note);
54             }
55         });
56     }
57
58     deleteNote(note: IdlObject) {
59         note.isdeleted(true);
60         this.modifyNotes(note).toPromise().then(_ => {
61             this.po.notes(
62                 this.po.notes().filter(n => n.id() !== note.id())
63             );
64         });
65     }
66
67     modifyNotes(notes: IdlObject | IdlObject[]): Observable<any> {
68         notes = [].concat(notes);
69
70         return this.net.request(
71             'open-ils.acq',
72             'open-ils.acq.po_note.cud.batch',
73             this.auth.token(), notes);
74     }
75 }
76