2021-10-20 09:39:12 +02:00
< ? php
2021-11-10 09:06:39 +01:00
use App\Utility\UI\IndexSetting ;
if ( empty ( $data [ 'table_setting_id' ]) && empty ( $model )) {
2021-10-20 09:39:12 +02:00
throw new Exception ( __ ( '`table_setting_id` must be set in order to use the `table_action` table topbar' ));
}
2023-11-02 08:08:06 +01:00
$now = date ( " Y-m-d_H-i-s " );
$downloadFilename = sprintf ( '%s_%s' , $data [ 'table_setting_id' ] ? ? h ( $model ), $now );
2021-11-10 09:06:39 +01:00
$data [ 'table_setting_id' ] = ! empty ( $data [ 'table_setting_id' ]) ? $data [ 'table_setting_id' ] : IndexSetting :: getIDFromTable ( $model );
$tableSettings = IndexSetting :: getTableSetting ( $loggedUser , $data [ 'table_setting_id' ]);
2021-10-20 11:28:39 +02:00
$compactDisplay = ! empty ( $tableSettings [ 'compact_display' ]);
2022-10-28 09:13:15 +02:00
$numberOfElement = $tableSettings [ 'number_of_element' ] ? ? 20 ;
2021-10-20 09:39:12 +02:00
$availableColumnsHtml = $this -> element ( '/genericElements/ListTopBar/group_table_action/hiddenColumns' , [
'table_data' => $table_data ,
'tableSettings' => $tableSettings ,
'table_setting_id' => $data [ 'table_setting_id' ],
]);
2021-11-10 09:06:39 +01:00
$metaTemplateColumnMenu = [];
if ( ! empty ( $meta_templates )) {
2021-11-11 08:24:07 +01:00
$metaTemplateColumnMenu [] = [ 'header' => true , 'text' => __ ( 'Meta Templates' ), 'icon' => 'object-group' ,];
2023-01-17 09:17:49 +01:00
if ( empty ( $meta_templates_enabled )) {
$metaTemplateColumnMenu [] = [ 'header' => false , 'text' => __ ( '- No enabled Meta Templates found -' ), 'class' => [ 'disabled' , 'muted' ]];
} else {
foreach ( $meta_templates_enabled as $meta_template ) {
$numberActiveMetaField = ! empty ( $tableSettings [ 'visible_meta_column' ][ $meta_template -> id ]) ? count ( $tableSettings [ 'visible_meta_column' ][ $meta_template -> id ]) : 0 ;
$metaTemplateColumnMenu [] = [
'text' => $meta_template -> name ,
'sup' => $meta_template -> version ,
'badge' => [
'text' => $numberActiveMetaField ,
'variant' => 'secondary' ,
'title' => __n ( '{0} meta-field active for this meta-template' , '{0} meta-fields active for this meta-template' , $numberActiveMetaField , $numberActiveMetaField ),
],
'keepOpen' => true ,
'menu' => [
[
'html' => $this -> element ( '/genericElements/ListTopBar/group_table_action/hiddenMetaColumns' , [
'tableSettings' => $tableSettings ,
'table_setting_id' => $data [ 'table_setting_id' ],
'meta_template' => $meta_template ,
])
]
],
];
}
2021-11-10 09:06:39 +01:00
}
}
2021-11-10 09:30:23 +01:00
$indexColumnMenu = array_merge (
[[ 'header' => true , 'text' => sprintf ( '%s\'s fields' , $this -> request -> getParam ( 'controller' ))]],
[[ 'html' => $availableColumnsHtml ]],
$metaTemplateColumnMenu
);
2021-11-10 09:06:39 +01:00
2023-11-02 08:08:06 +01:00
$indexDownloadMenu = [
[ 'header' => true , 'text' => 'JSON' , 'icon' => 'file-code' ],
[ 'text' => __ ( 'Download all' ), 'onclick' => sprintf ( 'downloadIndexTable(this, "%s")' , $downloadFilename . '.json' ), ],
[ 'text' => __ ( 'Download filtered table' ), 'onclick' => sprintf ( 'downloadIndexTable(this, "%s", true)' , $downloadFilename . '.json' ), ],
[ 'header' => true , 'text' => 'CSV' , 'icon' => 'file-csv' , ],
[ 'text' => __ ( 'Download all' ), 'onclick' => sprintf ( 'downloadIndexTable(this, "%s")' , $downloadFilename . '.csv' ), ],
[ 'text' => __ ( 'Download filtered table' ), 'onclick' => sprintf ( 'downloadIndexTable(this, "%s", true)' , $downloadFilename . '.csv' ), ],
];
2021-10-20 11:28:39 +02:00
$compactDisplayHtml = $this -> element ( '/genericElements/ListTopBar/group_table_action/compactDisplay' , [
'table_data' => $table_data ,
'tableSettings' => $tableSettings ,
'table_setting_id' => $data [ 'table_setting_id' ],
2022-10-28 09:13:15 +02:00
'compactDisplay' => $compactDisplay ,
]);
$numberOfElementHtml = $this -> element ( '/genericElements/ListTopBar/group_table_action/numberOfElement' , [
'table_data' => $table_data ,
'tableSettings' => $tableSettings ,
'table_setting_id' => $data [ 'table_setting_id' ],
'numberOfElement' => $numberOfElement ,
2023-09-06 09:18:40 +02:00
'includeAll' => ! empty ( $table_data [ 'includeAllPagination' ]),
2021-10-20 11:28:39 +02:00
]);
2021-10-20 09:39:12 +02:00
?>
< ? php if ( ! isset ( $data [ 'requirement' ]) || $data [ 'requirement' ]) : ?>
< ? php
echo $this -> Bootstrap -> dropdownMenu ([
'dropdown-class' => 'ms-1' ,
'alignment' => 'end' ,
'direction' => 'down' ,
2022-11-24 12:50:11 +01:00
'button' => [
2021-10-20 09:39:12 +02:00
'icon' => 'sliders-h' ,
'variant' => 'primary' ,
2022-10-28 09:13:15 +02:00
'class' => [ 'table_setting_dropdown_button' ],
2021-10-20 09:39:12 +02:00
],
'submenu_alignment' => 'end' ,
'submenu_direction' => 'start' ,
2022-11-24 12:50:11 +01:00
'attrs' => [
2021-10-20 09:39:12 +02:00
'data-table-random-value' => $tableRandomValue ,
'data-table_setting_id' => $data [ 'table_setting_id' ],
],
'menu' => [
[
'text' => __ ( 'Show/hide columns' ),
'icon' => 'eye-slash' ,
'keepOpen' => true ,
2021-11-10 09:06:39 +01:00
'menu' => $indexColumnMenu ,
2021-10-20 09:39:12 +02:00
],
2023-02-13 15:29:03 +01:00
[
'text' => __ ( 'Download' ),
'icon' => 'download' ,
2023-11-02 08:08:06 +01:00
'keepOpen' => true ,
'menu' => $indexDownloadMenu ,
2023-02-13 15:29:03 +01:00
],
2021-10-20 09:39:12 +02:00
[
2021-10-20 11:28:39 +02:00
'html' => $compactDisplayHtml ,
2022-10-28 09:13:15 +02:00
],
[
'html' => $numberOfElementHtml ,
2021-10-20 11:28:39 +02:00
]
2021-10-20 09:39:12 +02:00
]
]);
?>
< ? php endif ; ?>
2022-10-28 09:13:15 +02:00
< script >
$ ( document ) . ready ( function () {
const dropdownBtn = document . querySelector ( 'button.table_setting_dropdown_button' )
dropdownBtn . addEventListener ( 'hidden.bs.dropdown' , function () {
const $dropdownBtn = $ ( this )
const debouncedFunctions = $dropdownBtn . data ( 'debouncedFunctions' )
firePendingDebouncedFunctions ( dropdownBtn )
})
})
</ script >