From 4f7c95a3ec79972fe047fa47131747bee8900a5f Mon Sep 17 00:00:00 2001 From: Kurund Jalmi Date: Tue, 15 Aug 2023 15:32:17 +0100 Subject: [PATCH] add batch action for processing submissions --- .../Action/SearchDisplay/GetSearchTasks.php | 7 +++ .../crmSearchTaskProcess.ctrl.js | 59 +++++++++++++++++++ .../crmSearchTasks/crmSearchTaskProcess.html | 7 +++ 3 files changed, 73 insertions(+) create mode 100644 ext/search_kit/ang/crmSearchTasks/crmSearchTaskProcess.ctrl.js create mode 100644 ext/search_kit/ang/crmSearchTasks/crmSearchTaskProcess.html diff --git a/ext/search_kit/Civi/Api4/Action/SearchDisplay/GetSearchTasks.php b/ext/search_kit/Civi/Api4/Action/SearchDisplay/GetSearchTasks.php index 56595b207a..a27423dbc7 100644 --- a/ext/search_kit/Civi/Api4/Action/SearchDisplay/GetSearchTasks.php +++ b/ext/search_kit/Civi/Api4/Action/SearchDisplay/GetSearchTasks.php @@ -71,6 +71,13 @@ class GetSearchTasks extends \Civi\Api4\Generic\AbstractAction { 'number' => '>= 0', ]; + $tasks[$entity['name']]['process'] = [ + 'module' => 'crmSearchTasks', + 'title' => E::ts('Process Submissions'), + 'icon' => 'fa-save', + 'uiDialog' => ['templateUrl' => '~/crmSearchTasks/crmSearchTaskProcess.html'], + ]; + if (array_key_exists('update', $entity['actions'])) { $tasks[$entity['name']]['update'] = [ 'module' => 'crmSearchTasks', diff --git a/ext/search_kit/ang/crmSearchTasks/crmSearchTaskProcess.ctrl.js b/ext/search_kit/ang/crmSearchTasks/crmSearchTaskProcess.ctrl.js new file mode 100644 index 0000000000..13297492ac --- /dev/null +++ b/ext/search_kit/ang/crmSearchTasks/crmSearchTaskProcess.ctrl.js @@ -0,0 +1,59 @@ +(function(angular, $, _) { + "use strict"; + + angular.module('crmSearchTasks').controller('crmSearchTaskProcess', function ($scope, $timeout, crmApi4, searchTaskBaseTrait) { + var ts = $scope.ts = CRM.ts('org.civicrm.search_kit'), + // Combine this controller with model properties (ids, entity, entityInfo) and searchTaskBaseTrait + ctrl = angular.extend(this, $scope.model, searchTaskBaseTrait); + + this.entityTitle = this.getEntityTitle(); + this.afformName = ''; + + this.getAfformName = function(id) { + crmApi4('AfformSubmission', 'get', { + select: ["afform_name"], + where: [["id", "=", id]], + }).then(function(afformSubmissions) { + ctrl.afformName = afformSubmissions[0]['afform_name']; + }, function(error) { + ctrl.onError(); + }); + } + + this.processData = function() { + _.each(ctrl.ids, function(id) { + ctrl.start(); + crmApi4('Afform', 'process', { + submissionId: id, + name: ctrl.afformName + }).then(function(result) { + }, function(failure) { + ctrl.onError() + }); + }); + + ctrl.onSuccess(); + } + + this.save = function() { + // get the afform name + ctrl.getAfformName(ctrl.ids[0]); + + $timeout(function() { + ctrl.processData(); + },500); + + }; + + this.onSuccess = function() { + CRM.alert(ts('Successfully processed %1 %2.', {1: ctrl.ids.length, 2: ctrl.entityTitle}), ts('Saved'), 'success'); + this.close(); + }; + + this.onError = function() { + CRM.alert(ts('An error occurred while attempting to process %1 %2.', {1: ctrl.ids.length, 2: ctrl.entityTitle}), ts('Error'), 'error'); + this.cancel(); + }; + + }); +})(angular, CRM.$, CRM._); diff --git a/ext/search_kit/ang/crmSearchTasks/crmSearchTaskProcess.html b/ext/search_kit/ang/crmSearchTasks/crmSearchTaskProcess.html new file mode 100644 index 0000000000..4ca8fbe3ba --- /dev/null +++ b/ext/search_kit/ang/crmSearchTasks/crmSearchTaskProcess.html @@ -0,0 +1,7 @@ +
+
+

{{:: ts('Process the %1 selected %2 submission(s):', {1: model.ids.length, 2: $ctrl.entityTitle}) }}

+ + +
+
-- 2.25.1