Skip to content

Commit bada2d4

Browse files
committed
feat: Ripristino checklist impianti nelle attività
1 parent af2b0e5 commit bada2d4

1 file changed

Lines changed: 66 additions & 115 deletions

File tree

plugins/impianti_intervento/row-impianti.php

Lines changed: 66 additions & 115 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
<table class="table table-hover table-sm mb-0">
5959
<thead>
6060
<tr>
61+
<th class="text-center" width="1%"></th>
6162
<th class="text-center" width="120px">'.tr('Matricola').'</th>
6263
<th>'.tr('Nome Impianto').'</th>
6364
<th class="text-center" width="100px">'.tr('Data').'</th>
@@ -104,6 +105,12 @@
104105
}
105106
echo '
106107
<tr data-id="'.$impianto['id'].'">
108+
<td class="text-left">
109+
<button type="button" class="btn btn-xs btn-default '.$class.'" onclick="toggleDettagli(this)">
110+
<i class="fa fa-'.$icon.'"></i>
111+
</button>
112+
113+
</td>
107114
<td class="text-center">
108115
<span class="badge badge-secondary">'.$impianto['matricola'].'</span>
109116
</td>
@@ -129,9 +136,20 @@
129136
<i class="fa fa-trash"></i>
130137
</button>
131138
</td>
132-
</tr>';
139+
</tr>
140+
<tr style="display: none">
141+
<td colspan="7">
142+
<table class="table">
143+
<tbody class="sort check-impianto" data-sonof="0">';
144+
foreach ($checks as $check) {
145+
echo renderChecklist($check);
146+
}
147+
echo '
148+
</tbody>
149+
</table>
150+
</td>
151+
</tr>';
133152

