From e9e08c2c0bac46f787eccf3c8681f26ac366f006 Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Thu, 7 Jul 2022 16:28:36 -0400 Subject: [PATCH] LP1965448 Holdings edit enforce required stat cats 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 Signed-off-by: Galen Charlton --- .../staff/cat/volcopy/copy-attrs.component.html | 1 + .../app/staff/cat/volcopy/copy-attrs.component.ts | 2 ++ .../src/app/staff/cat/volcopy/volcopy.component.ts | 29 ++++++++++++---------- .../src/app/staff/cat/volcopy/volcopy.service.ts | 22 ++++++++++++++++ 4 files changed, 41 insertions(+), 13 deletions(-) diff --git a/Open-ILS/src/eg2/src/app/staff/cat/volcopy/copy-attrs.component.html b/Open-ILS/src/eg2/src/app/staff/cat/volcopy/copy-attrs.component.html index dcee71ddb1..2479ca6b1a 100644 --- a/Open-ILS/src/eg2/src/app/staff/cat/volcopy/copy-attrs.component.html +++ b/Open-ILS/src/eg2/src/app/staff/cat/volcopy/copy-attrs.component.html @@ -470,6 +470,7 @@ { - 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) { diff --git a/Open-ILS/src/eg2/src/app/staff/cat/volcopy/volcopy.service.ts b/Open-ILS/src/eg2/src/app/staff/cat/volcopy/volcopy.service.ts index d898c3e27f..1d42d97d6f 100644 --- a/Open-ILS/src/eg2/src/app/staff/cat/volcopy/volcopy.service.ts +++ b/Open-ILS/src/eg2/src/app/staff/cat/volcopy/volcopy.service.ts @@ -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; + } } -- 2.11.0