Merge pull request #19760 from civicrm/5.36
[civicrm-core.git] / ext / search / ang / crmSearchActions / crmSearchActionDelete.ctrl.js
index d7c3f4828213c190a8c6ef399b393f25688f2087..911e832eea87f7454c382811742085ff2d9ab4ee 100644 (file)
@@ -1,10 +1,10 @@
 (function(angular, $, _) {
   "use strict";
 
-  angular.module('crmSearchActions').controller('crmSearchActionDelete', function($scope, crmApi4, dialogService) {
-    var ts = $scope.ts = CRM.ts(),
+  angular.module('crmSearchActions').controller('crmSearchActionDelete', function($scope, dialogService) {
+    var ts = $scope.ts = CRM.ts('org.civicrm.search'),
       model = $scope.model,
-      ctrl = $scope.$ctrl = this;
+      ctrl = this;
 
     this.entityTitle = model.ids.length === 1 ? model.entityInfo.title : model.entityInfo.title_plural;
 
     };
 
     this.delete = function() {
-      crmApi4(model.entity, 'Delete', {
-        where: [['id', 'IN', model.ids]],
-      }).then(function() {
-        dialogService.close('crmSearchAction');
-      });
+      $('.ui-dialog-titlebar button').hide();
+      ctrl.run = {};
+    };
+
+    this.onSuccess = function() {
+      CRM.alert(ts('Successfully deleted %1 %2.', {1: model.ids.length, 2: ctrl.entityTitle}), ts('Deleted'), 'success');
+      dialogService.close('crmSearchAction');
+    };
+
+    this.onError = function() {
+      CRM.alert(ts('An error occurred while attempting to delete %1 %2.', {1: model.ids.length, 2: ctrl.entityTitle}), ts('Error'), 'error');
+      dialogService.close('crmSearchAction');
     };
 
   });