From a27f15d4f75b8675b5cb54e580ab0a9379fcf2a7 Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Tue, 27 Apr 2021 15:18:45 -0400 Subject: [PATCH] LP1904036 Check patron edit save state on page load Signed-off-by: Bill Erickson Signed-off-by: Jane Sandberg Signed-off-by: Galen Charlton --- .../src/app/staff/circ/patron/edit.component.ts | 32 ++++++++++++++-------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/Open-ILS/src/eg2/src/app/staff/circ/patron/edit.component.ts b/Open-ILS/src/eg2/src/app/staff/circ/patron/edit.component.ts index 3b1576d28a..66bfff1d33 100644 --- a/Open-ILS/src/eg2/src/app/staff/circ/patron/edit.component.ts +++ b/Open-ILS/src/eg2/src/app/staff/circ/patron/edit.component.ts @@ -234,7 +234,6 @@ export class EditComponent implements OnInit, AfterViewInit { } ngAfterViewInit() { - // Do this after view init so we can leverage } load(): Promise { @@ -253,7 +252,16 @@ export class EditComponent implements OnInit, AfterViewInit { .then(_ => this.setOptInSettings()) .then(_ => this.setSmsCarriers()) .then(_ => this.setFieldPatterns()) - .then(_ => this.loading = false); + .then(_ => this.loading = false) + // Not my preferred way to handle this, but some values are + // applied to widgets slightly after the load() is done and the + // widgets are rendered. If a widget is required and has no + // value yet, then a premature save state check will see the + // form as invalid and nonsaveable. In order the check for a + // non-saveable state on page load without forcing the page into + // an nonsaveable state on every page load, check the save state + // after a 1 second delay. + .then(_ => setTimeout(() => this.emitSaveState(), 1000)); } setEditProfiles(): Promise { @@ -782,15 +790,10 @@ export class EditComponent implements OnInit, AfterViewInit { return this.objectFromPath(path, index)[field](); } - adjustSaveSate() { - // Avoid responding to any value changes while we are loading - if (this.loading) { return; } - + emitSaveState() { // Timeout gives the form a chance to mark fields as (in)valid setTimeout(() => { - this.changesPending = true; - const invalidInput = document.querySelector('.ng-invalid'); const canSave = ( @@ -805,6 +808,13 @@ export class EditComponent implements OnInit, AfterViewInit { }); } + adjustSaveState() { + // Avoid responding to any value changes while we are loading + if (this.loading) { return; } + this.changesPending = true; + this.emitSaveState(); + } + userStatCatChange(cat: IdlObject, entry: ComboboxEntry) { let map = this.patron.stat_cat_entries() .filter(m => m.stat_cat() === cat.id())[0]; @@ -826,12 +836,12 @@ export class EditComponent implements OnInit, AfterViewInit { this.patron.stat_cat_entries().push(map); } - this.adjustSaveSate(); + this.adjustSaveState(); } userSettingChange(name: string, value: any) { this.userSettings[name] = value; - this.adjustSaveSate(); + this.adjustSaveState(); } applySurveyResponse(question: IdlObject, answer: ComboboxEntry) { @@ -926,7 +936,7 @@ export class EditComponent implements OnInit, AfterViewInit { break; } - this.adjustSaveSate(); + this.adjustSaveState(); } maintainJuvFlag() { -- 2.11.0