Correzioni grafiche per la gestione dinamica delle colonne

This commit is contained in:
Dasc3er 2020-08-25 09:29:32 +02:00
parent e70355cc9e
commit 3781750895
3 changed files with 47 additions and 13 deletions

View File

@ -78,7 +78,8 @@ echo '
redirectOperation($id_module, isset($id_parent) ? $id_parent : $id_record); redirectOperation($id_module, isset($id_parent) ? $id_parent : $id_record);
if ($user->is_admin && str_contains($structure['option'], '|select|')) { // Interfaccia per la modifica dell'ordine e della visibilità delle colonne (Amministratore)
if ($user->is_admin && str_contains($module['option'], '|select|')) {
echo ' echo '
<button type="button" class="btn btn-xs btn-primary pull-right" onclick="modificaColonne(this)"> <button type="button" class="btn btn-xs btn-primary pull-right" onclick="modificaColonne(this)">
<i class="fa fa-th-list"></i> '.tr('Modifica colonne').' <i class="fa fa-th-list"></i> '.tr('Modifica colonne').'

View File

@ -7,24 +7,18 @@ $structure = Modules::get($id_module);
$modulo_viste = Modules::get('Viste'); $modulo_viste = Modules::get('Viste');
echo ' echo '
<p>'.tr('Trascina le colonne per riordinare la struttura della tabella principale').'.</p> <p>'.tr('Trascina le colonne per ordinare la struttura della tabella principale, seleziona e deseleziona le colonne per renderle visibili o meno').'.</p>
<div class="sortable">'; <div class="sortable">';
$fields = $dbo->fetchArray('SELECT * FROM zz_views WHERE id_module='.prepare($id_module).' ORDER BY `order` ASC'); $fields = $dbo->fetchArray('SELECT * FROM zz_views WHERE id_module='.prepare($id_module).' ORDER BY `order` ASC');
foreach ($fields as $field) { foreach ($fields as $field) {
echo ' echo '
<div class="panel panel-default clickable col-md-4" data-id="'.$field['id'].'"> <div class="panel panel-default clickable col-md-4" data-id="'.$field['id'].'">
<div class="panel-body">'; <div class="panel-body">
<input type="checkbox" name="visibile" '.($field['visible'] ? 'checked' : '').'>
if ($field['visible']) { <span class="text-'.($field['visible'] ? 'success' : 'danger').'">'.$field['name'].'</span>
echo '
<span class="text-success">'.$field['name'].'</span>';
} else {
echo '
<span class="text-danger">'.$field['name'].'</span>';
}
echo '
<i class="fa fa-sort pull-right"></i> <i class="fa fa-sort pull-right"></i>
</div> </div>
</div>'; </div>';
@ -35,6 +29,37 @@ echo '
<div class="clearfix"></div> <div class="clearfix"></div>
<script> <script>
// Abilitazione dinamica delle colonne
$("input[name=visibile]").change(function() {
let panel = $(this).closest(".panel[data-id]");
let id = panel.data("id");
// Aggiornamento effettivo
$.post(globals.rootdir + "/actions.php", {
id_module: "'.$modulo_viste->id.'",
id_record: "'.$id_module.'",
op: "update_visible",
id_vista: id,
visible: $(this).is(":checked") ? 1 : 0,
});
// Aggiornamento grafico
let text = panel.find("span");
if ($(this).is(":checked")) {
text.removeClass("text-danger")
.addClass("text-success");
} else {
text.removeClass("text-success")
.addClass("text-danger");
}
});
// Ricaricamento della pagina alla chiusura
$("#modals > div button.close").on("click", function() {
location.reload();
});
// Ordinamento dinamico delle colonne
$(document).ready(function() { $(document).ready(function() {
$(".sortable").disableSelection(); $(".sortable").disableSelection();
$(".sortable").each(function() { $(".sortable").each(function() {
@ -47,8 +72,8 @@ echo '
$.post(globals.rootdir + "/actions.php", { $.post(globals.rootdir + "/actions.php", {
id: ui.item.data("id"), id: ui.item.data("id"),
id_module: '.$modulo_viste->id.', id_module: "'.$modulo_viste->id.'",
id_record: '.$id_module.', id_record: "'.$id_module.'",
op: "update_position", op: "update_position",
order: order.join(","), order: order.join(","),
}); });

View File

@ -156,5 +156,13 @@ switch (filter('op')) {
$dbo->query('UPDATE `zz_views` SET `order` = '.prepare($i).' WHERE id='.prepare($id_riga)); $dbo->query('UPDATE `zz_views` SET `order` = '.prepare($i).' WHERE id='.prepare($id_riga));
} }
break;
case 'update_visible':
$visible = filter('visible');
$id_riga = filter('id_vista');
$dbo->query('UPDATE `zz_views` SET `visible` = '.prepare($visible).' WHERE id = '.prepare($id_riga));
break; break;
} }