134-
// Checklist rimossa come richiesto
135153
}
136154
echo '
137155
</tbody>
@@ -149,6 +167,21 @@
149167
initNoteAutoSave();
150168
});
151169
170+
function toggleDettagli(trigger) {
171+
const tr = $(trigger).closest("tr");
172+
const dettagli = tr.next();
173+
174+
if (dettagli.css("display") === "none"){
175+
dettagli.show(500);
176+
$(trigger).children().removeClass("fa-plus");
177+
$(trigger).children().addClass("fa-minus");
178+
} else {
179+
dettagli.hide(500);
180+
$(trigger).children().removeClass("fa-minus");
181+
$(trigger).children().addClass("fa-plus");
182+
}
183+
}
184+
152185
// Inizializza il salvataggio automatico delle note
153186
function initNoteAutoSave() {
154187
let saveTimeout;
@@ -285,123 +318,41 @@ function saveNota(id) {
285318
});
286319
}
287320
288-
function loadChecklist(id){
289-
const $loading = $("#loading-checks_" + id);
290-
const $checklist = $("#checklist_" + id);
291-
292-
// Mostra loading e nasconde checklist esistente
293-
$loading.show();
294-
$checklist.empty();
295-
296-
$.ajax({
297-
url: globals.rootdir + "/actions.php",
298-
type: "POST",
299-
data: {
300-
id_module: globals.id_module,
301-
id_plugin: '.$id_plugin.',
302-
id_record: globals.id_record,
303-
op: "load_checklist",
304-
id_impianto: id,
305-
},
306-
success: function (response) {
307-
$loading.hide();
308-
309-
if (response && response.trim() !== "") {
310-
$checklist.html(response);
311-
init();
312-
313-
// Mostra messaggio di successo temporaneo
314-
setTimeout(function() {
315-
$checklist.prepend(\'<div class="alert alert-success alert-dismissible fade show mb-3" style="animation: fadeIn 0.5s;"><i class="fa fa-check mr-2"></i>\' + "'.tr('Checklist caricata con successo').'" + \'<button type="button" class="close" data-dismiss="alert"><span>&times;</span></button></div>\');
316-
317-
// Rimuovi automaticamente dopo 3 secondi
318-
setTimeout(function() {
319-
$checklist.find(".alert-success").fadeOut();
320-
}, 3000);
321-
}, 100);
322-
} else {
323-
$checklist.html(\'<div class="alert alert-info text-center border-0"><i class="fa fa-info-circle fa-2x mb-2 text-info"></i><h6 class="text-info">\' + "'.tr('Nessuna checklist disponibile').'" + \'</h6><p class="mb-0 text-muted">\' + "'.tr('Non sono presenti checklist per questo impianto').'" + \'</p></div>\');
324-
}
325-
326-
sortable("#tab_checks .sort", {
327-
axis: "y",
328-
handle: ".handle",
329-
cursor: "move",
330-
dropOnEmpty: true,
331-
scroll: true,
332-
});
333-
334-
sortable_table = sortable("#tab_checks .sort").length;
335-
336-
for(i=0; i<sortable_table; i++){
337-
sortable("#tab_checks .sort")[i].addEventListener("sortupdate", function(e) {
338-
339-
var sonof = $(this).data("sonof");
340-
341-
let order = $(this).find(".sonof_"+sonof+"[data-id]").toArray().map(a => $(a).data("id"))
321+
$(".checkbox").click(function(){
322+
if( $(this).is(":checked") ){
323+
var op = "save_checkbox";
324+
} else {
325+
var op = "remove_checkbox";
326+
}
342327
343-
$.post("'.$checklist_module->fileurl('ajax.php').'", {
344-
op: "update_position",
345-
order: order.join(","),
346-
});
347-
});
348-
}
328+
// Ricava l\'ID dell\'impianto: la checkbox è dentro la tabella dei dettagli
329+
// Risali fino alla riga principale che contiene la tabella dei dettagli
330+
var rigaDettagli = $(this).closest("tbody.check-impianto").closest("tr");
331+
var rigaImpianto = rigaDettagli.prev("tr[data-id]");
332+
var idImpianto = rigaImpianto.data("id");
349333
350-
$("textarea[name=\'note_checklist\']").keyup(function() {
351-
$(this).parent().parent().parent().find(".save-nota").removeClass("btn-default");
352-
$(this).parent().parent().parent().find(".save-nota").addClass("btn-success");
353-
});
354-
355-
$(".check-impianto .checkbox").click(function(){
356-
if($(this).is(":checked")){
357-
$.post("'.$checklist_module->fileurl('ajax.php').'", {
358-
op: "save_checkbox",
359-
id: $(this).attr("data-id"),
360-
},function(result){
361-
});
362-
363-
$(this).parent().parent().find(".text").css("text-decoration", "line-through");
364-
365-
parent = $(this).attr("data-id");
366-
$("tr.sonof_"+parent).find("input[type=checkbox]").each(function(){
367-
if(!$(this).is(":checked")){
368-
$(this).click();
369-
}
370-
});
371-
$(this).parent().parent().find(".verificato").removeClass("hidden");
372-
$(this).parent().parent().find(".verificato").text("'.tr('Verificato da _USER_ il _DATE_', [
373-
'_USER_' => $user->username,
374-
'_DATE_' => dateFormat(date('Y-m-d')).' '.date('H:i'),
375-
]).'");
376-
}else{
377-
$.post("'.$checklist_module->fileurl('ajax.php').'", {
378-
op: "remove_checkbox",
379-
id: $(this).attr("data-id"),
380-
},function(result){
381-
});
382-
383-
$(this).parent().parent().find(".text").css("text-decoration", "none");
384-
385-
parent = $(this).attr("data-id");
386-
$("tr.sonof_"+parent).find("input[type=checkbox]").each(function(){
387-
if($(this).is(":checked")){
388-
$(this).click();
389-
}
390-
});
391-
392-
$(this).parent().parent().find(".verificato").addClass("hidden");
334+
$.post("'.$checklist_module->fileurl('ajax.php').'", {
335+
op: op,
336+
id: $(this).attr("data-id"),
337+
}, function() {
338+
renderMessages();
339+
caricaImpianti().done(function() {
340+
// Dopo aver ricaricato gli impianti, aspetta un momento per il rendering e poi riapri i dettagli
341+
setTimeout(function() {
342+
if (idImpianto) {
343+
var rigaRicaricata = $("tr[data-id=\'" + idImpianto + "\']");
344+
var pulsanteToggle = rigaRicaricata.find("button[onclick*=\'toggleDettagli\']");
345+
if (pulsanteToggle.length > 0) {
346+
console.log("Riaprendo dettagli per impianto:", idImpianto);
347+
toggleDettagli(pulsanteToggle[0]);
348+
} else {
349+
console.log("Pulsante toggle non trovato per impianto:", idImpianto);
350+
}
393351
}
394-
})
395-
},
396-
error: function(xhr, status, error) {
397-
$loading.hide();
398-
$checklist.html(\'<div class="alert alert-danger text-center border-0"><i class="fa fa-exclamation-triangle fa-2x mb-2 text-danger"></i><h6 class="text-danger">\' + "'.tr('Errore nel caricamento').'" + \'</h6><p class="mb-2 text-muted">\' + "'.tr('Impossibile caricare la checklist per questo impianto').'" + \'</p><button class="btn btn-outline-primary btn-sm" onclick="refreshChecklist(\' + id + \')"><i class="fa fa-refresh mr-1"></i>\' + "'.tr('Riprova').'" + \'</button></div>\');
399-
400-
console.error("Errore caricamento checklist:", error);
401-
renderMessages();
402-
}
352+
}, 100); // Aspetta 100ms per il rendering completo
353+
});
403354
});
404-
}
355+
});
405356
406357
// Funzione per migliorare la ricerca
407358
function filtroImpianti() {

0 commit comments

Comments
 (0)