Aggiunto numero elementi selezionati nelle tabelle moduli

This commit is contained in:
Dasc3er 2021-07-16 09:49:24 +02:00
parent d5e7fa2a5a
commit 86d3deaa19
2 changed files with 28 additions and 17 deletions

View File

@ -364,10 +364,10 @@ function getTableSearch() {
* @param selector * @param selector
*/ */
function getTable(selector) { function getTable(selector) {
var table = $(selector); const table = $(selector);
var selected = new Map(); const selected = new Map();
var selected_ids = table.data('selected') ? table.data('selected').split(';') : []; const selected_ids = table.data('selected') ? table.data('selected').split(';') : [];
selected_ids.forEach(function (item, index) { selected_ids.forEach(function (item, index) {
selected.set(item, true); selected.set(item, true);
}); });
@ -388,11 +388,14 @@ function getTable(selector) {
datatable: table.DataTable(), datatable: table.DataTable(),
// Funzioni per i contenitori relativi alla tabella // Funzioni per i contenitori relativi alla tabella
getButtonsContainer: function () { getSelectControllerContainer: function () {
return $('.row[data-target="' + table.attr('id') + '"]').find('.table-btn'); return $('.row[data-target="' + table.attr('id') + '"]').find('.select-controller-container');
},
getExportContainer: function () {
return $('.row[data-target="' + table.attr('id') + '"]').find('.export-container');
}, },
getActionsContainer: function () { getActionsContainer: function () {
return $('.row[data-target="' + table.attr('id') + '"]').find('.bulk-container'); return $('.row[data-target="' + table.attr('id') + '"]').find('.actions-container');
}, },
// Gestione delle righe selezionate // Gestione delle righe selezionate
@ -401,19 +404,24 @@ function getTable(selector) {
return Array.from(selected.keys()); return Array.from(selected.keys());
}, },
saveSelectedRows: function () { saveSelectedRows: function () {
var selected_rows = this.getSelectedRows(); const selected_rows = this.getSelectedRows();
table.data('selected', selected_rows.join(';')); table.data('selected', selected_rows.join(';'));
var bulk_container = this.getActionsContainer(); // Abilitazione dinamica di azioni di gruppo e esportazione
var btn_container = this.getButtonsContainer(); const bulk_container = this.getActionsContainer();
const export_buttons = this.getExportContainer().find('.table-btn');
if (selected_rows.length > 0) { if (selected_rows.length > 0) {
bulk_container.removeClass('disabled').attr('disabled', false); bulk_container.removeClass('disabled').attr('disabled', false);
btn_container.removeClass('disabled').attr('disabled', false); export_buttons.removeClass('disabled').attr('disabled', false);
} else { } else {
bulk_container.addClass('disabled').attr('disabled', true); bulk_container.addClass('disabled').attr('disabled', true);
btn_container.addClass('disabled').attr('disabled', true); export_buttons.addClass('disabled').attr('disabled', true);
} }
// Aggiornamento contatore delle selezioni
this.getSelectControllerContainer()
.find('.selected-count').html(selected_rows.length);
// Aggiornamento del footer nel caso sia richiesto // Aggiornamento del footer nel caso sia richiesto
if (globals.restrict_summables_to_selected) { if (globals.restrict_summables_to_selected) {
this.updateSelectedFooter(); this.updateSelectedFooter();

View File

@ -165,9 +165,12 @@ if (!empty($type) && $type != 'menu' && $type != 'custom') {
echo ' echo '
<div class="row" data-target="'.$table_id.'"> <div class="row" data-target="'.$table_id.'">
<div class="col-md-5"> <div class="col-md-5">
<div class="btn-group" role="group"> <div class="btn-group select-controller-container" role="group">
<button type="button" class="btn btn-primary btn-select-all">'.tr('Seleziona tutto').'</button> <button type="button" class="btn btn-primary btn-select-all">'.tr('Seleziona tutto').'</button>
<button type="button" class="btn btn-default btn-select-none">'.tr('Deseleziona tutto').'</button> <button type="button" class="btn btn-default btn-select-none">
'.tr('Deseleziona tutto').'
<span class="badge selected-count">0</span>
</button>
</div> </div>
</div> </div>
@ -175,7 +178,7 @@ if (!empty($type) && $type != 'menu' && $type != 'custom') {
if (!empty($bulk)) { if (!empty($bulk)) {
echo ' echo '
<button class="btn btn-primary btn-block dropdown-toggle bulk-container disabled" type="button" data-toggle="dropdown" disabled>'.tr('Azioni di gruppo').' <span class="caret"></span></button> <button class="btn btn-primary btn-block dropdown-toggle actions-container disabled" type="button" data-toggle="dropdown" disabled>'.tr('Azioni di gruppo').' <span class="caret"></span></button>
<ul class="dropdown-menu" data-target="'.$table_id.'" role="menu">'; <ul class="dropdown-menu" data-target="'.$table_id.'" role="menu">';
foreach ($bulk as $key => $value) { foreach ($bulk as $key => $value) {
@ -200,7 +203,7 @@ if (!empty($type) && $type != 'menu' && $type != 'custom') {
<div class="col-md-5 text-right"> <div class="col-md-5 text-right">
<i class="fa fa-question-circle-o tip" title="'.tr('Le operazioni di esportazione, copia e stampa sono limitate alle righe selezionate e visibili della tabella').'. '.tr('Per azioni su tutti i contenuti selezionati, utilizzare le Azioni di gruppo').'."></i> <i class="fa fa-question-circle-o tip" title="'.tr('Le operazioni di esportazione, copia e stampa sono limitate alle righe selezionate e visibili della tabella').'. '.tr('Per azioni su tutti i contenuti selezionati, utilizzare le Azioni di gruppo').'."></i>
<div class="btn-group" role="group">'; <div class="btn-group export-container" role="group">';
if (setting('Abilita esportazione Excel e PDF')) { if (setting('Abilita esportazione Excel e PDF')) {
echo ' echo '