openstamanager/modules/stato_servizi/elenco-widget.php

286 lines
9.5 KiB
PHP
Raw Permalink Normal View History

<?php
/*
* OpenSTAManager: il software gestionale open source per l'assistenza tecnica e la fatturazione
* Copyright (C) DevCode s.r.l.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
include_once __DIR__.'/../../core.php';
echo '
<table class="table table-hover table-sm">
<thead>
<tr>
<th>'.tr('Nome').'</th>
2023-03-09 18:12:38 +01:00
<th>'.tr('Dimensione').'</th>
<th>'.tr('Ubicazione').'</th>
<th>'.tr('Stato').'</th>
<th>'.tr('Posizione').'</th>
</tr>
</thead>';
2024-03-04 12:28:16 +01:00
$widgets = $dbo->fetchArray('SELECT
`zz_widgets`.*,
2024-04-18 17:44:05 +02:00
`zz_widgets_lang`.`title` as name,
`zz_modules_lang`.`title` AS modulo
2024-03-04 12:28:16 +01:00
FROM zz_widgets
2024-03-22 15:52:24 +01:00
LEFT JOIN `zz_widgets_lang` ON (`zz_widgets`.`id` = `zz_widgets_lang`.`id_record` AND `zz_widgets_lang`.`id_lang` = '.prepare(Models\Locale::getDefault()->id).')
2024-03-04 12:28:16 +01:00
INNER JOIN `zz_modules` ON `zz_widgets`.`id_module` = `zz_modules`.`id`
2024-03-22 15:52:24 +01:00
LEFT JOIN `zz_modules_lang` ON (`zz_modules`.`id` = `zz_modules_lang`.`id_record` AND `zz_modules_lang`.`id_lang` = '.prepare(Models\Locale::getDefault()->id).')
2024-03-04 12:28:16 +01:00
ORDER BY
`id_module` ASC, `zz_widgets`.`order` ASC');
$gruppi = collect($widgets)->groupBy('modulo');
foreach ($gruppi as $modulo => $widgets) {
echo '
<thead>
<tr>
<th colspan="4" class="text-center text-muted" >'.$modulo.'</th>
</tr>
</thead>
<tbody>';
foreach ($widgets as $widget) {
$class = $widget['enabled'] ? 'success' : 'warning';
$nome_tipo = 'widget';
echo '
<tr class="'.$class.'" data-id="'.$widget['id'].'" data-nome='.json_encode($widget['name']).'>
<td>
'.$widget['name'].(!empty($widget['help']) ? '
<i class="tip fa fa-question-circle-o" title="'.$widget['help'].'"</i>' : '').'
</td>
2023-03-09 18:12:38 +01:00
<td>
2023-03-09 19:40:50 +01:00
{[ "type": "select", "name": "dimensione[]", "class": "widgets", "value": "'.$widget['class'].'", "values": "list=\"0\": \"'.tr('Da impostazioni').'\", \"col-md-3\": \"'.tr('Piccolo').'\", \"col-md-4\": \"'.tr('Medio').'\", \"col-md-6\": \"'.tr('Grande').'\", \"col-md-12\": \"'.tr('Molto grande').'\"", "extra": "data-id=\"'.$widget['id'].'\"" ]}
2023-03-09 18:12:38 +01:00
</td>
<td><small>'.(
2024-01-15 15:30:45 +01:00
string_starts_with($widget['location'], 'controller') ?
tr('Schermata modulo') :
tr('Schermata dettagli')
).'</small></td>
<td class="text-center">';
// Possibilità di disabilitare o abilitare il widget
if ($widget['enabled']) {
echo '
2024-05-16 18:02:50 +02:00
<div class="tip" data-widget="tooltip" title="'.tr('Questo _TYPE_ è abilitato: clicca qui per disabilitarlo', [
2024-03-22 15:52:24 +01:00
'_TYPE_' => $nome_tipo,
]).'">
2024-05-29 10:03:01 +02:00
<button type="button" class="btn btn-warning" onclick="disabilitaWidget(this)">
<i class="fa fa-power-off" title="'.tr('Disabilita').'"></i>
</button>
</div>';
} else {
echo '
2024-05-16 18:02:50 +02:00
<div class="tip" data-widget="tooltip" title="'.tr('Questo _TYPE_ è disabilitato: clicca qui per abilitarlo', [
2024-03-22 15:52:24 +01:00
'_TYPE_' => $nome_tipo,
]).'">
2024-05-29 10:03:01 +02:00
<button type="button" class="btn btn-success" onclick="abilitaWidget(this)">
<i class="fa fa-plug" title="'.tr('Abilita').'"></i>
</button>
</div>';
}
echo '
</td>
<td class="text-center">';
// Possibilità di spostare il widget
if (string_ends_with($widget['location'], 'top')) {
echo '
2024-05-16 18:02:50 +02:00
<div class="tip" data-widget="tooltip" title="'.tr('Questo widget è posizionato nella parte superiore della pagina').'">
<i class="fa fa-arrow-up" title="'.tr('Parte superiore').'"></i>
</div>
2024-05-16 18:02:50 +02:00
<div class="tip" data-widget="tooltip" title="'.tr('Clicca qui per spostare il widget nella parte laterale').'">
2024-05-29 10:03:01 +02:00
<button type="button" class="btn btn-info" onclick="spostaWidget(this)">
<i class="fa fa-arrow-right" title="'.tr('Sposta').'"></i>
</button>
</div>';
} else {
echo '
2024-05-16 18:02:50 +02:00
<div class="tip" data-widget="tooltip" title="'.tr('Clicca qui per spostare il widget nella parte superiore').'">
2024-05-29 10:03:01 +02:00
<button type="button" class="btn btn-info" onclick="spostaWidget(this)">
<i class="fa fa-arrow-up" title="'.tr('Sposta').'"></i>
</button>
</div>
2024-05-16 18:02:50 +02:00
<div class="tip" data-widget="tooltip" title="'.tr('Questo widget è posizionato nella parte laterale della pagina').'">
<i class="fa fa-arrow-right" title="'.tr('Parte laterale').'"></i>
</div>';
}
echo '
</td>
</tr>';
}
echo '
</tbody>';
}
echo '
</table>
<script>
function disabilitaWidget(button){
const riga = $(button).closest("tr");
const id = riga.data("id");
const nome = riga.data("nome");
const nome_tipo = "widget";
swal({
title: "'.tr('Disabilitare il _TYPE_?', [
2024-03-22 15:52:24 +01:00
'_TYPE_' => '" + nome_tipo + "',
]).'",
html: "'.tr('Sei sicuro di voler disabilitare il _TYPE_ _NAME_?', [
2024-03-22 15:52:24 +01:00
'_TYPE_' => '" + nome_tipo + "',
'_NAME_' => '" + nome + "',
]).'",
type: "warning",
showCancelButton: true,
confirmButtonText: "'.tr('Continua').'"
}).then(function (result) {
let restore = buttonLoading(button);
$.ajax({
url: globals.rootdir + "/actions.php",
type: "POST",
dataType: "JSON",
data: {
id_module: globals.id_module,
op: "disabilita-widget",
id: id,
},
success: function (response) {
caricaElencoWidget();
renderMessages();
},
error: function() {
buttonRestore(button, restore);
swal({
type: "error",
title: globals.translations.ajax.error.title,
text: globals.translations.ajax.error.text,
});
}
});
})
}
function abilitaWidget(button) {
const riga = $(button).closest("tr");
const id = riga.data("id");
const nome = riga.data("nome");
const nome_tipo = "widget";
swal({
title: "'.tr('Abilitare il _TYPE_?', [
2024-03-22 15:52:24 +01:00
'_TYPE_' => '" + nome_tipo + "',
]).'",
html: "'.tr('Sei sicuro di voler abilitare il _TYPE_ _NAME_?', [
2024-03-22 15:52:24 +01:00
'_TYPE_' => '" + nome_tipo + "',
'_NAME_' => '" + nome + "',
]).'",
type: "warning",
showCancelButton: true,
confirmButtonText: "'.tr('Continua').'"
}).then(function (result) {
let restore = buttonLoading(button);
$.ajax({
url: globals.rootdir + "/actions.php",
type: "POST",
dataType: "JSON",
data: {
id_module: globals.id_module,
op: "abilita-widget",
id: id,
},
success: function (response) {
caricaElencoWidget();
renderMessages();
},
error: function() {
buttonRestore(button, restore);
swal({
type: "error",
title: globals.translations.ajax.error.title,
text: globals.translations.ajax.error.text,
});
}
});
})
}
function spostaWidget(button) {
const riga = $(button).closest("tr");
const id = riga.data("id");
let restore = buttonLoading(button);
$.ajax({
url: globals.rootdir + "/actions.php",
type: "POST",
dataType: "JSON",
data: {
id_module: globals.id_module,
op: "sposta-widget",
id: id,
},
success: function (response) {
caricaElencoWidget();
renderMessages();
},
error: function() {
buttonRestore(button, restore);
swal({
type: "error",
title: globals.translations.ajax.error.title,
text: globals.translations.ajax.error.text,
});
}
});
}
2023-03-09 18:12:38 +01:00
$(".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>';