GUI - Add block fields to field palette
authorColeman Watts <coleman@civicrm.org>
Fri, 3 Jan 2020 20:40:39 +0000 (15:40 -0500)
committerCiviCRM <info@civicrm.org>
Wed, 16 Sep 2020 02:13:20 +0000 (19:13 -0700)
ext/afform/gui/ang/afGuiEditor.css
ext/afform/gui/ang/afGuiEditor.js
ext/afform/gui/ang/afGuiEditor/entity.html

index bfa548f3498cca20fb5798f5a8e5fbc641395e80..3399f74cd0bed4e7d7dbf966b87ee90d3b932698 100644 (file)
   margin-bottom: 5px !important;
 }
 
+#afGuiEditor-palette fieldset legend {
+  height: 30px;
+}
+
 #afGuiEditor hr {
   margin-top: 15px;
   margin-bottom: 10px;
@@ -79,7 +83,7 @@
 #afGuiEditor-palette-config .af-gui-entity-palette [type=search] {
   width: 120px;
   padding: 3px 3px 3px 5px;
-  height: 22px;
+  height: 25px;
   font-weight: normal;
   position: relative;
   top: -3px;
index 1a2655227d3b5e9d9382a747b61d7c83a9350690..609de11e2f71ded7947ec83d50759be8a5f67449 100644 (file)
         $scope.elementList = [];
         $scope.elementTitles = [];
 
+        function getEntityType() {
+          return $scope.entity.type === 'Contact' ? $scope.entity.data.contact_type : $scope.entity.type;
+        }
+
         $scope.getMeta = function() {
-          var type = $scope.entity.type === 'Contact' ? $scope.entity.data.contact_type : $scope.entity.type;
-          return $scope.editor ? $scope.editor.meta.entities[type] : {};
+          return $scope.editor ? $scope.editor.meta.entities[getEntityType()] : {};
         };
 
         $scope.valuesFields = function() {
 
         function buildFieldList(search) {
           $scope.fieldList.length = 0;
-          _.each($scope.getMeta().fields, function(field) {
-            if (!search || _.contains(field.name, search) || _.contains(field.title.toLowerCase(), search)) {
+          $scope.fieldList.push({
+            entityName: $scope.entity.name,
+            entityType: getEntityType(),
+            label: ts('%1 Fields', {1: $scope.getMeta().label}),
+            fields: filterFields($scope.getMeta().fields)
+          });
+
+          _.each($scope.editor.meta.entities, function(entity, entityName) {
+            if (check($scope.editor.scope.layout['#children'], {'af-join': entityName})) {
               $scope.fieldList.push({
-                "#tag": "af-field",
-                name: field.name
+                entityName: $scope.entity.name + '-join-' + entityName,
+                entityType: entityName,
+                label: ts('%1 Fields', {1: entity.label}),
+                fields: filterFields(entity.fields)
               });
             }
           });
+
+          function filterFields(fields) {
+            return _.transform(fields, function(fieldList, field) {
+              if (!search || _.contains(field.name, search) || _.contains(field.title.toLowerCase(), search)) {
+                fieldList.push({
+                  "#tag": "af-field",
+                  name: field.name
+                });
+              }
+            }, []);
+          }
         }
 
         function buildBlockList(search) {
index e89dfc220dd7909ee4643ee5ba0ddb53bcae83ff..a6c9b26aa83cc3a04afff9bc778abe4000fc6f7a 100644 (file)
           </div>
         </div>
       </div>
-      <div ng-if="fieldList.length">
-        <label>{{ ts('Fields') }}</label>
-        <div ui-sortable="{update: buildPaletteLists, items: '&gt; div:not(.disabled)', connectWith: '[data-entity=' + entity.name + '] &gt; [ui-sortable]'}" ng-model="fieldList">
-          <div ng-repeat="field in fieldList" ng-class="{disabled: fieldInUse(field.name)}">
-            {{ editor.getField(entity.type, field.name).title }}
+      <div ng-repeat="fieldGroup in fieldList">
+        <div ng-if="fieldGroup.fields.length">
+          <label>{{ fieldGroup.label }}</label>
+          <div ui-sortable="{update: buildPaletteLists, items: '&gt; div:not(.disabled)', connectWith: '[data-entity=' + fieldGroup.entityName + '] &gt; [ui-sortable]'}" ng-model="fieldGroup.fields">
+            <div ng-repeat="field in fieldGroup.fields" ng-class="{disabled: fieldInUse(field.name)}">
+              {{ editor.getField(fieldGroup.entityType, field.name).title }}
+            </div>
           </div>
         </div>
       </div>