diff --git a/plugins/checks.php b/plugins/checks.php index 15c925f5d..6b0d962af 100644 --- a/plugins/checks.php +++ b/plugins/checks.php @@ -115,7 +115,7 @@ function saveNota(id) { note: $("#note_" + id).val(), id: id }, function() { - alertPush(); + renderMessages(); $("#note_" + id).parent().parent().parent().find(".save-nota").removeClass("btn-success"); $("#note_" + id).parent().parent().parent().find(".save-nota").addClass("btn-default"); }); diff --git a/plugins/impianti_intervento/actions.php b/plugins/impianti_intervento/actions.php index b70626d0f..ad67eb482 100644 --- a/plugins/impianti_intervento/actions.php +++ b/plugins/impianti_intervento/actions.php @@ -23,13 +23,13 @@ use Models\Module; use Modules\Checklists\Check; $operazione = filter('op'); +$id_modulo_impianti = (new Module())->getByField('title', 'Impianti', Models\Locale::getPredefined()->id); switch ($operazione) { case 'add_impianto': if (post('id_impianto')) { $dbo->query('INSERT INTO my_impianti_interventi(idimpianto, idintervento) VALUES('.prepare(post('id_impianto')).', '.prepare($id_record).')'); - $id_modulo_impianti = (new Module())->getByField('title', 'Impianti', Models\Locale::getPredefined()->id); $checks_impianti = $dbo->fetchArray('SELECT * FROM zz_checks WHERE id_module = '.prepare($id_modulo_impianti).' AND id_record = '.prepare(post('id_impianto'))); foreach ($checks_impianti as $check_impianto) { $id_parent_new = null; @@ -52,7 +52,7 @@ switch ($operazione) { break; case 'update_impianto': - $components = (array) post('componenti'); + $components = (post('componenti') ? (array) post('componenti') : []); $note = post('note'); $id_impianto = post('id_impianto'); @@ -74,7 +74,6 @@ switch ($operazione) { break; case 'delete_impianto': - $id_modulo_impianti = (new Module())->getByField('title', 'Impianti', Models\Locale::getPredefined()->id); $dbo->query('DELETE FROM my_impianti_interventi WHERE idintervento='.prepare($id_record).' AND idimpianto = '.prepare(post('id'))); Check::deleteLinked([ 'id_module' => $id_module, @@ -92,5 +91,21 @@ switch ($operazione) { flash()->info(tr('Impianto rimosso correttamente!')); + break; + + case 'load_checklist': + $checks = Check::where('id_module_from', $id_modulo_impianti)->where('id_record_from', post('id_impianto'))->where('id_module', $id_module)->where('id_record', $id_record)->where('id_parent', null)->get(); + + $response = ''; + foreach ($checks as $check) { + $response .= renderChecklist($check); + } + + /*echo json_encode([ + 'checklist' => $response + ]);*/ + + echo $response; + break; } diff --git a/plugins/impianti_intervento/row-impianti.php b/plugins/impianti_intervento/row-impianti.php index 2d471736b..a9d9ed0af 100644 --- a/plugins/impianti_intervento/row-impianti.php +++ b/plugins/impianti_intervento/row-impianti.php @@ -111,7 +111,7 @@ foreach ($impianti_collegati as $impianto) { echo ' - @@ -137,11 +137,8 @@ foreach ($impianti_collegati as $impianto) { - '; - foreach ($checks as $check) { - echo renderChecklist($check); - } - echo ' + + '.tr('Caricamento checklist').'...
@@ -209,88 +206,6 @@ function updateImpianto(id) { }); } -sortable("#tab_checks .sort", { - axis: "y", - handle: ".handle", - cursor: "move", - dropOnEmpty: true, - scroll: true, -}); - -sortable_table = sortable("#tab_checks .sort").length; - -for(i=0; i $(a).data("id")) - - $.post("'.$checklist_module->fileurl('ajax.php').'", { - op: "update_position", - order: order.join(","), - }); - }); -} - -$("textarea[name=\'note_checklist\']").keyup(function() { - $(this).parent().parent().parent().find(".save-nota").removeClass("btn-default"); - $(this).parent().parent().parent().find(".save-nota").addClass("btn-success"); -}); - -function saveNota(id) { - $.post("'.$checklist_module->fileurl('ajax.php').'", { - op: "save_note", - note: $("#note_" + id).val(), - id: id - }, function() { - alertPush(); - $("#note_" + id).parent().parent().parent().find(".save-nota").removeClass("btn-success"); - $("#note_" + id).parent().parent().parent().find(".save-nota").addClass("btn-default"); - }); -} - -$(".check-impianto .checkbox").click(function(){ - if($(this).is(":checked")){ - $.post("'.$checklist_module->fileurl('ajax.php').'", { - op: "save_checkbox", - id: $(this).attr("data-id"), - },function(result){ - }); - - $(this).parent().parent().find(".text").css("text-decoration", "line-through"); - - parent = $(this).attr("data-id"); - $("tr.sonof_"+parent).find("input[type=checkbox]").each(function(){ - if(!$(this).is(":checked")){ - $(this).click(); - } - }); - $(this).parent().parent().find(".verificato").removeClass("hidden"); - $(this).parent().parent().find(".verificato").text("'.tr('Verificato da _USER_ il _DATE_', [ - '_USER_' => $user->username, - '_DATE_' => dateFormat(date('Y-m-d')).' '.date('H:i'), -]).'"); - }else{ - $.post("'.$checklist_module->fileurl('ajax.php').'", { - op: "remove_checkbox", - id: $(this).attr("data-id"), - },function(result){ - }); - - $(this).parent().parent().find(".text").css("text-decoration", "none"); - - parent = $(this).attr("data-id"); - $("tr.sonof_"+parent).find("input[type=checkbox]").each(function(){ - if($(this).is(":checked")){ - $(this).click(); - } - }); - - $(this).parent().parent().find(".verificato").addClass("hidden"); - } -}) - function delete_check(id){ if(confirm("Eliminare questa checklist?")){ $.post("'.$checklist_module->fileurl('ajax.php').'", { @@ -305,4 +220,108 @@ function delete_check(id){ function edit_check(id){ launch_modal("Modifica checklist", "'.$checklist_module->fileurl('components/edit-check.php').'?id_record="+id, 1); } + +function saveNota(id) { + $.post("'.$checklist_module->fileurl('ajax.php').'", { + op: "save_note", + note: $("#note_" + id).val(), + id: id + }, function() { + renderMessages(); + $("#note_" + id).parent().parent().parent().find(".save-nota").removeClass("btn-success"); + $("#note_" + id).parent().parent().parent().find(".save-nota").addClass("btn-default"); + }); +} + +function loadChecklist(id){ + $.ajax({ + url: globals.rootdir + "/actions.php", + type: "POST", + data: { + id_module: globals.id_module, + id_plugin: '.$id_plugin.', + id_record: globals.id_record, + op: "load_checklist", + id_impianto: id, + }, + success: function (response) { + $("#loading-checks_" + id).hide(); + $("#checklist_" + id).html(response); + init(); + + sortable("#tab_checks .sort", { + axis: "y", + handle: ".handle", + cursor: "move", + dropOnEmpty: true, + scroll: true, + }); + + sortable_table = sortable("#tab_checks .sort").length; + + for(i=0; i $(a).data("id")) + + $.post("'.$checklist_module->fileurl('ajax.php').'", { + op: "update_position", + order: order.join(","), + }); + }); + } + + $("textarea[name=\'note_checklist\']").keyup(function() { + $(this).parent().parent().parent().find(".save-nota").removeClass("btn-default"); + $(this).parent().parent().parent().find(".save-nota").addClass("btn-success"); + }); + + $(".check-impianto .checkbox").click(function(){ + if($(this).is(":checked")){ + $.post("'.$checklist_module->fileurl('ajax.php').'", { + op: "save_checkbox", + id: $(this).attr("data-id"), + },function(result){ + }); + + $(this).parent().parent().find(".text").css("text-decoration", "line-through"); + + parent = $(this).attr("data-id"); + $("tr.sonof_"+parent).find("input[type=checkbox]").each(function(){ + if(!$(this).is(":checked")){ + $(this).click(); + } + }); + $(this).parent().parent().find(".verificato").removeClass("hidden"); + $(this).parent().parent().find(".verificato").text("'.tr('Verificato da _USER_ il _DATE_', [ + '_USER_' => $user->username, + '_DATE_' => dateFormat(date('Y-m-d')).' '.date('H:i'), + ]).'"); + }else{ + $.post("'.$checklist_module->fileurl('ajax.php').'", { + op: "remove_checkbox", + id: $(this).attr("data-id"), + },function(result){ + }); + + $(this).parent().parent().find(".text").css("text-decoration", "none"); + + parent = $(this).attr("data-id"); + $("tr.sonof_"+parent).find("input[type=checkbox]").each(function(){ + if($(this).is(":checked")){ + $(this).click(); + } + }); + + $(this).parent().parent().find(".verificato").addClass("hidden"); + } + }) + }, + error: function() { + renderMessages(); + } + }); +} ';