LP1840050 FM Editor WIP
authorBill Erickson <berickxx@gmail.com>
Wed, 14 Aug 2019 16:41:55 +0000 (12:41 -0400)
committerBill Erickson <berickxx@gmail.com>
Wed, 14 Aug 2019 16:41:55 +0000 (12:41 -0400)
Signed-off-by: Bill Erickson <berickxx@gmail.com>
Open-ILS/src/eg2/src/app/share/fm-editor/fm-editor.component.html
Open-ILS/src/eg2/src/app/share/fm-editor/fm-editor.component.ts

index 48c05f4..2621b3e 100644 (file)
@@ -5,7 +5,7 @@
 <eg-string #failStr text="Update Failed" i18n-text></eg-string>
 
 <ng-template #dialogContent>
-  <div class="modal-header bg-info">
+  <div class="modal-header bg-info" *ngIf="!hideBanner">
     <h4 class="modal-title" i18n>Record Editor: {{recordLabel}}</h4>
     <ng-container *ngIf="isDialog()">
       <button type="button" class="close" 
index a3a6138..33da1f4 100644 (file)
@@ -118,14 +118,18 @@ export class FmRecordEditorComponent
     // Display within a modal dialog window or inline in the page.
     @Input() displayMode: 'dialog' | 'inline' = 'dialog';
 
+    // Hide the top 'Record Editor: ...' banner.  Primarily useful
+    // for displayMode === 'inline'
+    @Input() hideBanner: boolean;
+
     // Emit the modified object when the save action completes.
-    @Output() onSave$ = new EventEmitter<IdlObject>();
+    @Output() recordSaved = new EventEmitter<IdlObject>();
 
     // Emit the original object when the save action is canceled.
-    @Output() onCancel$ = new EventEmitter<IdlObject>();
+    @Output() recordCanceled = new EventEmitter<IdlObject>();
 
     // Emit an error message when the save action fails.
-    @Output() onError$ = new EventEmitter<string>();
+    @Output() recordError = new EventEmitter<string>();
 
     @ViewChild('translator') private translator: TranslateComponent;
     @ViewChild('successStr') successStr: StringComponent;
@@ -149,18 +153,23 @@ export class FmRecordEditorComponent
     //       'view' for viewing an existing record without editing
     @Input() mode: 'create' | 'update' | 'view' = 'create';
 
-    // Record ID to view/update.  Value is dynamic.  Records are not
-    // fetched until .open() is called.
-    _recordId: any;
+    // recordId and record getters and setters.
+    // Note that setting the this.recordId to NULL does not clear the
+    // current value of this.record and vice versa.  Only viable data
+    // is actionable.  This allows the caller to use both @Input()'s
+    // without each clobbering the other.
+
+    // Record ID to view/update.  
+    _recordId: any = null;
     @Input() set recordId(id: any) {
         if (id) {
             if (id !== this._recordId) {
                 this._recordId = id;
+                this._record = null; // force re-fetch
                 this.handleRecordChange();
             }
         } else {
             this._recordId = null;
-            this._record = null;
         }
     }
 
@@ -169,16 +178,15 @@ export class FmRecordEditorComponent
     }
 
     // IDL record we are editing
-    _record: IdlObject;
-
+    _record: IdlObject = null;
     @Input() set record(r: IdlObject) {
         if (r) {
             if (!this.idl.pkeyMatches(this.record, r)) {
                 this._record = r;
+                this._recordId = null; // avoid mismatch
                 this.handleRecordChange();
             }
         } else {
-            this._recordId = null;
             this._record = null;
         }
     }
@@ -546,12 +554,12 @@ export class FmRecordEditorComponent
         this.convertDatatypesToIdl(recToSave);
         this.pcrud[this.mode]([recToSave]).toPromise().then(
             result => {
-                this.onSave$.emit(result);
+                this.recordSaved.emit(result);
                 this.successStr.current().then(msg => this.toast.success(msg));
                 if (this.isDialog()) { this.close(result); }
             },
             error => {
-                this.onError$.emit(error);
+                this.recordError.emit(error);
                 this.failStr.current().then(msg => this.toast.warning(msg));
                 if (this.isDialog()) { this.error(error); }
             }
@@ -559,7 +567,7 @@ export class FmRecordEditorComponent
     }
 
     cancel() {
-        this.onCancel$.emit(this.record);
+        this.recordCanceled.emit(this.record);
         this.close();
     }