From e35ea0352d7fac0bdc523b9af499f78d04329f94 Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Thu, 29 Oct 2020 16:58:29 -0400 Subject: [PATCH] Search ext: Add option to format table cell as link in search display --- .../searchAdminDisplayTable.component.js | 8 ++++-- .../displays/searchAdminDisplayTable.html | 10 ++++--- ext/search/ang/crmSearchDisplay.ang.php | 2 +- .../crmSearchDisplayTable.component.js | 26 ++++++++++++++----- .../crmSearchDisplayTable.html | 3 +-- 5 files changed, 34 insertions(+), 15 deletions(-) diff --git a/ext/search/ang/crmSearchAdmin/displays/searchAdminDisplayTable.component.js b/ext/search/ang/crmSearchAdmin/displays/searchAdminDisplayTable.component.js index 871d5f7805..706366cc11 100644 --- a/ext/search/ang/crmSearchAdmin/displays/searchAdminDisplayTable.component.js +++ b/ext/search/ang/crmSearchAdmin/displays/searchAdminDisplayTable.component.js @@ -25,8 +25,8 @@ } this.sortableOptions = { - connectWith: '.crm-search-admin-table-columns', - containment: '.crm-search-admin-table-columns-wrapper' + connectWith: '.crm-search-admin-edit-columns', + containment: '.crm-search-admin-edit-columns-wrapper' }; this.removeCol = function(index) { @@ -39,6 +39,10 @@ ctrl.hiddenColumns.splice(index, 1); }; + this.toggleLink = function(col) { + col.link = col.link ? '' : (window.location.pathname + window.location.search).replace('civicrm/admin/search', 'civicrm/'); + }; + this.$onInit = function () { ctrl.getFieldLabel = ctrl.crmSearchAdmin.getFieldLabel; if (!ctrl.display.settings.columns) { diff --git a/ext/search/ang/crmSearchAdmin/displays/searchAdminDisplayTable.html b/ext/search/ang/crmSearchAdmin/displays/searchAdminDisplayTable.html index e65c0b6ba0..3777818fce 100644 --- a/ext/search/ang/crmSearchAdmin/displays/searchAdminDisplayTable.html +++ b/ext/search/ang/crmSearchAdmin/displays/searchAdminDisplayTable.html @@ -6,8 +6,8 @@ -
-
+
+
{{:: ts('Columns') }}
{{ $ctrl.getFieldLabel(col.expr) }} @@ -17,9 +17,13 @@
+
+ + +
-
+
{{:: ts('Hidden Columns') }}
{{ $ctrl.getFieldLabel(col.expr) }} diff --git a/ext/search/ang/crmSearchDisplay.ang.php b/ext/search/ang/crmSearchDisplay.ang.php index 31d98189de..84d0b762b0 100644 --- a/ext/search/ang/crmSearchDisplay.ang.php +++ b/ext/search/ang/crmSearchDisplay.ang.php @@ -10,7 +10,7 @@ return [ 'ang/crmSearchDisplay', ], 'basePages' => [], - 'requires' => ['crmUi', 'api4', 'crmSearchActions', 'ui.bootstrap'], + 'requires' => ['ngSanitize', 'crmUi', 'api4', 'crmSearchActions', 'ui.bootstrap'], 'exports' => [ 'crm-search-display-table' => 'E', ], diff --git a/ext/search/ang/crmSearchDisplay/crmSearchDisplayTable.component.js b/ext/search/ang/crmSearchDisplay/crmSearchDisplayTable.component.js index 09fa60a56f..6e190bb755 100644 --- a/ext/search/ang/crmSearchDisplay/crmSearchDisplayTable.component.js +++ b/ext/search/ang/crmSearchDisplay/crmSearchDisplayTable.component.js @@ -81,26 +81,38 @@ $scope.formatResult = function(row, col) { var value = row[col.key]; - return formatFieldValue(col, value); + return formatFieldValue(row, col, value); }; - function formatFieldValue(col, value) { - var type = col.dataType; + function formatFieldValue(row, col, value) { + var type = col.dataType, + result = value; if (_.isArray(value)) { return _.map(value, function(val) { return formatFieldValue(col, val); }).join(', '); } if (value && (type === 'Date' || type === 'Timestamp') && /^\d{4}-\d{2}-\d{2}/.test(value)) { - return CRM.utils.formatDate(value, null, type === 'Timestamp'); + result = CRM.utils.formatDate(value, null, type === 'Timestamp'); } else if (type === 'Boolean' && typeof value === 'boolean') { - return value ? ts('Yes') : ts('No'); + result = value ? ts('Yes') : ts('No'); } else if (type === 'Money' && typeof value === 'number') { - return CRM.formatMoney(value); + result = CRM.formatMoney(value); } - return value; + result = _.escape(result); + if (col.link) { + result = '' + result + ''; + } + return result; + } + + function replaceTokens(str, data) { + _.each(data, function(value, key) { + str = str.replace('[' + key + ']', value); + }); + return str; } $scope.selectAllRows = function() { diff --git a/ext/search/ang/crmSearchDisplay/crmSearchDisplayTable.html b/ext/search/ang/crmSearchDisplay/crmSearchDisplayTable.html index cf006e89df..e49fd6742f 100644 --- a/ext/search/ang/crmSearchDisplay/crmSearchDisplayTable.html +++ b/ext/search/ang/crmSearchDisplay/crmSearchDisplayTable.html @@ -18,8 +18,7 @@ - - {{ formatResult(row, col) }} + -- 2.25.1