LP#1857150: eg-fm-record-editor: add isDirty() method
authorGalen Charlton <gmc@equinoxinitiative.org>
Tue, 1 Sep 2020 02:39:49 +0000 (22:39 -0400)
committerJason Etheridge <jason@EquinoxInitiative.org>
Thu, 10 Sep 2020 20:35:48 +0000 (16:35 -0400)
This adds an isDirty() method to the form that components embedding
an eg-fm-record-editor can use to check whether the form is
currently dirty.

NOTE: not all of the custom components that can show up on
      an fm-edit form currently implement component-level
      dirty checks.

Sponsored-by: Evergreen Community Development Initiative
Signed-off-by: Galen Charlton <gmc@equinoxinitiative.org>
Signed-off-by: Ruth Frasur <rfrasur@library.in.gov>
Signed-off-by: Bill Erickson <berickxx@gmail.com>
Signed-off-by: Jason Etheridge <jason@EquinoxInitiative.org>
Open-ILS/src/eg2/src/app/share/fm-editor/fm-editor.component.ts

index a396fd4..9a1a12e 100644 (file)
@@ -1,5 +1,6 @@
 import {Component, OnInit, Input, ViewChild,
     Output, EventEmitter, TemplateRef} from '@angular/core';
+import {NgForm} from '@angular/forms';
 import {IdlService, IdlObject} from '@eg/core/idl.service';
 import {Observable} from 'rxjs';
 import {map} from 'rxjs/operators';
@@ -158,6 +159,7 @@ export class FmRecordEditorComponent
     @ViewChild('successStr', { static: true }) successStr: StringComponent;
     @ViewChild('failStr', { static: true }) failStr: StringComponent;
     @ViewChild('confirmDel', { static: true }) confirmDel: ConfirmDialogComponent;
+    @ViewChild('fmEditForm', { static: false}) fmEditForm: NgForm;
 
     // IDL info for the the selected IDL class
     idlDef: any;
@@ -293,6 +295,10 @@ export class FmRecordEditorComponent
         return this.displayMode === 'dialog';
     }
 
+    isDirty(): boolean {
+        return this.fmEditForm ? this.fmEditForm.dirty : false;
+    }
+
     // DEPRECATED: This is a duplicate of this.record = abc;
     setRecord(record: IdlObject) {
         console.warn('fm-editor:setRecord() is deprecated. ' +
@@ -618,6 +624,9 @@ export class FmRecordEditorComponent
         this.pcrud[this.mode]([recToSave]).toPromise().then(
             result => {
                 this.recordSaved.emit(result);
+                if (this.fmEditForm) {
+                    this.fmEditForm.form.markAsPristine();
+                }
                 this.successStr.current().then(msg => this.toast.success(msg));
                 if (this.isDialog()) { this.record = undefined; this.close(result); }
             },