From b4def6e91903786e5b2de9fe7242aecd8bc067f8 Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Thu, 14 Nov 2019 14:07:37 -0500 Subject: [PATCH] Edit option lists --- ext/afform/core/afform.php | 5 + ext/afform/core/ang/afField/afField.js | 14 +- .../core/ang/afField/widgets/CheckBox.html | 8 +- .../core/ang/afField/widgets/Radio.html | 6 +- .../core/ang/afField/widgets/Select.html | 2 +- ext/afform/gui/afform_gui.php | 16 +- ext/afform/gui/ang/afGuiEditor.css | 89 ++++++++++- ext/afform/gui/ang/afGuiEditor.js | 148 ++++++++++++++++-- ext/afform/gui/ang/afGuiEditor/block.html | 15 +- ext/afform/gui/ang/afGuiEditor/button.html | 5 +- .../gui/ang/afGuiEditor/editOptions.html | 30 ++++ ext/afform/gui/ang/afGuiEditor/field.html | 110 +++++++------ .../ang/afGuiEditor/inputType/CheckBox.html | 7 + .../gui/ang/afGuiEditor/inputType/Date.html | 5 + .../gui/ang/afGuiEditor/inputType/Number.html | 1 + .../gui/ang/afGuiEditor/inputType/Radio.html | 6 + .../afGuiEditor/inputType/RichTextEditor.html | 1 + .../gui/ang/afGuiEditor/inputType/Select.html | 1 + .../gui/ang/afGuiEditor/inputType/Text.html | 1 + .../ang/afGuiEditor/inputType/TextArea.html | 1 + ext/afform/gui/ang/afGuiEditor/text.html | 5 +- .../gui/ang/afGuiEditor/widgets/CheckBox.html | 7 - .../gui/ang/afGuiEditor/widgets/Date.html | 5 - .../gui/ang/afGuiEditor/widgets/Number.html | 1 - .../gui/ang/afGuiEditor/widgets/Radio.html | 4 - .../afGuiEditor/widgets/RichTextEditor.html | 1 - .../gui/ang/afGuiEditor/widgets/Select.html | 1 - .../gui/ang/afGuiEditor/widgets/Text.html | 1 - .../gui/ang/afGuiEditor/widgets/TextArea.html | 1 - ext/afform/mock/ang/testAfform.aff.html | 2 +- 30 files changed, 383 insertions(+), 116 deletions(-) create mode 100644 ext/afform/gui/ang/afGuiEditor/editOptions.html create mode 100644 ext/afform/gui/ang/afGuiEditor/inputType/CheckBox.html create mode 100644 ext/afform/gui/ang/afGuiEditor/inputType/Date.html create mode 100644 ext/afform/gui/ang/afGuiEditor/inputType/Number.html create mode 100644 ext/afform/gui/ang/afGuiEditor/inputType/Radio.html create mode 100644 ext/afform/gui/ang/afGuiEditor/inputType/RichTextEditor.html create mode 100644 ext/afform/gui/ang/afGuiEditor/inputType/Select.html create mode 100644 ext/afform/gui/ang/afGuiEditor/inputType/Text.html create mode 100644 ext/afform/gui/ang/afGuiEditor/inputType/TextArea.html delete mode 100644 ext/afform/gui/ang/afGuiEditor/widgets/CheckBox.html delete mode 100644 ext/afform/gui/ang/afGuiEditor/widgets/Date.html delete mode 100644 ext/afform/gui/ang/afGuiEditor/widgets/Number.html delete mode 100644 ext/afform/gui/ang/afGuiEditor/widgets/Radio.html delete mode 100644 ext/afform/gui/ang/afGuiEditor/widgets/RichTextEditor.html delete mode 100644 ext/afform/gui/ang/afGuiEditor/widgets/Select.html delete mode 100644 ext/afform/gui/ang/afGuiEditor/widgets/Text.html delete mode 100644 ext/afform/gui/ang/afGuiEditor/widgets/TextArea.html diff --git a/ext/afform/core/afform.php b/ext/afform/core/afform.php index 20fe6b1e77..a2eebb33ee 100644 --- a/ext/afform/core/afform.php +++ b/ext/afform/core/afform.php @@ -329,6 +329,11 @@ function afform_civicrm_alterAngular($angular) { // If it's not an object, don't mess with it. continue; } + // TODO: Teach the api to return options in this format + if (!empty($fieldInfo['options'])) { + $fieldInfo['options'] = CRM_Utils_Array::makeNonAssociative($fieldInfo['options'], 'key', 'label'); + } + $fieldDefn = $existingFieldDefn ? CRM_Utils_JS::getRawProps($existingFieldDefn) : []; foreach ($fieldInfo as $name => $prop) { // Merge array props 1 level deep diff --git a/ext/afform/core/ang/afField/afField.js b/ext/afform/core/ang/afField/afField.js index bd30e103d8..f600417323 100644 --- a/ext/afform/core/ang/afField/afField.js +++ b/ext/afform/core/ang/afField/afField.js @@ -16,15 +16,21 @@ $scope.fieldId = $scope.afFieldset.getDefn().modelName + '-' + $scope.fieldName; $scope.getData = $scope.afFieldset.getData; + $el.addClass('af-field-type-' + _.kebabCase($scope.defn.input_type)); + }, + controller: function($scope) { + $scope.getOptions = function() { + return $scope.defn.options || [{key: '1', label: ts('Yes')}, {key: '0', label: ts('No')}]; + }; + + $scope.select2Options = function() { return { - results: _.transform($scope.defn.options, function(result, val, key) { - result.push({id: key, text: val}); + results: _.transform($scope.getOptions(), function(result, opt) { + result.push({id: opt.key, text: opt.label}); }, []) }; }; - - $el.addClass('af-field-type-' + _.kebabCase($scope.defn.input_type)); } }; }); diff --git a/ext/afform/core/ang/afField/widgets/CheckBox.html b/ext/afform/core/ang/afField/widgets/CheckBox.html index bf0bd8bb9e..fbdab6b0b2 100644 --- a/ext/afform/core/ang/afField/widgets/CheckBox.html +++ b/ext/afform/core/ang/afField/widgets/CheckBox.html @@ -1,7 +1,7 @@ - + diff --git a/ext/afform/core/ang/afField/widgets/Radio.html b/ext/afform/core/ang/afField/widgets/Radio.html index c20d3daf03..f914f64c43 100644 --- a/ext/afform/core/ang/afField/widgets/Radio.html +++ b/ext/afform/core/ang/afField/widgets/Radio.html @@ -1,4 +1,4 @@ -