LP1840327 FM Editor isReadonlyOverride support user/berick/lp1840327-ang-standing-penalties
authorBill Erickson <berickxx@gmail.com>
Tue, 27 Aug 2019 16:18:12 +0000 (12:18 -0400)
committerBill Erickson <berickxx@gmail.com>
Tue, 27 Aug 2019 16:18:17 +0000 (12:18 -0400)
Allow FM editor users to provide a function called at run time which
determines whether a specific field value should cause a field input to
be marked as readonly in the editor form.

Adds sandbox example.

Signed-off-by: Bill Erickson <berickxx@gmail.com>
Open-ILS/src/eg2/src/app/share/fm-editor/fm-editor.component.ts
Open-ILS/src/eg2/src/app/staff/sandbox/sandbox.component.html
Open-ILS/src/eg2/src/app/staff/sandbox/sandbox.component.ts

index a574e54..08cc828 100644 (file)
@@ -65,6 +65,11 @@ export interface FmFieldOptions {
     // This only has an affect if the value is true.
     isReadonly?: boolean;
 
+    // If this function is defined, the function will be called
+    // at render time to see if the field should be marked readonly.
+    // This supersedes all other isReadonly specifiers.
+    isReadonlyOverride?: (field: string, record: IdlObject) => boolean;
+
     // Render the field using this custom template instead of chosing
     // from the default set of form inputs.
     customTemplate?: CustomFieldTemplate;
@@ -332,9 +337,18 @@ export class FmRecordEditorComponent
         let promise = null;
         const fieldOptions = this.fieldOptions[field.name] || {};
 
-        field.readOnly = this.mode === 'view'
-            || fieldOptions.isReadonly === true
-            || this.readonlyFieldsList.includes(field.name);
+        if (this.mode === 'view') {
+            field.readOnly = true;
+
+        } else if (fieldOptions.isReadonlyOverride) {
+            field.readOnly =
+                fieldOptions.isReadonlyOverride(field.name, this.record);
+
+        } else {
+
+            field.readOnly = fieldOptions.isReadonly === true
+                || this.readonlyFieldsList.includes(field.name);
+        }
 
         if (fieldOptions.isRequiredOverride) {
             field.isRequired = () => {
index b2d14c1..d296181 100644 (file)
   <eg-grid-column [sortable]="true" path="create_date"></eg-grid-column>
 </eg-grid>
 
-<eg-fm-record-editor #acpEditDialog idlClass="acp" hiddenFields="call_number,creator,create_date,editor,edit_time,loan_duration,fine_level,dummy_author,dummy_isbn,ref,floating,holdable,circ_as_type,active_date,mint_condition,cost,deleted,deposit,deposit_amount,circulate,status_changed_time,copy_number">
+<eg-fm-record-editor #acpEditDialog idlClass="acp" 
+  [fieldOptions]="{status: {isReadonlyOverride: acpEditorReadonly}}"
+  hiddenFields="call_number,creator,create_date,editor,edit_time,loan_duration,fine_level,dummy_author,dummy_isbn,ref,floating,holdable,circ_as_type,active_date,mint_condition,cost,deleted,deposit,deposit_amount,circulate,status_changed_time,copy_number">
 </eg-fm-record-editor>
 <eg-string #successString text="Updated succeeded!" i18n-text></eg-string>
 <eg-string #updateFailedString text="Updated failed!" i18n-text></eg-string>
index c6ea7c3..c9bbd9c 100644 (file)
@@ -105,6 +105,8 @@ export class SandboxComponent implements OnInit {
 
     myTimeForm: FormGroup;
 
+    acpEditorReadonly: (field: string, record: IdlObject) => boolean;
+
     constructor(
         private idl: IdlService,
         private org: OrgService,
@@ -269,6 +271,11 @@ export class SandboxComponent implements OnInit {
                     }
             } )
         });
+
+
+        this.acpEditorReadonly = (field: string, copy: IdlObject): boolean => {
+            return copy.status() === 3; // Lost
+        };
     }
 
     sbChannelHandler = msg => {