<div class="row border rounded border-dark pt-2 pb-2 bg-faint">
<div class="col-lg-1 font-weight-bold" i18n>Templates:</div>
<div class="col-lg-4">
- <eg-combobox domId="template-select" #copyTemplateCbox></eg-combobox>
+ <eg-combobox #copyTemplateCbox domId="template-select"
+ [allowFreeText]="true" [entries]="volcopy.templateNames"
+ [(ngModel)]="currentTemplate">
+ </eg-combobox>
</div>
<div class="col-lg-7 d-flex">
<button class="btn btn-outline-dark mr-2" (click)="applyTemplate()" i18n>Apply</button>
<button class="btn btn-outline-dark mr-2" (click)="saveTemplate()" i18n>Save</button>
<button class="btn btn-outline-dark mr-2" (click)="importTemplate()" i18n>Import</button>
- <button class="btn btn-outline-dark mr-2" (click)="exportTemplate()" i18n>Export</button>
+
+ <button class="btn btn-outline-dark mr-2" (click)="importTemplate()" i18n>Import</button>
+
+ <a (click)="exportTemplate($event)"
+ download="export_copy_template.json" [href]="exportTemplateUrl()">
+ <button class="btn btn-outline-dark mr-2" i18n>Export</button>
+ </a>
+
<div class="flex-1"> </div>
<button class="btn btn-outline-dark mr-2"
(click)="copyTemplateCbox.selectedId = null" i18n>Clear</button>
import {Component, Input, OnInit, AfterViewInit, ViewChild,
QueryList, ViewChildren} from '@angular/core';
import {Router, ActivatedRoute, ParamMap} from '@angular/router';
+import {SafeUrl} from '@angular/platform-browser';
import {tap} from 'rxjs/operators';
import {IdlObject, IdlService} from '@eg/core/idl.service';
import {EventService} from '@eg/core/event.service';
} from '@eg/staff/share/holdings/copy-alerts-dialog.component';
import {ComboboxComponent, ComboboxEntry} from '@eg/share/combobox/combobox.component';
import {BatchItemAttrComponent} from '@eg/staff/share/holdings/batch-item-attr.component';
+import {FileExportService} from '@eg/share/util/file-export.service';
@Component({
selector: 'eg-copy-attrs',
private holdings: HoldingsService,
private format: FormatService,
private store: StoreService,
+ private fileExport: FileExportService,
public volcopy: VolCopyService
) { }
ngAfterViewInit() {
const tmpl = this.store.getLocalItem('cat.copy.last_template');
- if (tmpl) { this.copyTemplateCbox.selectedId = tmpl; }
+ if (tmpl) {
+ // avoid Express Changed warning w/ timeout
+ setTimeout(() => this.copyTemplateCbox.selectedId = tmpl);
+ }
this.loanDurationLabelMap[1] = this.loanDurationShort.text;
this.loanDurationLabelMap[2] = this.loanDurationNormal.text;
// TODO: handle circ_lib, owning_lib changes specially
- console.debug('APPLYING', field, value);
-
this.context.copyList().forEach(copy => {
if (copy[field] && copy[field]() !== value) {
copy[field](value);
this.store.setLocalItem('cat.copy.last_template', entry.id);
+ // TODO: handle owning_lib and statcats differently.
+
const template = this.volcopy.templates[entry.id];
Object.keys(template).forEach(field => {
if (value === null || value === undefined) { return; }
this.applyCopyValue(field, value);
+
+ // Indicate in the form these values have changed
+ this.batchAttrs
+ .filter(ba => ba.name === field)
+ .forEach(attr => attr.hasChanged = true);
});
}
saveTemplate() {
+ const entry: ComboboxEntry = this.copyTemplateCbox.selected;
+ if (!entry) { return; }
+
+ let name;
+ let template;
+
+ if (entry.freetext) {
+ name = entry.label;
+ template = {};
+ } else {
+ name = entry.id;
+ template = this.volcopy.templates[name];
+ }
+
+ // Changes will have applied to all items.
+ const copy = this.context.copyList()[0];
+
this.batchAttrs.forEach(comp => {
- console.log(comp.editInputDomId);
+ if (comp.hasChanged) {
+ const value = copy[comp.name]();
+ if (value === null) {
+ delete template[comp.name];
+ } else {
+ template[comp.name] = value;
+ }
+ }
});
+
+ console.debug('Saving template', template);
+
+ this.volcopy.templates[name] = template;
+ this.volcopy.saveTemplates();
+ }
+
+ exportTemplate($event) {
+ if (this.fileExport.inProgress()) { return; }
+
+ const entry: ComboboxEntry = this.copyTemplateCbox.selected;
+ if (!entry) { return; }
+
+ const template = this.volcopy.templates[entry.id];
+
+ this.fileExport.exportFile(
+ $event, JSON.stringify(template), 'text/json');
+ }
+
+ // Returns null when no export is in progress.
+ exportTemplateUrl(): SafeUrl {
+ return this.fileExport.safeUrl;
}
displayAttr(field: string): boolean {