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';
10 templateUrl: 'notes.component.html',
11 selector: 'eg-lineitem-notes'
13 export class LineitemNotesComponent implements OnInit, AfterViewInit {
15 @Input() lineitem: IdlObject;
18 alertEntry: ComboboxEntry;
20 @Output() closeRequested: EventEmitter<void> = new EventEmitter<void>();
23 private idl: IdlService,
24 private org: OrgService,
25 private auth: AuthService,
26 private net: NetService
33 const node = document.getElementById('note-text-input');
34 if (node) { node.focus(); }
37 orgSn(id: number): string {
38 return this.org.get(id).shortname();
42 this.closeRequested.emit();
45 newNote(isAlert?: boolean) {
46 const note = this.idl.create('acqlin');
48 note.lineitem(this.lineitem.id());
49 note.value(this.noteText || '');
51 note.alert_text(this.alertEntry.id);
53 note.vendor_public(this.vendorPublic ? 't' : 'f');
56 this.modifyNotes(note).subscribe(resp => {
58 this.lineitem.lineitem_notes().unshift(resp.note);
63 deleteNote(note: IdlObject) {
65 this.modifyNotes(note).toPromise().then(_ => {
66 this.lineitem.lineitem_notes(
67 this.lineitem.lineitem_notes().filter(n => n.id() !== note.id())
72 modifyNotes(notes: IdlObject | IdlObject[]): Observable<any> {
73 notes = [].concat(notes);
75 return this.net.request(
77 'open-ils.acq.lineitem_note.cud.batch',
78 this.auth.token(), notes);