SearchKit - Fix 'Add New' button
authorColeman Watts <coleman@civicrm.org>
Mon, 19 Sep 2022 15:18:00 +0000 (11:18 -0400)
committerColeman Watts <coleman@civicrm.org>
Mon, 19 Sep 2022 15:18:00 +0000 (11:18 -0400)
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 29c6b72536667620965cf92d3ba29b56ebda523e..93135230dab2cc7ff8de9c9b4f1dddea45b3c26c 100644 (file)
@@ -1,4 +1,4 @@
-<a href="{{ $ctrl.settings.addButton.url }}" 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 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>
index 5bfdafcecb48974667aa0d396f98fb199927452a..e9b5bf051e39a40b54e9d572507bb717237a1280 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) {
-          this.settings.addButton.url = CRM.url(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() {
index 710f0dfa693af18861b1bccdcc67c77e45e032d0..7722006a24118bbd87e271fcc694fa4e5ab39056 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.settings.addButton.url"></div>
+    <div class="btn-group pull-right" ng-include="'~/crmSearchDisplay/AddButton.html'" ng-if="$ctrl.addButton"></div>
   </div>
   <div
     class="crm-search-display-grid-container crm-search-display-grid-layout-{{$ctrl.settings.colno}}"
index f719b31c0ef6ecad80d609a2ee0baa98fe875627..0516a679d1a4c50032a295c68872ebedb4f51f41 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.settings.addButton.url"></div>
+    <div class="btn-group pull-right" ng-include="'~/crmSearchDisplay/AddButton.html'" ng-if="$ctrl.addButton"></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 3d57aedf18d5b8ba06fa7c552e2572330816d235..285c3f1b45e8be32bd12a4d567051c3ab8bcb19e 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.settings.addButton.url"></div>
+    <div class="btn-group pull-right" ng-include="'~/crmSearchDisplay/AddButton.html'" ng-if="$ctrl.addButton"></div>
   </div>
   <table class="{{:: $ctrl.settings.classes.join(' ') }}">
     <thead>