From 2192fe648a872ec9915714093f4a4bb721d6fe4b Mon Sep 17 00:00:00 2001 From: Denys Vuika Date: Mon, 15 Aug 2016 11:57:47 +0100 Subject: [PATCH] #572 Minor code improvements --- .../src/components/widgets/widget.model.ts | 21 ++++++++++--------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/ng2-components/ng2-activiti-form/src/components/widgets/widget.model.ts b/ng2-components/ng2-activiti-form/src/components/widgets/widget.model.ts index 89d866e6fa..778b9fa584 100644 --- a/ng2-components/ng2-activiti-form/src/components/widgets/widget.model.ts +++ b/ng2-components/ng2-activiti-form/src/components/widgets/widget.model.ts @@ -30,6 +30,10 @@ export class FormFieldTypes { static RADIO_BUTTONS: string = 'radio-buttons'; static DISPLAY_VALUE: string = 'readonly'; static READONLY_TEXT: string = 'readonly-text'; + + static READONLY_TYPES: string[] = [ + FormFieldTypes.READONLY_TEXT + ]; } export class FormWidgetModel { @@ -178,18 +182,14 @@ export class FormFieldModel extends FormWidgetModel { this.form.values[this.id] = this.options[0].id; } } else { - if (!this.isIngonreType()) { + if (!FormFieldModel.isReadOnlyType(this.type)) { this.form.values[this.id] = this.value; } } } - private isIngonreType(): boolean { - if (this.type === FormFieldTypes.READONLY_TEXT) { - return true; - } else { - return false; - } + static isReadOnlyType(type: string) { + return FormFieldTypes.READONLY_TYPES.indexOf(type) > -1; } } @@ -387,7 +387,6 @@ export class FormModel { let tabCache: WidgetModelCache = {}; - // this.tabs = (json.tabs || []).map(t => new TabModel(this, t)); this.tabs = (json.tabs || []).map(t => { let model = new TabModel(this, t); tabCache[model.id] = model; @@ -397,7 +396,7 @@ export class FormModel { this.fields = (json.fields || json.formDefinition.fields || []).map(obj => new ContainerModel(this, obj)); if (data) { - this.updateFormValueWithProvaidedDataModel(data); + this.loadData(data); } for (let i = 0; i < this.fields.length; i++) { @@ -432,7 +431,9 @@ export class FormModel { } } - private updateFormValueWithProvaidedDataModel(data: any) { + // Loads external data and overrides field values + // Typically used when form definition and form data coming from different sources + private loadData(data: any) { for (let i = 0; i < this.fields.length; i++) { let containerModel = this.fields[i]; if (containerModel) {