LPXXX fm-editor API consolidation WIP user/berick/lpxxx-org-unit-admin
authorBill Erickson <berickxx@gmail.com>
Mon, 12 Aug 2019 21:46:40 +0000 (17:46 -0400)
committerBill Erickson <berickxx@gmail.com>
Mon, 12 Aug 2019 21:46:40 +0000 (17:46 -0400)
Signed-off-by: Bill Erickson <berickxx@gmail.com>
Open-ILS/src/eg2/src/app/share/fm-editor/fm-editor.component.ts

index 739a2c4..aa54bd1 100644 (file)
@@ -160,10 +160,14 @@ export class FmRecordEditorComponent
             }
         } else {
             this._recordId = null;
-            this.record = null;
+            this._record = null;
         }
     }
 
+    get recordId(): any {
+        return this._recordId;
+    }
+
     // IDL record we are editing
     _record: IdlObject;
 
@@ -174,7 +178,7 @@ export class FmRecordEditorComponent
                 this.handleRecordChange();
             }
         } else {
-            this.recordId = null;
+            this._recordId = null;
             this._record = null;
         }
     }
@@ -270,9 +274,12 @@ export class FmRecordEditorComponent
             let promise;
             if (this.record && this.recordId === null) {
                 promise = Promise.resolve(this.record);
-            } else {
+            } else if (this.recordId) {
                 promise =
                     this.pcrud.retrieve(this.idlClass, this.recordId).toPromise();
+            } else {
+                // Not enough data yet to fetch anything
+                return Promise.resolve();
             }
 
             return promise.then(rec => {
@@ -282,7 +289,8 @@ export class FmRecordEditorComponent
                         record found with id ${this.recordId}`);
                 }
 
-                this.record = rec;
+                // Set this._record (not this.record) to avoid loop in initRecord()
+                this._record = rec;
                 this.convertDatatypesToJs();
                 return this.getFieldList();
             });
@@ -292,8 +300,9 @@ export class FmRecordEditorComponent
         //
         // Create a new record from the stub record provided by the
         // caller or a new from-scratch record
-        this.record = this.record || this.idl.create(this.idlClass);
-        this.recordId = null; // avoid future confusion
+        // Set this._record (not this.record) to avoid loop in initRecord()
+        this._record = this.record || this.idl.create(this.idlClass);
+        this._recordId = null; // avoid future confusion
 
         return this.getFieldList();
     }