Afform - Set defaults for search filter fields
authorColeman Watts <coleman@civicrm.org>
Mon, 5 Apr 2021 20:40:17 +0000 (16:40 -0400)
committerColeman Watts <coleman@civicrm.org>
Mon, 5 Apr 2021 20:40:17 +0000 (16:40 -0400)
ext/afform/admin/ang/afGuiEditor/afGuiEditor.component.js
ext/afform/admin/ang/afGuiEditor/afGuiEntity.component.js
ext/afform/admin/ang/afGuiEditor/afGuiSearch.component.js
ext/afform/admin/ang/afGuiEditor/elements/afGuiField.component.js

index 17b9be23b0d6fac11412e7c2b8bb1ae1db668386..d1913cbf0b6ef01238cd6fd389c195cb0e6fcac3 100644 (file)
@@ -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
         }, 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})
index 818d4d825cd3b77b5b69ad2dc88b429d675cdcca..721c41ec6ea4641c287d5612f46f02a7c347e789 100644 (file)
@@ -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({
         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) {
index 46c9486c004791ef41a771fcf5997043e2778acc..ed1a98f73ad0716eaac7dec855ddce9aea39d0f4 100644 (file)
         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) {
index cecb660b0d49f91ce81750f621af829139b13c02..b9f5aa8eb55e73590894c1a32d6f0d6963b2670e 100644 (file)
@@ -33,7 +33,7 @@
       };
 
       this.isSearch = function() {
-        return !_.isEmpty($scope.meta.searchDisplays);
+        return ctrl.editor.getFormType() === 'search';
       };
 
       this.canBeRange = function() {