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-po-notes'
13 export class PoNotesComponent implements OnInit, AfterViewInit {
15 @Input() po: IdlObject;
19 @Output() closeRequested: EventEmitter<void> = new EventEmitter<void>();
22 private idl: IdlService,
23 private org: OrgService,
24 private auth: AuthService,
25 private net: NetService
32 const node = document.getElementById('note-text-input');
33 if (node) { node.focus(); }
36 orgSn(id: number): string {
37 return this.org.get(id).shortname();
41 this.closeRequested.emit();
45 const note = this.idl.create('acqpon');
47 note.purchase_order(this.po.id());
48 note.value(this.noteText || '');
49 note.vendor_public(this.vendorPublic ? 't' : 'f');
51 this.modifyNotes(note).subscribe(resp => {
53 this.po.notes().unshift(resp.note);
58 deleteNote(note: IdlObject) {
60 this.modifyNotes(note).toPromise().then(_ => {
62 this.po.notes().filter(n => n.id() !== note.id())
67 modifyNotes(notes: IdlObject | IdlObject[]): Observable<any> {
68 notes = [].concat(notes);
70 return this.net.request(
72 'open-ils.acq.po_note.cud.batch',
73 this.auth.token(), notes);