chg: [outbox] Support of bulk deletion

pull/59/head
mokaddem 2021-06-23 11:34:26 +02:00
parent 4899ede9cc
commit e933d6ca3b
2 changed files with 66 additions and 5 deletions

View File

@ -57,11 +57,15 @@ class OutboxController extends AppController
} }
} }
public function delete($id) public function delete($id=false)
{ {
$this->set('deletionTitle', __('Discard request')); $this->set('deletionTitle', __('Confirm message deletion'));
$this->set('deletionText', __('Are you sure you want to discard request #{0}?', $id)); if (!empty($id)) {
$this->set('deletionConfirm', __('Discard')); $this->set('deletionText', __('Are you sure you want to delete message #{0}?', $id));
} else {
$this->set('deletionText', __('Are you sure you want to delete the selected messages?'));
}
$this->set('deletionConfirm', __('Delete'));
$this->CRUD->delete($id); $this->CRUD->delete($id);
$responsePayload = $this->CRUD->getResponsePayload(); $responsePayload = $this->CRUD->getResponsePayload();
if (!empty($responsePayload)) { if (!empty($responsePayload)) {

View File

@ -8,6 +8,16 @@ echo $this->element('genericElements/IndexTable/index_table', [
'data' => $data, 'data' => $data,
'top_bar' => [ 'top_bar' => [
'children' => [ 'children' => [
[
'children' => [
[
'text' => __('Delete messages'),
'variant' => 'danger',
'onclick' => 'deleteMessages',
]
],
'type' => 'multi_select_actions',
],
[ [
'type' => 'context_filters', 'type' => 'context_filters',
'context_filters' => !empty($filteringContexts) ? $filteringContexts : [] 'context_filters' => !empty($filteringContexts) ? $filteringContexts : []
@ -23,6 +33,15 @@ echo $this->element('genericElements/IndexTable/index_table', [
] ]
], ],
'fields' => [ 'fields' => [
[
'element' => 'selector',
'class' => 'short',
'data' => [
'id' => [
'value_path' => 'id'
]
]
],
[ [
'name' => '#', 'name' => '#',
'sort' => 'id', 'sort' => 'id',
@ -90,5 +109,43 @@ echo $this->element('genericElements/IndexTable/index_table', [
] ]
] ]
]); ]);
echo '</div>';
?> ?>
<script>
function deleteMessages(idList, selectedData, $table) {
UI.submissionModalForIndex('/outbox/delete', '/outbox/index', $table).then(([modalObject, ajaxApi]) => {
const $idsInput = modalObject.$modal.find('form').find('input#ids-field')
$idsInput.val(JSON.stringify(idList))
const tableData = selectedData.map(row => {
return [row.id, row.scope, row.action, row.title]
});
handleMessageTable(
modalObject.$modal,
['<?= __('ID') ?>', '<?= __('Scope') ?>', '<?= __('Action') ?>', '<?= __('Title') ?>'],
tableData
)
})
function constructMessageTable(header, data) {
return HtmlHelper.table(
header,
data,
{
small: true,
borderless: true,
tableClass: ['message-table', 'mt-4 mb-0'],
}
)
}
function handleMessageTable($modal, header, data) {
const $modalBody = $modal.find('.modal-body')
const $messageTable = $modalBody.find('table.message-table')
const messageTableHTML = constructMessageTable(header, data)[0].outerHTML
if ($messageTable.length) {
$messageTable.html(messageTableHTML)
} else {
$modalBody.append(messageTableHTML)
}
}
}
</script>