[editTemplate]="template"
[labelCounts]="itemAttrCounts(field)"
(valueCleared)="applyCopyValue(field, null)"
- (changesSaved)="applyCopyValue(field)">
+ (changesSaved)="applyCopyValue(field, undefined, $event)">
</eg-batch-item-attr>
</ng-template>
import {CopyTagsDialogComponent
} from '@eg/staff/share/holdings/copy-tags-dialog.component';
import {ComboboxComponent, ComboboxEntry} from '@eg/share/combobox/combobox.component';
-import {BatchItemAttrComponent} from '@eg/staff/share/holdings/batch-item-attr.component';
+import {BatchItemAttrComponent, BatchChangeSelection
+ } from '@eg/staff/share/holdings/batch-item-attr.component';
import {FileExportService} from '@eg/share/util/file-export.service';
@Component({
return value;
}
- applyCopyValue(field: string, value?: any) {
+ copyWantsChange(copy: IdlObject, field: string,
+ changeSelection: BatchChangeSelection): boolean {
+ const disValue = this.getFieldDisplayValue(field, copy);
+ return changeSelection[disValue] === true;
+ }
+
+ applyCopyValue(field: string, value?: any, changeSelection?: BatchChangeSelection) {
if (value === undefined) {
value = this.values[field];
} else {
}
if (field === 'owning_lib') {
- return this.owningLibChanged(value);
+ return this.owningLibChanged(value, changeSelection);
}
this.context.copyList().forEach(copy => {
- if (copy[field] && copy[field]() !== value) {
- copy[field](value);
- copy.ischanged(true);
+ if (!copy[field] || copy[field]() === value) { return; }
+
+ // Change selection indicates which items should be modified
+ // based on the display value for the selected field at
+ // time of editing.
+ if (changeSelection &&
+ !this.copyWantsChange(copy, field, changeSelection)) {
+ return;
}
+
+ copy[field](value);
+ copy.ischanged(true);
});
}
- owningLibChanged(orgId: number) {
+ owningLibChanged(orgId: number, changeSelection?: BatchChangeSelection) {
if (!orgId) { return; }
// Map existing vol IDs to their replacments.
this.context.copyList().forEach(copy => {
+ if (changeSelection &&
+ !this.copyWantsChange(copy, 'owning_lib', changeSelection)) {
+ return;
+ }
+
// Change the copy circ lib to match the new owning lib
// if configured to do so.
if (this.volcopy.defaults.values.circ_lib_mod_with_owning_lib) {
</a>
</ng-container>
</div>
- <div *ngIf="!editing" tabindex="0" class="p-2"
- [ngClass]="{'has-changes': hasChanged}" (keyup.enter)="toggleEditMode()"
- (click)="toggleEditMode()">
+ <div tabindex="0" class="p-2" *ngIf="!editing || multiValue()"
+ [ngClass]="{'has-changes': hasChanged}">
<div class="d-flex"
*ngFor="let count of labelCounts | keyvalue; let idx = index">
- <ng-container *ngIf="!expanded && idx === defaultDisplayCount">
+ <ng-container *ngIf="!expanded && !editing && idx === defaultDisplayCount">
<span class="text-info" i18n>...</span>
</ng-container>
- <ng-container *ngIf="expanded || idx < defaultDisplayCount">
- <div class="flex-1">
+ <ng-container *ngIf="expanded || editing || idx < defaultDisplayCount">
+ <ng-container *ngIf="editing">
+ <div class="ml-4 mr-2">
+ <input type="checkbox" class="form-check-input"
+ [(ngModel)]="editValues[count.key]"/>
+ </div>
+ </ng-container>
+ <div class="flex-1"
+ (click)="toggleEditMode()" (keyup.enter)="toggleEditMode()">
<ng-container *ngIf="displayAs == 'bool'">
<span *ngIf="count.key == 't'" i18n>Yes</span>
<span *ngIf="count.key == 'f'" i18n>No</span>
<ng-template #default>{{count.key}}</ng-template>
</ng-container>
</div>
- <div i18n>{{count.value}} copies</div>
+ <div (click)="toggleEditMode()" (keyup.enter)="toggleEditMode()" i18n>
+ {{count.value}} copies
+ </div>
</ng-container>
</div>
</div>
* updates to batches of items.
*/
+
+// Map of display value to boolean indicating whether a given item
+// should be modified.
+export interface BatchChangeSelection {
+ [value: string]: boolean;
+}
+
@Component({
selector: 'eg-batch-item-attr',
templateUrl: 'batch-item-attr.component.html',
// and expandy.
@Input() defaultDisplayCount = 7;
- @Output() changesSaved: EventEmitter<void> = new EventEmitter<void>();
+ @Output() changesSaved: EventEmitter<BatchChangeSelection> =
+ new EventEmitter<BatchChangeSelection>();
+
@Output() changesCanceled: EventEmitter<void> = new EventEmitter<void>();
@Output() valueCleared: EventEmitter<void> = new EventEmitter<void>();
// Showing all entries?
expanded = false;
+ // Indicate which display values the user wants to modify.
+ editValues: BatchChangeSelection = {};
+
constructor() {}
save() {
this.hasChanged = true;
this.editing = false;
- this.changesSaved.emit();
+ this.changesSaved.emit(this.editValues);
}
cancel() {
return Object.keys(this.labelCounts).length > this.defaultDisplayCount;
}
+ multiValue(): boolean {
+ return Object.keys(this.labelCounts).length > 1;
+ }
+
toggleEditMode() {
if (this.readOnly) { return; }
// Avoid using selectRootElement to focus.
// https://stackoverflow.com/a/36059595
- if (this.editing && this.editInputDomId) {
- setTimeout(() => {
- const node = document.getElementById(this.editInputDomId);
- if (node) { node.focus(); }
- });
+ if (this.editing) {
+
+ Object.keys(this.labelCounts).forEach(
+ key => this.editValues[key] = true);
+
+ if (this.editInputDomId) {
+ setTimeout(() => {
+ const node = document.getElementById(this.editInputDomId);
+ if (node) { node.focus(); }
+ });
+ }
}
}
}