From 1bc66ce823e2af176598192374d3a9d3a5fa2fd8 Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Mon, 10 Oct 2022 14:54:12 +0100 Subject: [PATCH] SearchKit - Process tokens in the "Add new" button Allows an "Add new" button on drilldown searches. --- .../ang/afsearchAdminCustomFields.aff.html | 12 --------- ...vedSearch_Administer_Custom_Fields.mgd.php | 5 ++++ .../ang/crmSearchDisplay/AddButton.html | 6 ++--- .../traits/searchDisplayBaseTrait.service.js | 25 +++++++++++-------- .../crmSearchDisplayGrid.html | 2 +- .../crmSearchDisplayList.html | 2 +- .../crmSearchDisplayTable.html | 2 +- 7 files changed, 26 insertions(+), 28 deletions(-) diff --git a/ext/civicrm_admin_ui/ang/afsearchAdminCustomFields.aff.html b/ext/civicrm_admin_ui/ang/afsearchAdminCustomFields.aff.html index 9a5c68b032..d34a79642c 100644 --- a/ext/civicrm_admin_ui/ang/afsearchAdminCustomFields.aff.html +++ b/ext/civicrm_admin_ui/ang/afsearchAdminCustomFields.aff.html @@ -1,15 +1,3 @@
-
diff --git a/ext/civicrm_admin_ui/managed/SavedSearch_Administer_Custom_Fields.mgd.php b/ext/civicrm_admin_ui/managed/SavedSearch_Administer_Custom_Fields.mgd.php index 652498e75b..2d90956ce4 100644 --- a/ext/civicrm_admin_ui/managed/SavedSearch_Administer_Custom_Fields.mgd.php +++ b/ext/civicrm_admin_ui/managed/SavedSearch_Administer_Custom_Fields.mgd.php @@ -193,6 +193,11 @@ return [ FALSE, ], ], + 'addButton' => [ + 'path' => 'civicrm/admin/custom/group/field/add?reset=1&action=add&gid=[custom_group_id]', + 'text' => E::ts('Add Custom Field'), + 'icon' => 'fa-plus', + ], ], 'acl_bypass' => FALSE, ], diff --git a/ext/search_kit/ang/crmSearchDisplay/AddButton.html b/ext/search_kit/ang/crmSearchDisplay/AddButton.html index 93135230da..0c779885f6 100644 --- a/ext/search_kit/ang/crmSearchDisplay/AddButton.html +++ b/ext/search_kit/ang/crmSearchDisplay/AddButton.html @@ -1,4 +1,4 @@ - - - {{:: $ctrl.addButton.text }} + + + {{:: $ctrl.settings.addButton.text }} diff --git a/ext/search_kit/ang/crmSearchDisplay/traits/searchDisplayBaseTrait.service.js b/ext/search_kit/ang/crmSearchDisplay/traits/searchDisplayBaseTrait.service.js index e9b5bf051e..3146e9bf98 100644 --- a/ext/search_kit/ang/crmSearchDisplay/traits/searchDisplayBaseTrait.service.js +++ b/ext/search_kit/ang/crmSearchDisplay/traits/searchDisplayBaseTrait.service.js @@ -26,15 +26,6 @@ for (var p=0; p < placeholderCount; ++p) { this.placeholders.push({}); } - // Calculate URL of addButton and copy addButton to controller property - // It has to be copied rather than simply adding this.settings.addButton.url, - // because settings cannot be changed when they are supplied from the markup - if (this.settings.addButton && this.settings.addButton.path) { - // Clone the variable to prevent polluting it during Preview mode in the Admin UI - this.addButton = _.cloneDeep(this.settings.addButton); - // TODO: Evaluate variables in the path - this.addButton.url = CRM.url(this.addButton.path); - } this.getResults = _.debounce(function() { $scope.$apply(function() { @@ -103,6 +94,10 @@ return this.settings.actions || this.settings.draggable || (this.settings.tally && this.settings.tally.label); }, + getFilters: function() { + return _.assign({}, this.getAfformFilters(), this.filters); + }, + getAfformFilters: function() { return _.pick(this.afFieldset ? this.afFieldset.getFieldData() : {}, function(val) { return val !== null && (_.includes(['boolean', 'number', 'object'], typeof val) || val.length); @@ -118,11 +113,21 @@ sort: this.sort, limit: this.limit, seed: this.seed, - filters: _.assign({}, this.getAfformFilters(), this.filters), + filters: this.getFilters(), afform: this.afFieldset ? this.afFieldset.getFormName() : null }; }, + // Get path for the addButton + getButtonUrl: function() { + var path = this.settings.addButton.path, + filters = this.getFilters(); + _.each(filters, function(value, key) { + path = path.replace('[' + key + ']', value); + }); + return CRM.url(path); + }, + onClickSearchButton: function() { this.rowCount = null; this.page = 1; diff --git a/ext/search_kit/ang/crmSearchDisplayGrid/crmSearchDisplayGrid.html b/ext/search_kit/ang/crmSearchDisplayGrid/crmSearchDisplayGrid.html index 7722006a24..5e34daf997 100644 --- a/ext/search_kit/ang/crmSearchDisplayGrid/crmSearchDisplayGrid.html +++ b/ext/search_kit/ang/crmSearchDisplayGrid/crmSearchDisplayGrid.html @@ -1,7 +1,7 @@
-
+
-
+
      diff --git a/ext/search_kit/ang/crmSearchDisplayTable/crmSearchDisplayTable.html b/ext/search_kit/ang/crmSearchDisplayTable/crmSearchDisplayTable.html index 285c3f1b45..73e4104970 100644 --- a/ext/search_kit/ang/crmSearchDisplayTable/crmSearchDisplayTable.html +++ b/ext/search_kit/ang/crmSearchDisplayTable/crmSearchDisplayTable.html @@ -2,7 +2,7 @@
      -
      +
      -- 2.25.1