2020-05-29 13:41:58 +02:00
|
|
|
<?php
|
2021-11-10 09:06:39 +01:00
|
|
|
/*
|
2020-06-21 23:53:38 +02:00
|
|
|
* echo $this->element('/genericElements/IndexTable/index_table', [
|
2020-05-29 13:41:58 +02:00
|
|
|
* 'top_bar' => (
|
|
|
|
* // search/filter bar information compliant with ListTopBar
|
|
|
|
* ),
|
2020-06-21 23:53:38 +02:00
|
|
|
* 'data' => [
|
2020-05-29 13:41:58 +02:00
|
|
|
// the actual data to be used
|
|
|
|
* ),
|
2020-06-21 23:53:38 +02:00
|
|
|
* 'fields' => [
|
2020-05-29 13:41:58 +02:00
|
|
|
* // field list with information for the paginator, the elements used for the individual cells, etc
|
|
|
|
* ),
|
|
|
|
* 'title' => optional title,
|
|
|
|
* 'description' => optional description,
|
|
|
|
* 'primary_id_path' => path to each primary ID (extracted and passed as $primary to fields)
|
|
|
|
* ));
|
|
|
|
*
|
|
|
|
*/
|
2021-11-10 09:06:39 +01:00
|
|
|
|
|
|
|
$newMetaFields = [];
|
|
|
|
if (!empty($requestedMetaFields)) { // Create mapping for new index table fields on the fly
|
|
|
|
foreach ($requestedMetaFields as $requestedMetaField) {
|
|
|
|
$template_id = $requestedMetaField['template_id'];
|
|
|
|
$meta_template_field_id = $requestedMetaField['meta_template_field_id'];
|
|
|
|
$newMetaFields[] = [
|
|
|
|
'name' => $meta_templates[$template_id]['meta_template_fields'][$meta_template_field_id]['field'],
|
|
|
|
'data_path' => "MetaTemplates.{$template_id}.meta_template_fields.{$meta_template_field_id}.metaFields.{n}.value",
|
|
|
|
'element' => 'generic_field',
|
|
|
|
'_metafield' => true,
|
|
|
|
'_automatic_field' => true,
|
|
|
|
];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$data['fields'] = array_merge($data['fields'], $newMetaFields);
|
|
|
|
|
2020-05-29 13:41:58 +02:00
|
|
|
$tableRandomValue = Cake\Utility\Security::randomString(8);
|
|
|
|
echo '<div id="table-container-' . h($tableRandomValue) . '">';
|
2020-06-23 00:58:27 +02:00
|
|
|
if (!empty($data['title'])) {
|
2021-09-17 13:04:37 +02:00
|
|
|
echo sprintf('<h2 class="fw-light">%s</h2>', h($data['title']));
|
2020-05-29 13:41:58 +02:00
|
|
|
}
|
2020-06-23 00:58:27 +02:00
|
|
|
if (!empty($data['description'])) {
|
2020-05-29 13:41:58 +02:00
|
|
|
echo sprintf(
|
2021-09-17 13:04:37 +02:00
|
|
|
'<div class="fw-light">%s</div>',
|
2020-05-29 13:41:58 +02:00
|
|
|
empty($data['description']) ? '' : h($data['description'])
|
|
|
|
);
|
|
|
|
}
|
2021-09-16 15:50:55 +02:00
|
|
|
echo '<div class="panel">';
|
2020-05-29 13:41:58 +02:00
|
|
|
if (!empty($data['html'])) {
|
|
|
|
echo sprintf('<div>%s</div>', $data['html']);
|
|
|
|
}
|
|
|
|
$skipPagination = isset($data['skip_pagination']) ? $data['skip_pagination'] : 0;
|
|
|
|
if (!$skipPagination) {
|
2020-06-21 23:53:38 +02:00
|
|
|
$paginationData = !empty($data['paginatorOptions']) ? $data['paginatorOptions'] : [];
|
2020-05-29 13:41:58 +02:00
|
|
|
echo $this->element(
|
|
|
|
'/genericElements/IndexTable/pagination',
|
2020-06-21 23:53:38 +02:00
|
|
|
[
|
2020-05-29 13:41:58 +02:00
|
|
|
'paginationOptions' => $paginationData,
|
|
|
|
'tableRandomValue' => $tableRandomValue
|
2020-06-21 23:53:38 +02:00
|
|
|
]
|
2020-05-29 13:41:58 +02:00
|
|
|
);
|
2020-06-23 00:58:27 +02:00
|
|
|
echo $this->element(
|
|
|
|
'/genericElements/IndexTable/pagination_links'
|
|
|
|
);
|
2020-05-29 13:41:58 +02:00
|
|
|
}
|
2021-07-05 09:30:20 +02:00
|
|
|
$multiSelectData = getMultiSelectData($data['top_bar']);
|
|
|
|
if (!empty($multiSelectData)) {
|
|
|
|
$multiSelectField = [
|
|
|
|
'element' => 'selector',
|
|
|
|
'class' => 'short',
|
|
|
|
'data' => $multiSelectData['data']
|
|
|
|
];
|
|
|
|
array_unshift($data['fields'], $multiSelectField);
|
|
|
|
}
|
2020-05-29 13:41:58 +02:00
|
|
|
if (!empty($data['top_bar'])) {
|
|
|
|
echo $this->element(
|
|
|
|
'/genericElements/ListTopBar/scaffold',
|
2020-06-21 23:53:38 +02:00
|
|
|
[
|
2020-05-29 13:41:58 +02:00
|
|
|
'data' => $data['top_bar'],
|
2021-10-20 09:39:12 +02:00
|
|
|
'table_data' => $data,
|
2020-05-29 13:41:58 +02:00
|
|
|
'tableRandomValue' => $tableRandomValue
|
2020-06-21 23:53:38 +02:00
|
|
|
]
|
2020-05-29 13:41:58 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
$rows = '';
|
|
|
|
$row_element = isset($data['row_element']) ? $data['row_element'] : 'row';
|
2020-06-21 23:53:38 +02:00
|
|
|
$options = isset($data['options']) ? $data['options'] : [];
|
|
|
|
$actions = isset($data['actions']) ? $data['actions'] : [];
|
|
|
|
if ($this->request->getParam('prefix') === 'Open') {
|
|
|
|
$actions = [];
|
|
|
|
}
|
|
|
|
$dblclickActionArray = !empty($actions) ? $this->Hash->extract($actions, '{n}[dbclickAction]') : [];
|
2020-05-29 13:41:58 +02:00
|
|
|
$dbclickAction = '';
|
|
|
|
foreach ($data['data'] as $k => $data_row) {
|
|
|
|
$primary = null;
|
|
|
|
if (!empty($data['primary_id_path'])) {
|
|
|
|
$primary = $this->Hash->extract($data_row, $data['primary_id_path'])[0];
|
|
|
|
}
|
|
|
|
if (!empty($dblclickActionArray)) {
|
|
|
|
$dbclickAction = sprintf("changeLocationFromIndexDblclick(%s)", $k);
|
|
|
|
}
|
|
|
|
$rows .= sprintf(
|
2020-06-04 10:05:45 +02:00
|
|
|
'<tr data-row-id="%s" %s %s class="%s %s">%s</tr>',
|
2020-05-29 13:41:58 +02:00
|
|
|
h($k),
|
|
|
|
empty($dbclickAction) ? '' : 'ondblclick="' . $dbclickAction . '"',
|
|
|
|
empty($primary) ? '' : 'data-primary-id="' . $primary . '"',
|
2020-06-04 10:05:45 +02:00
|
|
|
empty($data['row_modifier']) ? '' : h($data['row_modifier']($data_row)),
|
|
|
|
empty($data['class']) ? '' : h($data['row_class']),
|
2020-05-29 13:41:58 +02:00
|
|
|
$this->element(
|
|
|
|
'/genericElements/IndexTable/' . $row_element,
|
2020-06-21 23:53:38 +02:00
|
|
|
[
|
2020-05-29 13:41:58 +02:00
|
|
|
'k' => $k,
|
|
|
|
'row' => $data_row,
|
|
|
|
'fields' => $data['fields'],
|
|
|
|
'options' => $options,
|
|
|
|
'actions' => $actions,
|
|
|
|
'primary' => $primary,
|
|
|
|
'tableRandomValue' => $tableRandomValue
|
2020-06-21 23:53:38 +02:00
|
|
|
]
|
2020-05-29 13:41:58 +02:00
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
$tbody = '<tbody>' . $rows . '</tbody>';
|
|
|
|
echo sprintf(
|
2021-11-10 09:06:39 +01:00
|
|
|
'<table class="table table-hover" id="index-table-%s" data-table-random-value="%s" data-reload-url="%s">%s%s</table>',
|
2021-06-23 11:15:22 +02:00
|
|
|
$tableRandomValue,
|
2020-05-29 13:41:58 +02:00
|
|
|
$tableRandomValue,
|
2021-11-10 09:06:39 +01:00
|
|
|
h($this->Url->build(['action' => $this->request->getParam('action'),])),
|
2020-05-29 13:41:58 +02:00
|
|
|
$this->element(
|
|
|
|
'/genericElements/IndexTable/headers',
|
2020-06-21 23:53:38 +02:00
|
|
|
[
|
2020-05-29 13:41:58 +02:00
|
|
|
'fields' => $data['fields'],
|
|
|
|
'paginator' => $this->Paginator,
|
2020-06-21 23:53:38 +02:00
|
|
|
'actions' => (empty($actions) ? false : true),
|
2020-05-29 13:41:58 +02:00
|
|
|
'tableRandomValue' => $tableRandomValue
|
2020-06-21 23:53:38 +02:00
|
|
|
]
|
2020-05-29 13:41:58 +02:00
|
|
|
),
|
|
|
|
$tbody
|
|
|
|
);
|
|
|
|
if (!$skipPagination) {
|
|
|
|
echo $this->element('/genericElements/IndexTable/pagination_counter', $paginationData);
|
|
|
|
echo $this->element('/genericElements/IndexTable/pagination_links');
|
|
|
|
}
|
|
|
|
echo '</div>';
|
2021-09-13 11:43:42 +02:00
|
|
|
echo '</div>';
|
2020-05-29 13:41:58 +02:00
|
|
|
?>
|
|
|
|
<script type="text/javascript">
|
|
|
|
$(document).ready(function() {
|
2021-06-23 11:15:22 +02:00
|
|
|
$('#index-table-<?= $tableRandomValue ?>').data('data', <?= json_encode($data['data']) ?>);
|
2020-05-29 13:41:58 +02:00
|
|
|
$('.privacy-toggle').on('click', function() {
|
|
|
|
var $privacy_target = $(this).parent().find('.privacy-value');
|
|
|
|
if ($(this).hasClass('fa-eye')) {
|
|
|
|
$privacy_target.text($privacy_target.data('hidden-value'));
|
|
|
|
$(this).removeClass('fa-eye');
|
|
|
|
$(this).addClass('fa-eye-slash');
|
|
|
|
} else {
|
|
|
|
$privacy_target.text('****************************************');
|
|
|
|
$(this).removeClass('fa-eye-slash');
|
|
|
|
$(this).addClass('fa-eye');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
</script>
|
2021-07-05 09:30:20 +02:00
|
|
|
|
|
|
|
<?php
|
|
|
|
function getMultiSelectData($topbar) {
|
|
|
|
foreach ($topbar['children'] as $child) {
|
|
|
|
if (!empty($child['type']) && $child['type'] == 'multi_select_actions') {
|
|
|
|
return $child;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return [];
|
|
|
|
}
|