LP1847800 fm-editor defaultNewRecord backport
authorBill Erickson <berickxx@gmail.com>
Wed, 13 May 2020 14:22:02 +0000 (10:22 -0400)
committerChris Sharp <csharp@georgialibraries.org>
Thu, 14 May 2020 21:25:43 +0000 (17:25 -0400)
Backport the defaultNewRecord option for the fm-editor and auto admin
pages to support new record creation based on grid filters.

This feature was originally part of LP1840287 which was not backported
to 3.4

Signed-off-by: Bill Erickson <berickxx@gmail.com>
Signed-off-by: Chris Sharp <csharp@georgialibraries.org>
Open-ILS/src/eg2/src/app/share/fm-editor/fm-editor.component.ts
Open-ILS/src/eg2/src/app/staff/share/admin-page/admin-page.component.html

index 2d92718..bed3d86 100644 (file)
@@ -100,6 +100,9 @@ export class FmRecordEditorComponent
     // behaviour for each field (by field name).
     @Input() fieldOptions: {[fieldName: string]: FmFieldOptions} = {};
 
+    // This is used to set default values when making a new record
+    @Input() defaultNewRecord: IdlObject;
+
     // list of fields that should not be displayed
     @Input() hiddenFieldsList: string[] = [];
     @Input() hiddenFields: string; // comma-separated string version
@@ -356,8 +359,16 @@ export class FmRecordEditorComponent
         //
         // Create a new record from the stub record provided by the
         // caller or a new from-scratch record
-        // Set this._record (not this.record) to avoid loop in initRecord()
-        this._record = this.record || this.idl.create(this.idlClass);
+        if (!this.record) {
+            // NOTE: Set this._record (not this.record) to avoid
+            // loop in initRecord()
+            if (this.defaultNewRecord) {
+                // Clone to avoid polluting the stub record
+                this._record = this.idl.clone(this.defaultNewRecord);
+            } else {
+                this._record = this.idl.create(this.idlClass);
+            }
+        }
         this._recordId = null; // avoid future confusion
 
         return this.getFieldList();
index 00bc67a..09c1557 100644 (file)
@@ -48,7 +48,7 @@
 </eg-grid>
 
 <eg-fm-record-editor #editDialog idlClass="{{idlClass}}" 
-    [fieldOptions]="fieldOptions"
+    [fieldOptions]="fieldOptions" [defaultNewRecord]="defaultNewRecord"
     [preloadLinkedValues]="true" readonlyFields="{{readonlyFields}}">
 </eg-fm-record-editor>