-import {Component, Input, Output, OnInit, EventEmitter} from '@angular/core';
+import {Component, Input, Output, OnInit, EventEmitter, ViewChild} from '@angular/core';
import {IdlService} from '@eg/core/idl.service';
import {EventService} from '@eg/core/event.service';
import {NetService} from '@eg/core/net.service';
import {OrgService} from '@eg/core/org.service';
import {PcrudService} from '@eg/core/pcrud.service';
import {MarcRecord} from './marcrecord';
+import {ComboboxEntry, ComboboxComponent
+ } from '@eg/share/combobox/combobox.component';
/**
* MARC Record editor main interface.
record: MarcRecord;
editorTab: 'rich' | 'flat';
+ sources: ComboboxEntry[];
@Input() set recordId(id: number) {
if (!id) { return; }
// the record is successfully saved.
@Output() recordSaved: EventEmitter<string>;
+ @ViewChild('sourceSelector') sourceSelector: ComboboxComponent;
+
constructor(
private evt: EventService,
private idl: IdlService,
private org: OrgService,
private pcrud: PcrudService
) {
+ this.sources = [];
this.recordSaved = new EventEmitter<string>();
}
-
ngOnInit() {
// Default to flat for now since it's all that's supported.
this.editorTab = 'flat';
+
+ this.pcrud.retrieveAll('cbs').subscribe(
+ src => this.sources.push({id: +src.id(), label: src.source()}),
+ _ => {},
+ () => {
+ this.sources = this.sources.sort((a, b) =>
+ a.label.toLowerCase() < b.label.toLowerCase() ? -1 : 1
+ );
+ }
+ );
}
saveRecord(): Promise<any> {
return Promise.resolve();
}
+ const source = this.sourceSelector.selected ?
+ this.sourceSelector.selected.label : null; // 'label' not a typo
+
if (this.record.id) { // Editing an existing record
const method = 'open-ils.cat.biblio.record.marc.replace';
- return this.net.request(
- 'open-ils.cat', method,
- this.auth.token(), this.record.id,
- xml, null /* TODO: record source */
+ return this.net.request('open-ils.cat', method,
+ this.auth.token(), this.record.id, xml, source
).toPromise().then(response => {
const evt = this.evt.parse(response);
.toPromise().then(bib => {
this.record = new MarcRecord(bib.marc());
this.record.id = id;
+ if (bib.source()) {
+ this.sourceSelector.applyEntryId(+bib.source());
+ }
});
}