Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SearchKit - Allow html in columns #24023

Merged
merged 1 commit into from
Jul 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ private function formatColumn($column, $data) {
$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');
Expand All @@ -231,6 +232,12 @@ private function formatColumn($column, $data) {
$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':
Expand Down
2 changes: 1 addition & 1 deletion ext/search_kit/ang/crmSearchAdmin.module.js
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@
};

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;
Expand Down Expand Up @@ -162,6 +162,17 @@
}
};

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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)" >
Expand Down Expand Up @@ -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>
Expand Down
31 changes: 31 additions & 0 deletions ext/search_kit/ang/crmSearchAdmin/displays/colType/html.html
Original file line number Diff line number Diff line change
@@ -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>
2 changes: 2 additions & 0 deletions ext/search_kit/ang/crmSearchDisplay/colType/html.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<span ng-bind-html="colData.val">
</span>