LP1975879 Holdings editor allows owning lib changed
authorBill Erickson <berickxx@gmail.com>
Fri, 8 Jul 2022 20:19:44 +0000 (16:19 -0400)
committerGalen Charlton <gmc@equinoxOLI.org>
Mon, 11 Jul 2022 16:42:00 +0000 (12:42 -0400)
A new edit (pencil) icon appears to the left of the first call number
field in the 'holdings' tab of the copy edit.  When clicked, the user has
a chance to enter a new org unit value to act as the owning lib of the
affected call number.

If the "Change Circ Lib When Owning Lib Changes" preference is set, then
any copies linked to the affected call number within the current edit
session will have their circ libs updated to match the new owning lib of
the call number.

Signed-off-by: Bill Erickson <berickxx@gmail.com>
Signed-off-by: Galen Charlton <gmc@equinoxOLI.org>
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 5926461..1eaa072 100644 (file)
                 <span>{{orgNode.target.shortname()}}</span>
               </ng-container>
             </div>
-            <div class="pr-1">
-              <ng-container *ngIf="copyIdx == 0 && volIdx == 0 && (
-                context.sessionType == 'record' || context.sessionType == 'mixed')">
-                  <ng-template #addOrgTmpl>
-                    <eg-org-select [limitPerms]="['CREATE_VOLUME']" 
-                      placeholder="Select Location..." i18n-placeholder
-                      [hideOrgs]="volcopy.hideVolOrgs"
-                      (onChange)="addVol($event); addOrgPopover.close()">
-                    </eg-org-select>
-                  </ng-template>
+            <ng-container *ngIf="copyIdx == 0 && volIdx == 0 && (
+              context.sessionType == 'record' || context.sessionType == 'mixed')">
+              <div class="pr-1">
+                <ng-template #addOrgTmpl>
+                  <eg-org-select [limitPerms]="['CREATE_VOLUME']" 
+                    placeholder="Select Location..." i18n-placeholder
+                    [hideOrgs]="volcopy.hideVolOrgs"
+                    (onChange)="addVol($event); addOrgPopover.close()">
+                  </eg-org-select>
+                </ng-template>
 
-                  <button class="btn btn-sm material-icon-button p-1"
-                    placement="bottom" [ngbPopover]="addOrgTmpl"
-                    autoClose="outside" #addOrgPopover="ngbPopover"
-                    i18n-popoverTitle="Add Call Number For Location"
-                    i18n-title title="Add Call Number For Location"
-                    (click)="addVolOrg=null">
-                    <span class="material-icons">add_circle_outline</span>
-                  </button>
-              </ng-container>
-            </div>
+                <button class="btn btn-sm material-icon-button p-1"
+                  placement="bottom" [ngbPopover]="addOrgTmpl"
+                  autoClose="outside" #addOrgPopover="ngbPopover"
+                  i18n-popoverTitle="Add Call Number For Location"
+                  i18n-title title="Add Call Number For Location">
+                  <span class="material-icons">add_circle_outline</span>
+                </button>
+              </div>
+            </ng-container>
+            <ng-container *ngIf="copyIdx == 0">
+              <div class="pr-1">
+                <ng-template #editOrgTmpl>
+                  <eg-org-select [limitPerms]="['CREATE_VOLUME']" 
+                    placeholder="Select Location..." i18n-placeholder
+                    [hideOrgs]="volcopy.hideVolOrgs"
+                    (onChange)="editVolOwner(volNode, $event); editOrgPopover.close()">
+                  </eg-org-select>
+                </ng-template>
+
+                <button class="btn btn-sm material-icon-button p-1"
+                  placement="bottom" [ngbPopover]="editOrgTmpl"
+                  autoClose="outside" #editOrgPopover="ngbPopover"
+                  i18n-popoverTitle="Edit Call Number Owning Location"
+                  i18n-title title="Edit Call Number Owning Location">
+                  <span class="material-icons">edit</span>
+                </button>
+              </div>
+            </ng-container>
           </div>
         </div>
         <div class="p-1" [ngStyle]="{flex: flexAt(3)}">
index ab9309c..9baf350 100644 (file)
@@ -518,6 +518,54 @@ export class VolEditComponent implements OnInit {
         }
     }
 
+    editVolOwner(volNode: HoldingsTreeNode, org: IdlObject) {
+        if (!org) { return; }
+
+        const orgId = org.id();
+        const vol = volNode.target;
+
+        vol.owning_lib(orgId);
+        vol.ischanged(true);
+
+        // Move the vol node away from its previous org node and append
+        // it to the children list of the target node.
+        let targetOrgNode: HoldingsTreeNode;
+        this.context.orgNodes().forEach(orgNode => {
+
+            if (orgNode.target.id() === orgId) {
+                targetOrgNode = orgNode;
+                return;
+            }
+
+            orgNode.children.forEach((vNode, volIdx) => {
+                if (vol.id() === vNode.target.id()) {
+                    orgNode.children.splice(volIdx, 1);
+                }
+            });
+        });
+
+        if (!targetOrgNode) {
+            targetOrgNode = this.context.findOrCreateOrgNode(orgId);
+        }
+
+        targetOrgNode.children.push(volNode);
+
+        // If configured to do so, also update the circ_lib for any
+        // copies linked to this call number in this edit session.
+        if (this.volcopy.defaults.values.circ_lib_mod_with_owning_lib) {
+            volNode.children.forEach(copyNode => {
+                const copy = copyNode.target;
+                if (copy.circ_lib() !== orgId) {
+                    copy.circ_lib(orgId);
+                    copy.ischanged(true);
+                }
+            });
+        }
+
+        this.emitSaveChange();
+    }
+
+
     displayColumn(field: string): boolean {
         return this.volcopy.defaults.hidden[field] !== true;
     }