Fix ordinamento per colonne viste

This commit is contained in:
Luca 2018-11-12 11:52:10 +01:00
parent 1ce4a50bf9
commit d228d85d33
2 changed files with 22 additions and 20 deletions

View File

@ -163,17 +163,16 @@ switch (filter('op')) {
break; break;
case 'update_position': case 'update_position':
$start = filter('start') + 1;
$end = filter('end') + 1;
$id = filter('id');
if ($start > $end) { $orders = explode(",", $_POST['order']);
$dbo->query('UPDATE `zz_views` SET `order`=`order` + 1 WHERE `order`>='.prepare($end).' AND `order`<'.prepare($start).' AND id_module='.prepare($id_record)); $order = 0;
$dbo->query('UPDATE `zz_views` SET `order`='.prepare($end).' WHERE id='.prepare($id));
} elseif ($end != $start) { foreach ($orders as $idriga) {
$dbo->query('UPDATE `zz_views` SET `order`=`order` - 1 WHERE `order`>'.prepare($start).' AND `order`<='.prepare($end).' AND id_module='.prepare($id_record)); $dbo->query('UPDATE `zz_views` SET `order`='.prepare($order).' WHERE id='.prepare($idriga));
$dbo->query('UPDATE `zz_views` SET `order`='.prepare($end).' WHERE id='.prepare($id)); $order++;
} }
break; break;
} }

View File

@ -217,15 +217,15 @@ if (!empty($options) && $options != 'custom') {
<div class="col-md-3"> <div class="col-md-3">
<div class="panel panel-primary"> <div class="panel panel-primary">
<div class="panel-heading"> <div class="panel-heading">
<h3 class="panel-title">'.tr('Ordine di visualizzazione').'. <span class="tip pull-right" title="'.tr("Trascina per ordinare le colonne").'."><i class="fa fa-question-circle-o"></i></span></h3> <h3 class="panel-title">'.tr('Ordine di visualizzazione').' <span class="tip pull-right" title="'.tr("Trascina per ordinare le colonne").'."><i class="fa fa-question-circle-o"></i></span></h3>
</div> </div>
<div class="panel-body sortable">'; <div class="panel-body sortable">';
foreach ($fields as $field) { foreach ($fields as $field) {
echo ' echo '
<p data-id="'.$field['id'].'"> <p class="clickable" data-id="'.$field['id'].'">
<i class="fa fa-sort"></i> <i class="fa fa-sort" ></i>
'; ';
if ($field['visible']) { if ($field['visible']) {
echo '<strong class="text-success">'.$field['name'].'</strong>'; echo '<strong class="text-success">'.$field['name'].'</strong>';
@ -499,24 +499,27 @@ $(document).ready(function(){
cursor: "move", cursor: "move",
dropOnEmpty: true, dropOnEmpty: true,
scroll: true, scroll: true,
start: function(event, ui) {
ui.item.data("start", ui.item.index());
},
update: function(event, ui) { update: function(event, ui) {
$.get("'.$rootdir.'/actions.php", {
var order = "";
$("div.panel-body.sortable p[data-id]").each( function(){
order += ","+$(this).data("id");
});
order = order.replace(/^,/, "");
$.post("'.$rootdir.'/actions.php", {
id: ui.item.data("id"), id: ui.item.data("id"),
id_module: '.$id_module.', id_module: '.$id_module.',
id_record: '.$id_record.', id_record: '.$id_record.',
op: "update_position", op: "update_position",
start: ui.item.data("start"), order: order,
end: ui.item.index()
}); });
} }
}); });
}); });
}); });
</script>'; </script>';
// Fix apertura non corrisposta di un tag div // Fix apertura non corrisposta di un tag div
echo '</div>'; echo '</div>';
} }