SearchKit - Process tokens in the "Add new" button
authorColeman Watts <coleman@civicrm.org>
Mon, 10 Oct 2022 13:54:12 +0000 (14:54 +0100)
committerColeman Watts <coleman@civicrm.org>
Mon, 10 Oct 2022 14:02:11 +0000 (15:02 +0100)
Allows an "Add new" button on drilldown searches.

ext/civicrm_admin_ui/ang/afsearchAdminCustomFields.aff.html
ext/civicrm_admin_ui/managed/SavedSearch_Administer_Custom_Fields.mgd.php
ext/search_kit/ang/crmSearchDisplay/AddButton.html
ext/search_kit/ang/crmSearchDisplay/traits/searchDisplayBaseTrait.service.js
ext/search_kit/ang/crmSearchDisplayGrid/crmSearchDisplayGrid.html
ext/search_kit/ang/crmSearchDisplayList/crmSearchDisplayList.html
ext/search_kit/ang/crmSearchDisplayTable/crmSearchDisplayTable.html

index 9a5c68b03239d6c7ae279684ebbef38dc989caba..d34a79642ca092635d2453371748bcbbcb1196d2 100644 (file)
@@ -1,15 +1,3 @@
 <div af-fieldset="">
-  <div class="af-markup">
-    <div class="form-inline">
-      <a class="btn btn-primary" target="crm-popup" ng-href="{{ crmUrl('civicrm/admin/custom/group/field/add', {gid: routeParams.gid, reset: 1}) }}">
-        <i class="crm-i fa-plus-circle"></i>
-        {{:: ts('Add Field') }}
-      </a>
-      <a class="btn btn-secondary" ng-href="{{ crmUrl('civicrm/admin/custom/group') }}">
-        <i class="crm-i fa-times"></i>
-        {{:: ts('Done') }}
-      </a>
-    </div>
-  </div>
   <crm-search-display-table search-name="Administer_Custom_Fields" display-name="Table" filters="{custom_group_id: routeParams.gid}"></crm-search-display-table>
 </div>
index 652498e75b02bad7006c40ff8c353b84b391f097..2d90956ce420ee4f4f74f41c36b7c3699e1ea859 100644 (file)
@@ -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,
       ],
index 93135230dab2cc7ff8de9c9b4f1dddea45b3c26c..0c779885f6fe8e09181416d00b135b40d9692257 100644 (file)
@@ -1,4 +1,4 @@
-<a ng-href="{{ $ctrl.addButton.url }}" class="btn btn-primary" target="crm-popup">
-  <i ng-if="$ctrl.addButton.icon" class="crm-i {{:: $ctrl.addButton.icon }}"></i>
-  {{:: $ctrl.addButton.text }}
+<a ng-href="{{ $ctrl.getButtonUrl() }}" class="btn btn-primary" target="crm-popup">
+  <i ng-if="$ctrl.settings.addButton.icon" class="crm-i {{:: $ctrl.settings.addButton.icon }}"></i>
+  {{:: $ctrl.settings.addButton.text }}
 </a>
index e9b5bf051e39a40b54e9d572507bb717237a1280..3146e9bf9804fa5f65d1ec3c151014df4548b1fd 100644 (file)
         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() {
         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);
           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;
index 7722006a24118bbd87e271fcc694fa4e5ab39056..5e34daf997dfda01534c9a15b08b24b792cf6431 100644 (file)
@@ -1,7 +1,7 @@
 <div class="crm-search-display crm-search-display-grid">
   <div class="form-inline">
     <div class="btn-group" ng-include="'~/crmSearchDisplay/SearchButton.html'" ng-if="$ctrl.settings.button"></div>
-    <div class="btn-group pull-right" ng-include="'~/crmSearchDisplay/AddButton.html'" ng-if="$ctrl.addButton"></div>
+    <div class="btn-group pull-right" ng-include="'~/crmSearchDisplay/AddButton.html'" ng-if="$ctrl.settings.addButton.path"></div>
   </div>
   <div
     class="crm-search-display-grid-container crm-search-display-grid-layout-{{$ctrl.settings.colno}}"
index 0516a679d1a4c50032a295c68872ebedb4f51f41..ec1eaac3a76d5dcfb42f7fc5463623b0dd32d3e8 100644 (file)
@@ -1,7 +1,7 @@
 <div class="crm-search-display crm-search-display-list">
   <div class="form-inline">
     <div class="btn-group" ng-include="'~/crmSearchDisplay/SearchButton.html'" ng-if="$ctrl.settings.button"></div>
-    <div class="btn-group pull-right" ng-include="'~/crmSearchDisplay/AddButton.html'" ng-if="$ctrl.addButton"></div>
+    <div class="btn-group pull-right" ng-include="'~/crmSearchDisplay/AddButton.html'" ng-if="$ctrl.settings.addButton.path"></div>
   </div>
   <ol ng-if=":: $ctrl.settings.style === 'ol'" ng-include="'~/crmSearchDisplayList/crmSearchDisplayList' + ($ctrl.loading ? 'Loading' : 'Items') + '.html'" ng-style="{'list-style': $ctrl.settings.symbol}"></ol>
   <ul ng-if=":: $ctrl.settings.style !== 'ol'" ng-include="'~/crmSearchDisplayList/crmSearchDisplayList' + ($ctrl.loading ? 'Loading' : 'Items') + '.html'" ng-style="{'list-style': $ctrl.settings.symbol}"></ul>
index 285c3f1b45e8be32bd12a4d567051c3ab8bcb19e..73e41049708a99b049551fc2568a64d1952795e8 100644 (file)
@@ -2,7 +2,7 @@
   <div class="form-inline">
     <div class="btn-group" ng-include="'~/crmSearchDisplay/SearchButton.html'" ng-if="$ctrl.settings.button"></div>
     <crm-search-tasks ng-if="$ctrl.settings.actions" entity="$ctrl.apiEntity" ids="$ctrl.selectedRows" search="$ctrl.search" display="$ctrl.display" display-controller="$ctrl" refresh="$ctrl.refreshAfterTask()"></crm-search-tasks>
-    <div class="btn-group pull-right" ng-include="'~/crmSearchDisplay/AddButton.html'" ng-if="$ctrl.addButton"></div>
+    <div class="btn-group pull-right" ng-include="'~/crmSearchDisplay/AddButton.html'" ng-if="$ctrl.settings.addButton.path"></div>
   </div>
   <table class="{{:: $ctrl.settings.classes.join(' ') }}">
     <thead>