context: VolCopyContext;
loading = true;
sessionExpired = false;
+ printLabels = false;
tab = 'holdings'; // holdings | attrs | config
target: string; // item | callnumber | record | session
}
}
- load(copyIds?: number[]) {
+ load(copyIds?: number[]): Promise<any> {
this.sessionExpired = false;
this.loading = true;
this.context.reset();
- this.volcopy.load()
+ return this.volcopy.load()
.then(_ => this.fetchHoldings(copyIds))
.then(_ => this.volcopy.applyVolLabels(
this.context.volNodes().map(n => n.target)))
.then(_ => this.context.sortHoldings())
.then(_ => this.context.setRecordId())
+ .then(_ => this.printLabels =
+ this.volcopy.defaults.values.print_labels === true)
.then(_ => this.loading = false);
}
}
- save() {
+ save(close?: boolean): Promise<any> {
this.loading = true;
// Volume update API wants volumes fleshed with copies, instead
});
});
+ let promise: Promise<number[]> = Promise.resolve([]);
+
if (volumes.length > 0) {
- this.saveApi(volumes);
- } else {
- this.loading = false;
+ promise = this.saveApi(volumes, false, close);
}
+
+ return promise.then(copyIds => {
+
+ // In addition to the copies edited in this update call,
+ // reload any other copies that were previously loaded.
+ const ids: any = {}; // dedupe
+ this.context.copyList()
+ .map(c => c.id())
+ .filter(id => id > 0) // scrub the new copy IDs
+ .concat(copyIds)
+ .forEach(id => ids[id] = true);
+
+ copyIds = Object.keys(ids).map(id => Number(id));
+
+ if (close) {
+ return this.openPrintLabels(copyIds)
+ .then(_ => setTimeout(() => window.close()));
+ }
+
+ return this.load(Object.keys(ids).map(id => Number(id)));
+
+ }).then(_ => this.loading = false);
}
- saveApi(volumes: IdlObject[], override?: boolean) {
+ saveApi(volumes: IdlObject[], override?:
+ boolean, close?: boolean): Promise<number[]> {
let method = 'open-ils.cat.asset.volume.fleshed.batch.update';
if (override) { method += '.override'; }
- this.net.request('open-ils.cat',
+ return this.net.request('open-ils.cat',
method, this.auth.token(), volumes, true,
{ auto_merge_vols: true,
create_parts: true,
const evt = this.evt.parse(copyIds);
- // TODO: handle overrides?
if (evt) {
+ // TODO: handle overrides?
+ // return this.saveApi(volumes, true, close);
this.loading = false;
alert(evt);
- return;
+ return Promise.reject();
}
- // In addition to the copies edited in this update call,
- // reload any other copies that were previously loaded.
+ return copyIds;
+ });
+ }
- const ids: any = {}; // dedupe
- this.context.copyList()
- .map(c => c.id())
- .concat(copyIds)
- .forEach(id => ids[id] = true);
+ savePrintLabels() {
+ this.volcopy.defaults.values.print_labels = this.printLabels === true;
+ this.volcopy.saveDefaults();
+ }
- return this.load(Object.keys(ids).map(id => Number(id)));
+ openPrintLabels(copyIds?: number[]): Promise<any> {
+ if (!this.printLabels) { return Promise.resolve(); }
+
+ if (!copyIds || copyIds.length === 0) {
+ copyIds = this.context.copyList()
+ .map(c => c.id()).filter(id => id > 0);
+ }
+
+ return this.net.request(
+ 'open-ils.actor',
+ 'open-ils.actor.anon_cache.set_value',
+ null, 'print-labels-these-copies', {copies : copyIds}
+
+ ).toPromise().then(key => {
+
+ const url = '/eg/staff/cat/printlabels/' + key;
+ setTimeout(() => window.open(url, '_blank'));
});
}
}