2021-03-15 22:47:13 +01:00
|
|
|
<?php
|
|
|
|
echo $this->Html->scriptBlock(sprintf(
|
|
|
|
'var csrfToken = %s;',
|
|
|
|
json_encode($this->request->getAttribute('csrfToken'))
|
|
|
|
));
|
|
|
|
echo $this->element('genericElements/IndexTable/index_table', [
|
|
|
|
'data' => [
|
|
|
|
'data' => $data,
|
|
|
|
'top_bar' => [
|
|
|
|
'children' => [
|
2021-06-23 11:19:56 +02:00
|
|
|
[
|
2021-07-05 09:30:20 +02:00
|
|
|
'type' => 'multi_select_actions',
|
2021-06-23 11:19:56 +02:00
|
|
|
'children' => [
|
|
|
|
[
|
2022-10-25 10:26:03 +02:00
|
|
|
'text' => __('Discard message'),
|
2021-06-23 11:19:56 +02:00
|
|
|
'variant' => 'danger',
|
2022-10-25 10:26:03 +02:00
|
|
|
'onclick' => 'discardMessages',
|
2021-06-23 11:19:56 +02:00
|
|
|
]
|
|
|
|
],
|
2021-07-05 09:30:20 +02:00
|
|
|
'data' => [
|
|
|
|
'id' => [
|
|
|
|
'value_path' => 'id'
|
|
|
|
]
|
|
|
|
]
|
2021-06-23 11:19:56 +02:00
|
|
|
],
|
2021-03-15 22:47:13 +01:00
|
|
|
[
|
|
|
|
'type' => 'context_filters',
|
|
|
|
'context_filters' => !empty($filteringContexts) ? $filteringContexts : []
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'type' => 'search',
|
2021-11-10 15:31:09 +01:00
|
|
|
'button' => __('Search'),
|
2021-03-15 22:47:13 +01:00
|
|
|
'placeholder' => __('Enter value to search'),
|
|
|
|
'data' => '',
|
|
|
|
'searchKey' => 'value',
|
|
|
|
'allowFilering' => true
|
2022-10-25 10:26:03 +02:00
|
|
|
],
|
|
|
|
[
|
|
|
|
'type' => 'table_action',
|
|
|
|
'table_setting_id' => 'inbox_index',
|
2021-03-15 22:47:13 +01:00
|
|
|
]
|
|
|
|
]
|
|
|
|
],
|
|
|
|
'fields' => [
|
|
|
|
[
|
|
|
|
'name' => '#',
|
2023-12-12 09:52:33 +01:00
|
|
|
'sort' => 'Inbox.id',
|
2021-03-15 22:47:13 +01:00
|
|
|
'data_path' => 'id',
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'name' => 'created',
|
2023-12-12 09:52:33 +01:00
|
|
|
'sort' => 'Inbox.created',
|
2021-03-15 22:47:13 +01:00
|
|
|
'data_path' => 'created',
|
|
|
|
'element' => 'datetime'
|
|
|
|
],
|
2022-10-25 14:38:16 +02:00
|
|
|
[
|
|
|
|
'name' => 'severity',
|
|
|
|
'sort' => 'severity',
|
|
|
|
'data_path' => 'severity',
|
|
|
|
'element' => 'function',
|
|
|
|
'function' => function ($entry, $context) {
|
|
|
|
return $context->Bootstrap->badge([
|
|
|
|
'text' => $entry->severity_variant,
|
|
|
|
'variant' => $entry->severity_variant,
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
],
|
2021-03-15 22:47:13 +01:00
|
|
|
[
|
|
|
|
'name' => 'scope',
|
|
|
|
'sort' => 'scope',
|
|
|
|
'data_path' => 'scope',
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'name' => 'action',
|
|
|
|
'sort' => 'action',
|
|
|
|
'data_path' => 'action',
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'name' => 'title',
|
|
|
|
'sort' => 'title',
|
|
|
|
'data_path' => 'title',
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'name' => 'origin',
|
|
|
|
'sort' => 'origin',
|
|
|
|
'data_path' => 'origin',
|
|
|
|
],
|
|
|
|
[
|
2024-05-15 11:25:31 +02:00
|
|
|
'name' => __('to'),
|
2023-12-12 09:52:33 +01:00
|
|
|
'sort' => 'Inbox.user_id',
|
2021-03-15 22:47:13 +01:00
|
|
|
'data_path' => 'user',
|
|
|
|
'element' => 'user'
|
|
|
|
],
|
|
|
|
[
|
2022-10-25 14:38:16 +02:00
|
|
|
'name' => 'message',
|
|
|
|
'sort' => 'message',
|
|
|
|
'data_path' => 'message',
|
2021-03-15 22:47:13 +01:00
|
|
|
],
|
|
|
|
],
|
|
|
|
'title' => __('Inbox'),
|
|
|
|
'description' => __('A list of requests to be manually processed'),
|
|
|
|
'actions' => [
|
2021-03-18 09:26:01 +01:00
|
|
|
[
|
|
|
|
'url' => '/inbox/view',
|
|
|
|
'url_params_data_paths' => ['id'],
|
2021-03-18 14:01:14 +01:00
|
|
|
'icon' => 'eye',
|
|
|
|
'title' => __('View request')
|
2021-03-18 09:26:01 +01:00
|
|
|
],
|
2021-03-15 22:47:13 +01:00
|
|
|
[
|
|
|
|
'open_modal' => '/inbox/process/[onclick_params_data_path]',
|
|
|
|
'modal_params_data_path' => 'id',
|
2021-03-18 14:01:14 +01:00
|
|
|
'icon' => 'cogs',
|
|
|
|
'title' => __('Process request')
|
2021-03-15 22:47:13 +01:00
|
|
|
],
|
|
|
|
[
|
2021-03-18 09:26:01 +01:00
|
|
|
'open_modal' => '/inbox/delete/[onclick_params_data_path]',
|
2021-03-15 22:47:13 +01:00
|
|
|
'modal_params_data_path' => 'id',
|
2021-03-18 14:01:14 +01:00
|
|
|
'icon' => 'trash',
|
2022-10-25 10:26:03 +02:00
|
|
|
'title' => __('Discard message')
|
2021-03-15 22:47:13 +01:00
|
|
|
],
|
|
|
|
]
|
|
|
|
]
|
|
|
|
]);
|
|
|
|
?>
|
2021-06-23 11:19:56 +02:00
|
|
|
|
|
|
|
<script>
|
2022-10-25 10:26:03 +02:00
|
|
|
function discardMessages(idList, selectedData, $table) {
|
2021-06-23 11:19:56 +02:00
|
|
|
const successCallback = function([data, modalObject]) {
|
|
|
|
UI.reload('/inbox/index', UI.getContainerForTable($table), $table)
|
|
|
|
}
|
|
|
|
const failCallback = ([data, modalObject]) => {
|
|
|
|
const tableData = selectedData.map(row => {
|
|
|
|
entryInError = data.filter(error => error.data.id == row.id)[0]
|
|
|
|
$faIcon = $('<i class="fa"></i>').addClass(entryInError.success ? 'fa-check text-success' : 'fa-times text-danger')
|
|
|
|
return [row.id, row.scope, row.action, row.title, entryInError.message, JSON.stringify(entryInError.errors), $faIcon]
|
|
|
|
});
|
|
|
|
handleMessageTable(
|
|
|
|
modalObject.$modal,
|
|
|
|
['<?= __('ID') ?>', '<?= __('Scope') ?>', '<?= __('Action') ?>', '<?= __('Title') ?>', '<?= __('Message') ?>', '<?= __('Error') ?>', '<?= __('State') ?>'],
|
|
|
|
tableData
|
|
|
|
)
|
|
|
|
const $footer = $(modalObject.ajaxApi.statusNode).parent()
|
|
|
|
modalObject.ajaxApi.statusNode.remove()
|
2021-09-17 13:04:37 +02:00
|
|
|
const $cancelButton = $footer.find('button[data-bs-dismiss="modal"]')
|
2021-06-23 11:19:56 +02:00
|
|
|
$cancelButton.text('<?= __('OK') ?>').removeClass('btn-secondary').addClass('btn-primary')
|
|
|
|
}
|
|
|
|
UI.submissionModal('/inbox/delete', successCallback, failCallback).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'],
|
|
|
|
}
|
|
|
|
)
|
|
|
|
}
|
2022-10-25 10:26:03 +02:00
|
|
|
|
2021-06-23 11:19:56 +02:00
|
|
|
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>
|