LP1809288: Make some brt fields read-only
[Evergreen.git] / Open-ILS / src / eg2 / src / app / share / fm-editor / fm-editor.component.ts
index 308218a..7b90a02 100644 (file)
@@ -110,6 +110,8 @@ export class FmRecordEditorComponent
         if (id) { this.recId = id; }
     }
 
+    idPrefix: string;
+
     constructor(
       private modal: NgbModal, // required for passing to parent
       private idl: IdlService,
@@ -124,6 +126,9 @@ export class FmRecordEditorComponent
         this.listifyInputs();
         this.idlDef = this.idl.classes[this.idlClass];
         this.recordLabel = this.idlDef.label;
+
+       // Add some randomness to the generated DOM IDs to ensure against clobbering
+       this.idPrefix = 'fm-editor-' + Math.floor(Math.random() * 100000);
     }
 
     // Opening dialog, fetch data.
@@ -251,7 +256,18 @@ export class FmRecordEditorComponent
                 };
             }
 
-            if (field.datatype === 'link') {
+            if (field.datatype === 'link' && field.readOnly) { // no need to fetch all possible values for read-only fields
+                let id_to_fetch = this.record[field.name]();
+                if (id_to_fetch) {
+                    promises.push(
+                        this.pcrud.retrieve(field.class, this.record[field.name]())
+                        .toPromise().then(list => {
+                            field.linkedValues =
+                                this.flattenLinkedValues(field.class, Array(list));
+                        })
+                    );
+                }
+            } else if (field.datatype === 'link') {
                 promises.push(
                     this.pcrud.retrieveAll(field.class, {}, {atomic : true})
                     .toPromise().then(list => {