From a9e54f6138878562778f7254eb53227d9357fea9 Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Tue, 27 Aug 2019 12:18:12 -0400 Subject: [PATCH] LP1840327 FM Editor isReadonlyOverride support 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 --- .../src/app/share/fm-editor/fm-editor.component.ts | 20 +++++++++++++++++--- .../eg2/src/app/staff/sandbox/sandbox.component.html | 4 +++- .../eg2/src/app/staff/sandbox/sandbox.component.ts | 7 +++++++ 3 files changed, 27 insertions(+), 4 deletions(-) diff --git a/Open-ILS/src/eg2/src/app/share/fm-editor/fm-editor.component.ts b/Open-ILS/src/eg2/src/app/share/fm-editor/fm-editor.component.ts index a574e5491d..08cc8286f8 100644 --- a/Open-ILS/src/eg2/src/app/share/fm-editor/fm-editor.component.ts +++ b/Open-ILS/src/eg2/src/app/share/fm-editor/fm-editor.component.ts @@ -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 = () => { diff --git a/Open-ILS/src/eg2/src/app/staff/sandbox/sandbox.component.html b/Open-ILS/src/eg2/src/app/staff/sandbox/sandbox.component.html index b2d14c1b95..d29618127a 100644 --- a/Open-ILS/src/eg2/src/app/staff/sandbox/sandbox.component.html +++ b/Open-ILS/src/eg2/src/app/staff/sandbox/sandbox.component.html @@ -262,7 +262,9 @@ - + diff --git a/Open-ILS/src/eg2/src/app/staff/sandbox/sandbox.component.ts b/Open-ILS/src/eg2/src/app/staff/sandbox/sandbox.component.ts index c6ea7c3f17..c9bbd9c116 100644 --- a/Open-ILS/src/eg2/src/app/staff/sandbox/sandbox.component.ts +++ b/Open-ILS/src/eg2/src/app/staff/sandbox/sandbox.component.ts @@ -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 => { -- 2.11.0