|
58 | 58 | <table class="table table-hover table-sm mb-0"> |
59 | 59 | <thead> |
60 | 60 | <tr> |
| 61 | + <th class="text-center" width="1%"></th> |
61 | 62 | <th class="text-center" width="120px">'.tr('Matricola').'</th> |
62 | 63 | <th>'.tr('Nome Impianto').'</th> |
63 | 64 | <th class="text-center" width="100px">'.tr('Data').'</th> |
|
104 | 105 | } |
105 | 106 | echo ' |
106 | 107 | <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> |
107 | 114 | <td class="text-center"> |
108 | 115 | <span class="badge badge-secondary">'.$impianto['matricola'].'</span> |
109 | 116 | </td> |
|
129 | 136 | <i class="fa fa-trash"></i> |
130 | 137 | </button> |
131 | 138 | </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>'; |
133 | 152 |
|
134 | | - // Checklist rimossa come richiesto |
135 | 153 | } |
136 | 154 | echo ' |
137 | 155 | </tbody> |
|
149 | 167 | initNoteAutoSave(); |
150 | 168 | }); |
151 | 169 |
|
| 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 | +
|
152 | 185 | // Inizializza il salvataggio automatico delle note |
153 | 186 | function initNoteAutoSave() { |
154 | 187 | let saveTimeout; |
@@ -285,123 +318,41 @@ function saveNota(id) { |
285 | 318 | }); |
286 | 319 | } |
287 | 320 |
|
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>×</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 | + } |
342 | 327 |
|
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"); |
349 | 333 |
|
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 | + } |
393 | 351 | } |
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 | + }); |
403 | 354 | }); |
404 | | -} |
| 355 | +}); |
405 | 356 |
|
406 | 357 | // Funzione per migliorare la ricerca |
407 | 358 | function filtroImpianti() { |
|
0 commit comments