Aggiunta modifica dimensione widget

This commit is contained in:
loviuz 2023-03-09 18:12:38 +01:00
parent 86fd08124f
commit ecd2c1fc08
3 changed files with 57 additions and 10 deletions

View File

@ -29,6 +29,26 @@ use Carbon\Carbon;
$id = post('id');
switch (filter('op')) {
case 'cambia-dimensione':
$result = $dbo->update('zz_widgets', [
'class' => post('valore')
], [
'id' => post('id')
]);
echo json_encode([
'result' => $result,
]);
if ($result) {
flash()->info('Impostazione modificata con successo!');
} else {
flash()->error('Errore durante il salvataggio!');
}
break;
case 'rimuovi-modulo':
$id = filter('id');
$is_plugin = filter('tipo') == 'plugin';

View File

@ -24,6 +24,7 @@ echo '
<thead>
<tr>
<th>'.tr('Nome').'</th>
<th>'.tr('Dimensione').'</th>
<th>'.tr('Ubicazione').'</th>
<th>'.tr('Stato').'</th>
<th>'.tr('Posizione').'</th>
@ -56,6 +57,9 @@ foreach ($gruppi as $modulo => $widgets) {
'.$widget['name'].(!empty($widget['help']) ? '
<i class="tip fa fa-question-circle-o" title="'.$widget['help'].'"</i>' : '').'
</td>
<td>
{[ "type": "select", "name": "dimensione[]", "class": "widgets", "value": "'.$widget['class'].'", "values": "list=\"0\": \"'.tr('Da impostazioni').'\", \"3\": \"'.tr('Piccolo').'\", \"4\": \"'.tr('Medio').'\", \"6\": \"'.tr('Grande').'\", \"12\": \"'.tr('Molto grande').'\"", "extra": "data-id=\"'.$widget['id'].'\"" ]}
</td>
<td><small>'.(
string_starts_with($widget['location'], 'controller') ?
tr('Schermata modulo') :
@ -250,4 +254,26 @@ function spostaWidget(button) {
}
});
}
$(".widgets").on("change", function() {
$.ajax({
url: globals.rootdir + "/actions.php",
cache: false,
type: "POST",
dataType: "JSON",
data: {
op: "cambia-dimensione",
id_module: globals.id_module,
id: $(this).data("id"),
valore: $(this).val()
},
success: function(data) {
renderMessages();
},
error: function(data) {
swal("'.tr('Errore').'", "'.tr('Errore durante il salvataggio dei dati').'", "error");
}
});
});
</script>';

View File

@ -214,7 +214,7 @@ class WidgetManager implements ManagerInterface
protected function group($options)
{
$query = 'SELECT id, id_module FROM zz_widgets WHERE id_module = '.prepare($options['id_module']).' AND (|position|) AND enabled = 1 ORDER BY `order` ASC';
$query = 'SELECT id, id_module, class FROM zz_widgets WHERE id_module = '.prepare($options['id_module']).' AND (|position|) AND enabled = 1 ORDER BY `order` ASC';
// Mobile (tutti i widget a destra)
if (isMobile()) {
@ -245,13 +245,11 @@ class WidgetManager implements ManagerInterface
// Generazione del codice HTML
if (!empty($widgets)) {
$row_max = setting('Numero massimo Widget per riga');
if ($row_max > 6) {
$row_max = 6;
} elseif ($row_max < 1) {
$row_max = 1;
foreach ($widgets as $widget) {
$row_max = empty($widget['class'])? setting('Numero massimo Widget per riga') : $widget['class'];
}
$result = '
<ul class="row widget" id="widget-'.$options['position'].'" data-class="">';
@ -259,10 +257,13 @@ class WidgetManager implements ManagerInterface
foreach ($widgets as $widget) {
if ($widgets[0]['id_module'] == $database->fetchOne('SELECT id FROM zz_modules WHERE title = "Stato dei servizi"')['id']) {
$result .= '
<li class="col-sm-6 col-md-4 col-lg-5 li-widget" id="widget_'.$widget['id'].'" style="height:100% !important;" data-id="'.$widget['id'].'">';
} else {
<li class="col-sm-6 col-md-4 col-lg-'.$widget['class'].' li-widget" id="widget_'.$widget['id'].'" style="height:100% !important;" data-id="'.$widget['id'].'">';
} else if (empty($widget['class'])) {
$result .= '
<li class="col-sm-6 col-md-4 col-lg-'.intval(12 / $row_max).' li-widget" id="widget_'.$widget['id'].'" data-id="'.$widget['id'].'">';
} else {
$result .= '
<li class= "col-sm-6 col-md-4 col-lg-'.$widget['class'].' li-widget" id="widget_'.$widget['id'].'" data-id="'.$widget['id'].'">';
}
$info = array_merge($options, [
'id' => $widget['id'],