Skip to content
Snippets Groups Projects
Commit 074cbf20 authored by colemanw's avatar colemanw
Browse files

SearchKit - Use POST to send contact ids to action forms

Fixes #2736
parent bea5230b
Branches
Tags
No related merge requests found
......@@ -36,12 +36,14 @@ class GetSearchTasks extends \Civi\Api4\Generic\AbstractAction {
$tasks = [$entity['name'] => []];
if (array_key_exists($entity['name'], \CRM_Export_BAO_Export::getComponents())) {
$key = \CRM_Core_Key::get('CRM_Export_Controller_Standalone', TRUE);
$tasks[$entity['name']]['export'] = [
'title' => E::ts('Export %1', [1 => $entity['title_plural']]),
'icon' => 'fa-file-excel-o',
'crmPopup' => [
'path' => "'civicrm/export/standalone'",
'query' => "{reset: 1, entity: '{$entity['name']}', id: ids.join(',')}",
'query' => "{reset: 1, entity: '{$entity['name']}'}",
'data' => "{id: ids.join(','), qfKey: '$key'}",
],
];
}
......@@ -99,12 +101,14 @@ class GetSearchTasks extends \Civi\Api4\Generic\AbstractAction {
if ($task['url'] === 'civicrm/task/pick-profile') {
$task['title'] = E::ts('Profile Update');
}
$key = \CRM_Core_Key::get(\CRM_Utils_Array::first((array) $task['class']), TRUE);
$tasks[$entity['name']]['contact.' . $id] = [
'title' => $task['title'],
'icon' => $task['icon'] ?? 'fa-gear',
'crmPopup' => [
'path' => "'{$task['url']}'",
'query' => "{reset: 1, cids: ids.join(',')}",
'query' => "{reset: 1}",
'data' => "{cids: ids.join(','), qfKey: '$key'}",
],
];
}
......@@ -136,12 +140,13 @@ class GetSearchTasks extends \Civi\Api4\Generic\AbstractAction {
// FIXME: tasks() function always checks permissions, should respect `$this->checkPermissions`
foreach (\CRM_Contribute_Task::tasks() as $id => $task) {
if (!empty($task['url'])) {
$key = \CRM_Core_Key::get(\CRM_Utils_Array::first((array) $task['class']), TRUE);
$tasks[$entity['name']]['contribution.' . $id] = [
'title' => $task['title'],
'icon' => $task['icon'] ?? 'fa-gear',
'crmPopup' => [
'path' => "'{$task['url']}'",
'query' => "{id: ids.join(',')}",
'data' => "{id: ids.join(','), qfKey: '$key'}",
],
];
}
......
......@@ -67,7 +67,7 @@
if (action.crmPopup) {
var path = $scope.$eval(action.crmPopup.path, data),
query = action.crmPopup.query && $scope.$eval(action.crmPopup.query, data);
CRM.loadForm(CRM.url(path, query))
CRM.loadForm(CRM.url(path, query), {post: action.crmPopup.data && $scope.$eval(action.crmPopup.data, data)})
.on('crmFormSuccess', ctrl.refresh);
}
// If action uses dialogService
......
......@@ -202,6 +202,7 @@
options: {
url: null,
block: true,
post: null,
crmForm: null
},
_originalContent: null,
......@@ -287,12 +288,22 @@
return false;
});
},
_ajax: function(url) {
if (!this.options.post || !this.isOriginalUrl()) {
return $.getJSON(url);
}
return $.post({
url: url,
dataType: 'json',
data: this.options.post
});
},
refresh: function() {
var that = this;
var url = this._formatUrl(this.options.url, 'json');
if (this.options.crmForm) $('form', this.element).ajaxFormUnbind();
if (this.options.block) this.element.block();
$.getJSON(url, function(data) {
this._ajax(url).then(function(data) {
if (data.status === 'redirect') {
that.options.url = data.userContext;
return that.refresh();
......@@ -321,7 +332,7 @@
$('[name="'+formElement+'"]', that.element).crmError(msg);
});
}
}).fail(function(data, msg, status) {
}, function(data, msg, status) {
that._onFailure(data, status);
});
},
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment