From: Coleman Watts Date: Mon, 5 Apr 2021 20:40:17 +0000 (-0400) Subject: Afform - Set defaults for search filter fields X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=d4e2c9ff19adf919997b6af47ae36a842c8dbf06;p=civicrm-core.git Afform - Set defaults for search filter fields --- diff --git a/ext/afform/admin/ang/afGuiEditor/afGuiEditor.component.js b/ext/afform/admin/ang/afGuiEditor/afGuiEditor.component.js index 17b9be23b0..d1913cbf0b 100644 --- a/ext/afform/admin/ang/afGuiEditor/afGuiEditor.component.js +++ b/ext/afform/admin/ang/afGuiEditor/afGuiEditor.component.js @@ -52,7 +52,7 @@ editor.layout = {'#children': []}; $scope.entities = {}; - if ($scope.afform.type === 'form') { + if (editor.getFormType() === 'form') { editor.allowEntityConfig = true; editor.layout['#children'] = afGui.findRecursive($scope.afform.layout, {'#tag': 'af-form'})[0]['#children']; $scope.entities = _.mapValues(afGui.findRecursive(editor.layout['#children'], {'#tag': 'af-entity'}, 'name'), backfillEntityDefaults); @@ -63,7 +63,7 @@ } } - if ($scope.afform.type === 'block') { + else if (editor.getFormType() === 'block') { editor.layout['#children'] = $scope.afform.layout; editor.blockEntity = $scope.afform.join || $scope.afform.block; $scope.entities[editor.blockEntity] = backfillEntityDefaults({ @@ -73,9 +73,8 @@ }); } - if ($scope.afform.type === 'search') { + else if (editor.getFormType() === 'search') { editor.layout['#children'] = afGui.findRecursive($scope.afform.layout, {'af-fieldset': ''})[0]['#children']; - } // Set changesSaved to true on initial load, false thereafter whenever changes are made to the model @@ -85,6 +84,10 @@ }, true); } + this.getFormType = function() { + return $scope.afform.type; + }; + $scope.updateLayoutHtml = function() { $scope.layoutHtml = '...Loading...'; crmApi4('Afform', 'convert', {layout: $scope.afform.layout, from: 'deep', to: 'html', formatWhitespace: true}) diff --git a/ext/afform/admin/ang/afGuiEditor/afGuiEntity.component.js b/ext/afform/admin/ang/afGuiEditor/afGuiEntity.component.js index 818d4d825c..721c41ec6e 100644 --- a/ext/afform/admin/ang/afGuiEditor/afGuiEntity.component.js +++ b/ext/afform/admin/ang/afGuiEditor/afGuiEntity.component.js @@ -54,7 +54,7 @@ label: ts('%1 Fields', {1: $scope.getMeta().label}), fields: filterFields($scope.getMeta().fields) }); - + // Add fields for af-join blocks _.each(afGui.meta.entities, function(entity, entityName) { if (check(ctrl.editor.layout['#children'], {'af-join': entityName})) { $scope.fieldList.push({ @@ -69,13 +69,18 @@ function filterFields(fields) { return _.transform(fields, function(fieldList, field) { if (!search || _.contains(field.name, search) || _.contains(field.label.toLowerCase(), search)) { - fieldList.push({ - "#tag": "af-field", - name: field.name - }); + fieldList.push(fieldDefaults(field)); } }, []); } + + function fieldDefaults(field) { + var tag = { + "#tag": "af-field", + name: field.name + }; + return tag; + } } function buildBlockList(search) { diff --git a/ext/afform/admin/ang/afGuiEditor/afGuiSearch.component.js b/ext/afform/admin/ang/afGuiEditor/afGuiSearch.component.js index 46c9486c00..ed1a98f73a 100644 --- a/ext/afform/admin/ang/afGuiEditor/afGuiSearch.component.js +++ b/ext/afform/admin/ang/afGuiEditor/afGuiSearch.component.js @@ -76,13 +76,25 @@ function filterFields(fields, prefix) { return _.transform(fields, function(fieldList, field) { if (!search || _.contains(field.name, search) || _.contains(field.label.toLowerCase(), search)) { - fieldList.push({ - "#tag": "af-field", - name: (prefix ? prefix + '.' : '') + field.name - }); + fieldList.push(fieldDefaults(field, prefix)); } }, []); } + + function fieldDefaults(field, prefix) { + var tag = { + "#tag": "af-field", + name: (prefix ? prefix + '.' : '') + field.name + }; + if (field.input_type === 'Select') { + tag.defn = {input_attrs: {multiple: true}}; + } else if (field.input_type === 'Date') { + tag.defn = {input_type: 'Select', search_range: true}; + } else if (field.options) { + tag.defn = {input_type: 'Select', input_attrs: {multiple: true}}; + } + return tag; + } } function buildElementList(search) { diff --git a/ext/afform/admin/ang/afGuiEditor/elements/afGuiField.component.js b/ext/afform/admin/ang/afGuiEditor/elements/afGuiField.component.js index cecb660b0d..b9f5aa8eb5 100644 --- a/ext/afform/admin/ang/afGuiEditor/elements/afGuiField.component.js +++ b/ext/afform/admin/ang/afGuiEditor/elements/afGuiField.component.js @@ -33,7 +33,7 @@ }; this.isSearch = function() { - return !_.isEmpty($scope.meta.searchDisplays); + return ctrl.editor.getFormType() === 'search'; }; this.canBeRange = function() {