LPXXX Angular Volcopy
authorBill Erickson <berickxx@gmail.com>
Tue, 9 Jun 2020 17:33:36 +0000 (13:33 -0400)
committerBill Erickson <berickxx@gmail.com>
Tue, 9 Jun 2020 17:33:36 +0000 (13:33 -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

index 30d7e78..a606b5d 100644 (file)
@@ -4,12 +4,16 @@
   dialogTitle="Delete Call Number?"
   dialogBody="Delete {{deleteVolCount}} Call Number(s) and {{deleteCopyCount}} Associated Item(s)?">
 </eg-confirm-dialog>
+<eg-confirm-dialog 
+  #confirmDelCopy
+  i18n-dialogTitle i18n-dialogBody
+  dialogTitle="Delete Item?"
+  dialogBody="Delete {{deleteCopyCount}} Item(s)?">
+</eg-confirm-dialog>
 
 <div class="row d-flex vol-row border border-info mb-2">
-  <div class="p-1" [ngStyle]="{flex: flexAt(1)}">
-  </div>
-  <div class="p-1" [ngStyle]="{flex: flexAt(2)}">
-  </div>
+  <div class="p-1" [ngStyle]="{flex: flexAt(1)}"> </div>
+  <div class="p-1" [ngStyle]="{flex: flexAt(2)}"> </div>
   <div class="p-1" [ngStyle]="{flex: flexAt(3)}">
     <label class="font-weight-bold" i18n>Classification</label>
     <div>
           </ng-container>
         </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"
-            [ngClass]="{'text-danger': copyNode.target._dupe_barcode}"
-                                               (ngModelChange)="barcodeChanged(copyNode.target, $event)"
-            (keyup.enter)="selectNextBarcode(copyNode.target.id())"
-            (keyup.shift.enter)="selectNextBarcode(copyNode.target.id(), true)"
-            (focus)="$event.target.select()"
-            [ngModel]="copyNode.target.barcode()"
-            (ngModelChange)="applyCopyValue(copyNode.target, 'barcode', $event)"/>
-          <div *ngIf="copyNode.target._dupe_barcode"
-            class="alert alert-danger font-italic p-1" i18n>
-            Duplicate Barcode</div>
+
+          <div class="d-flex">
+            <button class="clear-button" (click)="deleteCopy(copyNode)"
+              title="Delete Item" i18n-title>
+              <span class="material-icons">clear</span>
+            </button>
+
+            <input type="text" class="form-control form-control-sm"
+              id="barcode-input-{{copyNode.target.id()}}"
+              spellcheck="false"
+              [required]="true"
+              [ngClass]="{'text-danger': copyNode.target._dupe_barcode}"
+              (ngModelChange)="barcodeChanged(copyNode.target, $event)"
+              (keyup.enter)="selectNextBarcode(copyNode.target.id())"
+              (keyup.shift.enter)="selectNextBarcode(copyNode.target.id(), true)"
+              (focus)="$event.target.select()"
+              [ngModel]="copyNode.target.barcode()"
+              (ngModelChange)="applyCopyValue(copyNode.target, 'barcode', $event)"/>
+            <div *ngIf="copyNode.target._dupe_barcode"
+              class="alert alert-danger font-italic p-1" i18n>
+              Duplicate Barcode</div>
+          </div>
         </div>
         <div class="p-1" [ngStyle]="{flex: flexAt(9)}">
           <input type="number" min="0" class="form-control form-control-sm"
index 4c3f715..f25da3c 100644 (file)
@@ -54,6 +54,9 @@ export class VolEditComponent implements OnInit {
     @ViewChild('confirmDelVol', {static: false})
         confirmDelVol: ConfirmDialogComponent;
 
+    @ViewChild('confirmDelCopy', {static: false})
+        confirmDelCopy: ConfirmDialogComponent;
+
     constructor(
         private renderer: Renderer2,
         private idl: IdlService,
@@ -274,9 +277,10 @@ export class VolEditComponent implements OnInit {
     }
 
     // Empty volumes get a stub copy
-    addStubCopies() {
+    addStubCopies(volNode?: HoldingsTreeNode) {
+        const nodes = volNode ? [volNode] : this.context.volNodes();
 
-        this.context.volNodes().forEach(volNode => {
+        nodes.forEach(volNode => {
             if (volNode.children.length == 0) {
                 const vol = volNode.target;
                 const copy = this.createStubCopy(vol);
@@ -426,6 +430,47 @@ export class VolEditComponent implements OnInit {
         }
     }
 
+    deleteCopy(copyNode: HoldingsTreeNode) {
+        this.deleteCopyCount = 1;
+        this.confirmDelCopy.open().toPromise().then(confirmed => {
+            if (confirmed) { this.deleteOneCopy(copyNode); }
+        });
+    }
+
+    deleteOneCopy(copyNode: HoldingsTreeNode) {
+
+        const targetCopy = copyNode.target;
+
+        const orgNodes = this.context.orgNodes();
+        for (let orgIdx = 0; orgIdx < orgNodes.length; orgIdx++) {
+            const orgNode = orgNodes[orgIdx];
+
+            for (let volIdx = 0; volIdx < orgNode.children.length; volIdx++) {
+                const volNode = orgNode.children[volIdx];
+
+                for (let copyIdx = 0; copyIdx < volNode.children.length; copyIdx++) {
+                    const copy = volNode.children[copyIdx].target;
+
+                    if (copy.id() === targetCopy.id()) {
+                        volNode.children.splice(copyIdx, 1);
+                        if (!copy.isnew()) {
+                            copy.isdeleted(true);
+                            this.copiesToDelete.push(copy);
+                        }
+
+                        if (volNode.children.length === 0) {
+                            // When removing the last copy, add a stub copy.
+                            this.addStubCopies();
+                        }
+
+                        return;
+                    }
+                }
+            }
+        }
+    }
+
+
     deleteVol(volNode: HoldingsTreeNode) {
         this.deleteVolCount = 1;
         this.deleteCopyCount = volNode.children.length;
@@ -473,7 +518,7 @@ export class VolEditComponent implements OnInit {
                     });
                 }
 
-                if (deleteVolIdx) { break; }
+                if (deleteVolIdx !== null) { break; }
             }
 
             if (deleteVolIdx !== null) {