LP1965448 Holdings edit enforce required stat cats
authorBill Erickson <berickxx@gmail.com>
Thu, 7 Jul 2022 20:28:36 +0000 (16:28 -0400)
committerGalen Charlton <gmc@equinoxOLI.org>
Fri, 8 Jul 2022 17:17:20 +0000 (13:17 -0400)
Required copy stat cats require a value when creating or editing
copies.

Switching between tabs in the copy editor no longer alert the user when
a change is pending, since it may be necessary to hop between tabs to
resolve issues.  Pending changes alerts will still appear when leaving
the page if needed.

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/copy-attrs.component.html
Open-ILS/src/eg2/src/app/staff/cat/volcopy/copy-attrs.component.ts
Open-ILS/src/eg2/src/app/staff/cat/volcopy/volcopy.component.ts
Open-ILS/src/eg2/src/app/staff/cat/volcopy/volcopy.service.ts

index dcee71d..2479ca6 100644 (file)
         </ng-template>
         <eg-batch-item-attr label="{{cat.name()}} ({{orgSn(cat.owner())}})" i18n-label
           name="stat_cat_{{cat.id()}}" editInputDomId="stat-cat-input-{{cat.id()}}"
+          [valueRequired]="cat.required() == 't'"
           [editTemplate]="statCatTemplate"
           [labelCounts]="statCatCounts(cat.id())"
           (valueCleared)="statCatChanged(cat.id(), true)"
index 8b4c29b..e04a2bc 100644 (file)
@@ -414,6 +414,8 @@ export class CopyAttrsComponent implements OnInit, AfterViewInit {
 
             copy.ischanged(true);
         });
+
+        this.emitSaveChange();
     }
 
     openCopyAlerts() {
index e288b8d..c650d6d 100644 (file)
@@ -179,18 +179,13 @@ export class VolCopyComponent implements OnInit {
     beforeTabChange(evt: NgbNavChangeEvent) {
         evt.preventDefault();
 
-        let promise = this.canDeactivate();
-        if (!(promise instanceof Promise)) {
-            promise = Promise.resolve(promise);
-        }
-
-        promise.then(ok => {
-            if (ok) {
-                this.routingAllowed = true;
-                this.tab = evt.nextId;
-                this.routeToTab();
-            }
-        });
+        // Always allow routing between tabs since no changes are lost
+        // in the process.  In some cases, this is necessary to avoid
+        // "pending changes" alerts while you are trying to resolve
+        // other issues (e.g. applying values for required fields).
+        this.routingAllowed = true;
+        this.tab = evt.nextId;
+        this.routeToTab();
     }
 
     routeToTab() {
@@ -527,7 +522,15 @@ export class VolCopyComponent implements OnInit {
     }
 
     isNotSaveable(): boolean {
-        return !(this.volsCanSave && this.attrsCanSave);
+
+        if (!this.volsCanSave) { return true; }
+        if (!this.attrsCanSave) { return true; }
+
+        // This can happen regardless of whether we are modifying
+        // volumes vs. copies.
+        if (this.volcopy.missingRequiredStatCat()) { return true; }
+
+        return false;
     }
 
     volsCanSaveChange(can: boolean) {
index d898c3e..1d42d97 100644 (file)
@@ -436,5 +436,27 @@ export class VolCopyService {
         return this.copyStatuses[statId] &&
                this.copyStatuses[statId].restrict_copy_delete() === 't';
     }
+
+    // Returns true if any items are missing values for a required stat cat.
+    missingRequiredStatCat(): boolean {
+        let missing = false;
+
+        this.currentContext.copyList().forEach(copy => {
+            if (!copy.barcode()) { return; }
+
+            this.commonData.acp_stat_cat.forEach(cat => {
+                if (cat.required() !== 't') { return; }
+
+                const matches = copy.stat_cat_entries()
+                    .filter(e => e.stat_cat() === cat.id());
+
+                if (matches.length === 0) {
+                    missing = true;
+                }
+            });
+        });
+
+        return missing;
+    }
 }