From ecd2c1fc0838c9765e648203260fdc590a8d2830 Mon Sep 17 00:00:00 2001 From: loviuz Date: Thu, 9 Mar 2023 18:12:38 +0100 Subject: [PATCH] Aggiunta modifica dimensione widget --- modules/stato_servizi/actions.php | 20 +++++++++++++++++ modules/stato_servizi/elenco-widget.php | 26 +++++++++++++++++++++++ src/HTMLBuilder/Manager/WidgetManager.php | 21 +++++++++--------- 3 files changed, 57 insertions(+), 10 deletions(-) diff --git a/modules/stato_servizi/actions.php b/modules/stato_servizi/actions.php index c5f233652..286085006 100755 --- a/modules/stato_servizi/actions.php +++ b/modules/stato_servizi/actions.php @@ -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'; diff --git a/modules/stato_servizi/elenco-widget.php b/modules/stato_servizi/elenco-widget.php index 8a4b499e3..68aa7b1c3 100644 --- a/modules/stato_servizi/elenco-widget.php +++ b/modules/stato_servizi/elenco-widget.php @@ -24,6 +24,7 @@ echo ' '.tr('Nome').' + '.tr('Dimensione').' '.tr('Ubicazione').' '.tr('Stato').' '.tr('Posizione').' @@ -56,6 +57,9 @@ foreach ($gruppi as $modulo => $widgets) { '.$widget['name'].(!empty($widget['help']) ? ' ' : '').' + + {[ "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'].'\"" ]} + '.( 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"); + } + }); +}); + '; diff --git a/src/HTMLBuilder/Manager/WidgetManager.php b/src/HTMLBuilder/Manager/WidgetManager.php index 3b6a4534c..643d3ce01 100755 --- a/src/HTMLBuilder/Manager/WidgetManager.php +++ b/src/HTMLBuilder/Manager/WidgetManager.php @@ -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,12 +245,10 @@ 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 = '
    '; @@ -258,11 +256,14 @@ class WidgetManager implements ManagerInterface // Aggiungo ad uno ad uno tutti i widget foreach ($widgets as $widget) { if ($widgets[0]['id_module'] == $database->fetchOne('SELECT id FROM zz_modules WHERE title = "Stato dei servizi"')['id']) { - $result .= ' -
  • '; + $result .= ' +
  • '; + } else if (empty($widget['class'])) { + $result .= ' +
  • '; } else { - $result .= ' -
  • '; + $result .= ' +
  • '; } $info = array_merge($options, [ 'id' => $widget['id'],