} from '@eg/share/combobox/combobox.component';
import {ConfirmDialogComponent} from '@eg/share/dialog/confirm.component';
+interface MarcSavedEvent {
+ marcXml: string;
+ bibSource?: number;
+}
/**
* MARC Record editor main interface.
if (xml) { this.fromXml(xml); }
}
+ // Tell us which record source to select by default.
+ // Useful for new records and in-place editing from bare XML.
+ @Input() recordSource: number;
+
// If true, saving records to the database is assumed to
// happen externally. IOW, the record editor is just an
// in-place MARC modification interface.
- inPlaceMode: boolean;
+ @Input() inPlaceMode: boolean;
// In inPlaceMode, this is emitted in lieu of saving the record
// in th database. When inPlaceMode is false, this is emitted after
// the record is successfully saved.
- @Output() recordSaved: EventEmitter<string>;
+ @Output() recordSaved: EventEmitter<MarcSavedEvent>;
@ViewChild('sourceSelector', { static: true }) sourceSelector: ComboboxComponent;
@ViewChild('confirmDelete', { static: true }) confirmDelete: ConfirmDialogComponent;
private toast: ToastService
) {
this.sources = [];
- this.recordSaved = new EventEmitter<string>();
+ this.recordSaved = new EventEmitter<MarcSavedEvent>();
}
ngOnInit() {
this.sources = this.sources.sort((a, b) =>
a.label.toLowerCase() < b.label.toLowerCase() ? -1 : 1
);
+
+ if (this.recordSource) {
+ this.sourceSelector.applyEntryId(this.recordSource);
+ }
}
);
}
saveRecord(): Promise<any> {
const xml = this.record.toXml();
+ let sourceName: string = null;
+ let sourceId: number = null;
+
+ if (this.sourceSelector.selected) {
+ sourceName = this.sourceSelector.selected.label;
+ sourceId = this.sourceSelector.selected.id;
+ }
+
if (this.inPlaceMode) {
// Let the caller have the modified XML and move on.
- this.recordSaved.emit(xml);
+ this.recordSaved.emit({marcXml: xml, bibSource: sourceId});
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, source
+ this.auth.token(), this.record.id, xml, sourceName
).toPromise().then(response => {
const evt = this.evt.parse(response);
}
this.successMsg.current().then(msg => this.toast.success(msg));
- this.recordSaved.emit(xml);
+ this.recordSaved.emit({marcXml: xml, bibSource: sourceId});
return response;
});
}
}
return this.fromId(this.record.id)
- .then(_ => this.recordSaved.emit(this.record.toXml()));
+ .then(_ => this.recordSaved.emit(
+ {marcXml: this.record.toXml()}));
});
});
}
if (evt) { console.error(evt); return alert(evt); }
return this.fromId(this.record.id)
- .then(_ => this.recordSaved.emit(this.record.toXml()));
+ .then(_ => this.recordSaved.emit(
+ {marcXml: this.record.toXml()}));
});
});
}