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