SearchKit - Faster delete/revert actions in search listing
authorColeman Watts <coleman@civicrm.org>
Mon, 6 Dec 2021 03:06:49 +0000 (22:06 -0500)
committerColeman Watts <coleman@civicrm.org>
Mon, 20 Dec 2021 21:51:32 +0000 (16:51 -0500)
ext/search_kit/ang/crmSearchAdmin/searchListing/crmSearchAdminSearchListing.component.js

index 5b18b02ee09ffbd239ab77132087f9f28827c53d..dde44a4470f6ad869bb050e3cad59b61b08ea1b7 100644 (file)
           message: getMessage(),
         }).on('crmConfirm:yes', function() {
           $scope.$apply(function() {
-            return revert ? ctrl.revertSearch(search) : ctrl.deleteSearch(search);
+            return revert ? ctrl.revertSearch(row) : ctrl.deleteSearch(row);
           });
         }).block();
 
         });
       };
 
-      this.deleteSearch = function(search) {
-        crmStatus({start: ts('Deleting...'), success: ts('Search Deleted')},
-          crmApi4('SavedSearch', 'delete', {where: [['id', '=', search.id]]}).then(function() {
-            ctrl.rowCount = null;
-            ctrl.runSearch();
-          })
+      this.deleteSearch = function(row) {
+        ctrl.runSearch(
+          [['SavedSearch', 'delete', {where: [['id', '=', row.key]]}]],
+          {start: ts('Deleting...'), success: ts('Search Deleted')},
+          row
         );
       };
 
-      this.revertSearch = function(search) {
-        crmStatus({start: ts('Reverting...'), success: ts('Search Reverted')},
-          crmApi4('SavedSearch', 'revert', {
-            where: [['id', '=', search.id]],
+      this.revertSearch = function(row) {
+        ctrl.runSearch(
+          [['SavedSearch', 'revert', {
+            where: [['id', '=', row.key]],
             chain: {
               revertDisplays: ['SearchDisplay', 'revert', {'where': [['saved_search_id', '=', '$id'], ['has_base', '=', true]]}],
               deleteDisplays: ['SearchDisplay', 'delete', {'where': [['saved_search_id', '=', '$id'], ['has_base', '=', false]]}]
             }
-          }).then(function() {
-            ctrl.rowCount = null;
-            ctrl.runSearch();
-          })
+          }]],
+          {start: ts('Reverting...'), success: ts('Search Reverted')},
+          row
         );
       };