SearchKit - Allow html in columns
authorColeman Watts <coleman@civicrm.org>
Tue, 19 Jul 2022 17:21:15 +0000 (13:21 -0400)
committerColeman Watts <coleman@civicrm.org>
Tue, 19 Jul 2022 17:24:30 +0000 (13:24 -0400)
This adds a column type 'html' and defaults rich-text fields to use that column type.
Fixes dev/core#3723

ext/search_kit/Civi/Api4/Action/SearchDisplay/AbstractRunAction.php
ext/search_kit/ang/crmSearchAdmin.module.js
ext/search_kit/ang/crmSearchAdmin/crmSearchAdminDisplay.component.js
ext/search_kit/ang/crmSearchAdmin/displays/colType/field.html
ext/search_kit/ang/crmSearchAdmin/displays/colType/html.html [new file with mode: 0644]
ext/search_kit/ang/crmSearchDisplay/colType/html.html [new file with mode: 0644]

index 59c209f8181369f22c23343df5d3109e11bb66b8..5df9ef6d1ef64c63283eae3a04f6ebf4d9c189a5 100644 (file)
@@ -206,6 +206,7 @@ abstract class AbstractRunAction extends \Civi\Api4\Generic\AbstractAction {
     $out = [];
     switch ($column['type']) {
       case 'field':
+      case 'html':
         $rawValue = $data[$column['key']] ?? NULL;
         if (!$this->hasValue($rawValue) && isset($column['empty_value'])) {
           $out['val'] = $this->replaceTokens($column['empty_value'], $data, 'view');
@@ -231,6 +232,12 @@ abstract class AbstractRunAction extends \Civi\Api4\Generic\AbstractAction {
             $out['edit'] = $edit;
           }
         }
+        if ($column['type'] === 'html') {
+          if (is_array($out['val'])) {
+            $out['val'] = implode(', ', $out['val']);
+          }
+          $out['val'] = \CRM_Utils_String::purifyHTML($out['val']);
+        }
         break;
 
       case 'image':
index ddd9bc3350a1053a0d473f35d7bbea0f1e88f9e7..729be45d6426dfe0a42170ac6ac1dd267b912f1c 100644 (file)
         var info = parseExpr(fieldExpr),
           field = (_.findWhere(info.args, {type: 'field'}) || {}).field || {},
           values = _.merge({
-            type: 'field',
+            type: field.input_type === 'RichTextEditor' ? 'html' : 'field',
             key: info.alias,
             dataType: (info.fn && info.fn.data_type) || field.data_type
           }, defaults);
index 5956e2b3b64800446ac1000635ad3f25ffe4f809..88ce9ce15535656244f2684e88183c63640d7789 100644 (file)
       };
 
       this.getColLabel = function(col) {
-        if (col.type === 'field' || col.type === 'image') {
+        if (col.type === 'field' || col.type === 'image' || col.type === 'html') {
           return ctrl.getFieldLabel(col.key);
         }
         return ctrl.colTypes[col.type].label;
         }
       };
 
+      this.toggleHtml = function(col) {
+        if (col.type === 'html') {
+          col.type = 'field';
+        } else {
+          delete col.editable;
+          delete col.link;
+          delete col.icons;
+          col.type = 'html';
+        }
+      };
+
       this.canBeImage = function(col) {
         var expr = ctrl.getExprFromSelect(col.key),
           info = searchMeta.parseExpr(expr);
index e4337785976e089da70f74fd6edf847aebcc9fda..631a76d3e9d1db1cbed25a5dd0be6c3cf45990bb 100644 (file)
@@ -4,6 +4,12 @@
     {{:: ts('Image') }}
   </label>
 </div>
+<div class="form-inline" ng-if=":: !$ctrl.parent.canBeImage(col)">
+  <label>
+    <input type="checkbox" ng-click="$ctrl.parent.toggleHtml(col)" >
+    {{:: ts('Allow HTML') }}
+  </label>
+</div>
 <div class="form-inline crm-search-admin-flex-row" >
   <label title="{{:: ts('Display as clickable link') }}" >
     <input type="checkbox" ng-checked="col.link" ng-click="$ctrl.parent.toggleLink(col)" >
@@ -36,7 +42,7 @@
 <div class="form-inline crm-search-admin-flex-row">
   <label title="{{:: ts('Change the contents of this field, or combine multiple field values.') }}">
     <input type="checkbox" ng-checked="col.rewrite" ng-click="$ctrl.parent.toggleRewrite(col)" >
-    {{:: ts('Rewrite') }}
+    {{:: ts('Rewrite Text') }}
   </label>
   <input type="text" class="form-control crm-flex-1" ng-if="col.rewrite" ng-model="col.rewrite" ng-model-options="{updateOn: 'blur'}">
   <crm-search-admin-token-select ng-if="col.rewrite" model="col" field="rewrite" suffix=":label"></crm-search-admin-token-select>
diff --git a/ext/search_kit/ang/crmSearchAdmin/displays/colType/html.html b/ext/search_kit/ang/crmSearchAdmin/displays/colType/html.html
new file mode 100644 (file)
index 0000000..6315986
--- /dev/null
@@ -0,0 +1,31 @@
+<div class="form-inline">
+  <label>
+    <input type="checkbox" checked ng-click="$ctrl.parent.toggleHtml(col)" >
+    {{:: ts('Allow HTML') }}
+  </label>
+</div>
+<div class="form-inline crm-search-admin-flex-row">
+  <label>
+    <input type="checkbox" ng-checked="col.title" ng-click="col.title = col.title ? null : $ctrl.parent.getFieldLabel(col.key)" >
+    {{:: ts('Tooltip') }}
+  </label>
+  <input class="form-control crm-flex-1" type="text" ng-model="col.title" ng-if="col.title" ng-model-options="{updateOn: 'blur'}" />
+  <crm-search-admin-token-select ng-if="col.title" model="col" field="title" suffix=":label"></crm-search-admin-token-select>
+</div>
+<div class="form-inline crm-search-admin-flex-row">
+  <label title="{{:: ts('HTML to display if the field contents are empty.') }}">
+    <input type="checkbox" ng-checked="col.empty_value" ng-click="$ctrl.parent.toggleEmptyVal(col)" >
+    {{:: ts('Empty placeholder') }}
+  </label>
+  <input type="text" class="form-control crm-flex-1" ng-if="col.empty_value" ng-model="col.empty_value" ng-model-options="{updateOn: 'blur'}">
+  <crm-search-admin-token-select ng-if="col.empty_value" model="col" field="empty_value" suffix=":label"></crm-search-admin-token-select>
+</div>
+<div class="form-inline crm-search-admin-flex-row">
+  <label title="{{:: ts('Change the contents of this field, or combine multiple field values.') }}">
+    <input type="checkbox" ng-checked="col.rewrite" ng-click="$ctrl.parent.toggleRewrite(col)" >
+    {{:: ts('Rewrite HTML') }}
+  </label>
+  <input type="text" class="form-control crm-flex-1" ng-if="col.rewrite" ng-model="col.rewrite" ng-model-options="{updateOn: 'blur'}">
+  <crm-search-admin-token-select ng-if="col.rewrite" model="col" field="rewrite" suffix=":label"></crm-search-admin-token-select>
+</div>
+<search-admin-css-rules label="{{:: ts('Style') }}" item="col" default="col.key"></search-admin-css-rules>
diff --git a/ext/search_kit/ang/crmSearchDisplay/colType/html.html b/ext/search_kit/ang/crmSearchDisplay/colType/html.html
new file mode 100644 (file)
index 0000000..1b79b5e
--- /dev/null
@@ -0,0 +1,2 @@
+<span ng-bind-html="colData.val">
+</span>