LPXXX Angular Volcopy
authorBill Erickson <berickxx@gmail.com>
Fri, 5 Jun 2020 18:07:39 +0000 (14:07 -0400)
committerBill Erickson <berickxx@gmail.com>
Fri, 5 Jun 2020 18:07:39 +0000 (14:07 -0400)
Signed-off-by: Bill Erickson <berickxx@gmail.com>
Open-ILS/src/eg2/src/app/staff/cat/volcopy/vol-edit.component.html
Open-ILS/src/eg2/src/app/staff/cat/volcopy/vol-edit.component.ts
Open-ILS/src/eg2/src/app/staff/cat/volcopy/volcopy.ts

index dbfcbea..4b849b9 100644 (file)
@@ -46,7 +46,7 @@
   <div class="p-1" [ngStyle]="{flex: flexAt(7)}">
     <label class="font-weight-bold" i18n>Batch</label>
     <div>
-      <button class="btn btn-outline-dark label-with-material-icon" 
+      <button class="btn btn-sm btn-outline-dark label-with-material-icon" 
         (click)="batchVolApply()">
         <span i18n>Apply</span>
         <span class="material-icons">arrow_downward</span>
         <div class="p-1" [ngStyle]="{flex: flexAt(3)}">
           <ng-container *ngIf="copyIdx == 0">
             <eg-combobox 
-              [startId]="volNode.target.label_class()"
+              [selectedId]="volNode.target.label_class()"
               [smallFormControl]="true"
               [required]="true" 
               (onChange)="applyVolValue(volNode.target, 'label_class', $event ? $event.id : null)">
         <div class="p-1" [ngStyle]="{flex: flexAt(4)}">
           <ng-container *ngIf="copyIdx == 0">
             <eg-combobox 
-              [startId]="volNode.target.prefix()"
+              [selectedId]="volNode.target.prefix()"
               [required]="true" 
               [smallFormControl]="true"
               (onChange)="applyVolValue(volNode.target, 'prefix', $event ? $event.id : null)">
         <div class="p-1" [ngStyle]="{flex: flexAt(5)}">
           <ng-container *ngIf="copyIdx == 0">
             <input class="form-control form-control-sm" type="text"
+              spellcheck="false"
               [required]="true"
               [ngModel]="volNode.target.label()"
               (onChange)="applyVolValue(volNode.target, 'label', $event)">
         <div class="p-1" [ngStyle]="{flex: flexAt(6)}">
           <ng-container *ngIf="copyIdx == 0">
             <eg-combobox 
-              [startId]="volNode.target.suffix()"
+              [selectedId]="volNode.target.suffix()"
               [required]="true" 
               [smallFormControl]="true"
               (onChange)="applyVolValue(volNode.target, 'suffix', $event ? $event.id : null)">
         </div>
         <div class="p-1" [ngStyle]="{flex: flexAt(8)}">
           <input type="text" class="form-control form-control-sm"
+            id="barcode-input-{{copyNode.target.id()}}"
+            spellcheck="false"
             [required]="true"
+            (keyup.enter)="selectNextBarcode(copyNode.target.id())"
+            (keyup.shift.enter)="selectNextBarcode(copyNode.target.id(), true)"
             [ngModel]="copyNode.target.barcode()"
             (ngModelChange)="applyCopyValue(copyNode.target, 'barcode', $event)"/>
         </div>
           <ng-container *ngIf="recordHasParts(volNode.target.record())">
             <eg-combobox 
               [disabled]="bibParts[volNode.target.record()].length == 0"
-              [startId]="copyNode.target.parts()[0] ? copyNode.target.parts()[0].id() : null"
+              [selectedId]="copyNode.target.parts()[0] ? copyNode.target.parts()[0].id() : null"
               [smallFormControl]="true"
               (onChange)="copyPartChanged(copyNode, $event)">
               <eg-combobox-entry *ngFor="let part of bibParts[volNode.target.record()]"
index 1a01e01..f6e927c 100644 (file)
@@ -31,13 +31,15 @@ export class VolEditComponent implements OnInit {
     volSuffixes: IdlObject[] = null;
     bibParts: {[bibId: number]: IdlObject[]} = {};
 
-    batchVolClass: number = null;
-    batchVolPrefix: number = null;
-    batchVolSuffix: number = null;
-    batchVolLabel: string = null;
+    batchVolClass: ComboboxEntry;
+    batchVolPrefix: ComboboxEntry;
+    batchVolSuffix: ComboboxEntry;
+    batchVolLabel: ComboboxEntry;
+
     recordVolLabels: string[] = [];
 
     constructor(
+        private renderer: Renderer2,
         private pcrud: PcrudService,
         private net: NetService,
         private holdings: HoldingsService
@@ -152,6 +154,51 @@ export class VolEditComponent implements OnInit {
     }
 
     batchVolApply() {
+        this.context.volNodes().forEach(volNode => {
+            const vol = volNode.target;
+            console.log('batch vol class', this.batchVolClass.id);
+            if (this.batchVolClass) {
+                this.applyVolValue(vol, 'label_class', this.batchVolClass.id);
+            }
+            if (this.batchVolPrefix) {
+                this.applyVolValue(vol, 'prefix', this.batchVolPrefix.id);
+            }
+            if (this.batchVolSuffix) {
+                this.applyVolValue(vol, 'suffix', this.batchVolSuffix.id);
+            }
+            if (this.batchVolLabel) {
+                this.applyVolValue(vol, 'label', this.batchVolLabel.id);
+            }
+        });
+    }
+
+    selectNextBarcode(id: number, previous?: boolean) {
+        let found = false;
+        let nextId: number = null;
+        let firstId: number = null;
+
+        let copies = this.context.copyList();
+        if (previous) { copies = copies.reverse(); }
+
+        // Find the ID of the next item.  If this is the last item,
+        // loop back to the first item.
+        copies.forEach(copy => {
+            if (nextId !== null) { return; }
+
+            // In case we have to loop back to the first copy.
+            if (firstId === null) { firstId = copy.id(); }
+
+            if (found) {
+                if (nextId === null) {
+                    nextId = copy.id();
+                }
+            } else if (copy.id() === id) {
+                found = true;
+            }
+        });
+
+        this.renderer.selectRootElement(
+                '#barcode-input-' + (nextId || firstId)).select();
     }
 }
 
index c73a6bd..aa07966 100644 (file)
@@ -32,6 +32,21 @@ export class VolCopyContext {
         return this.holdings.root.children;
     }
 
+    volNodes(): HoldingsTreeNode[] {
+        let vols = [];
+        this.orgNodes().forEach(orgNode =>
+            vols = vols.concat(orgNode.children));
+        return vols;
+    }
+
+    copyList(): IdlObject[] {
+        let copies = [];
+        this.volNodes().forEach(volNode => {
+            copies = copies.concat(volNode.children.map(c => c.target));
+        });
+        return copies;
+    }
+
     // Returns IDs for all bib records represented in our holdings tree.
     getRecordIds(): number[] {
         const idHash: {[id: number]: boolean} = {};