Caricamento checklist plugin Impianti

This commit is contained in:
MatteoPistorello 2024-04-23 17:14:56 +02:00
parent 146a36ab9e
commit 818ce3cc1e
3 changed files with 126 additions and 92 deletions

View File

@ -115,7 +115,7 @@ function saveNota(id) {
note: $("#note_" + id).val(), note: $("#note_" + id).val(),
id: id id: id
}, function() { }, function() {
alertPush(); renderMessages();
$("#note_" + id).parent().parent().parent().find(".save-nota").removeClass("btn-success"); $("#note_" + id).parent().parent().parent().find(".save-nota").removeClass("btn-success");
$("#note_" + id).parent().parent().parent().find(".save-nota").addClass("btn-default"); $("#note_" + id).parent().parent().parent().find(".save-nota").addClass("btn-default");
}); });

View File

@ -23,13 +23,13 @@ use Models\Module;
use Modules\Checklists\Check; use Modules\Checklists\Check;
$operazione = filter('op'); $operazione = filter('op');
$id_modulo_impianti = (new Module())->getByField('title', 'Impianti', Models\Locale::getPredefined()->id);
switch ($operazione) { switch ($operazione) {
case 'add_impianto': case 'add_impianto':
if (post('id_impianto')) { if (post('id_impianto')) {
$dbo->query('INSERT INTO my_impianti_interventi(idimpianto, idintervento) VALUES('.prepare(post('id_impianto')).', '.prepare($id_record).')'); $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'))); $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) { foreach ($checks_impianti as $check_impianto) {
$id_parent_new = null; $id_parent_new = null;
@ -52,7 +52,7 @@ switch ($operazione) {
break; break;
case 'update_impianto': case 'update_impianto':
$components = (array) post('componenti'); $components = (post('componenti') ? (array) post('componenti') : []);
$note = post('note'); $note = post('note');
$id_impianto = post('id_impianto'); $id_impianto = post('id_impianto');
@ -74,7 +74,6 @@ switch ($operazione) {
break; break;
case 'delete_impianto': 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'))); $dbo->query('DELETE FROM my_impianti_interventi WHERE idintervento='.prepare($id_record).' AND idimpianto = '.prepare(post('id')));
Check::deleteLinked([ Check::deleteLinked([
'id_module' => $id_module, 'id_module' => $id_module,
@ -92,5 +91,21 @@ switch ($operazione) {
flash()->info(tr('Impianto rimosso correttamente!')); 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; break;
} }

View File

@ -111,7 +111,7 @@ foreach ($impianti_collegati as $impianto) {
echo ' echo '
<tr data-id="'.$impianto['id'].'"> <tr data-id="'.$impianto['id'].'">
<td class="text-left"> <td class="text-left">
<button type="button" class="btn btn-xs btn-default '.$class.'" onclick="toggleDettagli(this)"> <button type="button" class="btn btn-xs btn-default '.$class.'" onclick="loadChecklist('.$impianto['id'].'); toggleDettagli(this);">
<i class="fa fa-'.$icon.'"></i> <i class="fa fa-'.$icon.'"></i>
</button> </button>
@ -137,11 +137,8 @@ foreach ($impianti_collegati as $impianto) {
<tr style="display: none"> <tr style="display: none">
<td colspan="7"> <td colspan="7">
<table class="table"> <table class="table">
<tbody class="sort check-impianto" data-sonof="0">'; <tbody class="sort check-impianto" data-sonof="0" id="checklist_'.$impianto['id'].'">
foreach ($checks as $check) { <span class="text-muted" id="loading-checks_'.$impianto['id'].'"><i class="fa fa-spin fa-spinner"></i> '.tr('Caricamento checklist').'...</span>
echo renderChecklist($check);
}
echo '
</tbody> </tbody>
</table> </table>
</td> </td>
@ -209,17 +206,60 @@ function updateImpianto(id) {
}); });
} }
sortable("#tab_checks .sort", { function delete_check(id){
if(confirm("Eliminare questa checklist?")){
$.post("'.$checklist_module->fileurl('ajax.php').'", {
op: "delete_check",
id: id,
}, function(){
location.reload();
});
}
}
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", axis: "y",
handle: ".handle", handle: ".handle",
cursor: "move", cursor: "move",
dropOnEmpty: true, dropOnEmpty: true,
scroll: true, scroll: true,
}); });
sortable_table = sortable("#tab_checks .sort").length; sortable_table = sortable("#tab_checks .sort").length;
for(i=0; i<sortable_table; i++){ for(i=0; i<sortable_table; i++){
sortable("#tab_checks .sort")[i].addEventListener("sortupdate", function(e) { sortable("#tab_checks .sort")[i].addEventListener("sortupdate", function(e) {
var sonof = $(this).data("sonof"); var sonof = $(this).data("sonof");
@ -231,26 +271,14 @@ for(i=0; i<sortable_table; i++){
order: order.join(","), order: order.join(","),
}); });
}); });
} }
$("textarea[name=\'note_checklist\']").keyup(function() { $("textarea[name=\'note_checklist\']").keyup(function() {
$(this).parent().parent().parent().find(".save-nota").removeClass("btn-default"); $(this).parent().parent().parent().find(".save-nota").removeClass("btn-default");
$(this).parent().parent().parent().find(".save-nota").addClass("btn-success"); $(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(){ $(".check-impianto .checkbox").click(function(){
if($(this).is(":checked")){ if($(this).is(":checked")){
$.post("'.$checklist_module->fileurl('ajax.php').'", { $.post("'.$checklist_module->fileurl('ajax.php').'", {
op: "save_checkbox", op: "save_checkbox",
@ -270,7 +298,7 @@ $(".check-impianto .checkbox").click(function(){
$(this).parent().parent().find(".verificato").text("'.tr('Verificato da _USER_ il _DATE_', [ $(this).parent().parent().find(".verificato").text("'.tr('Verificato da _USER_ il _DATE_', [
'_USER_' => $user->username, '_USER_' => $user->username,
'_DATE_' => dateFormat(date('Y-m-d')).' '.date('H:i'), '_DATE_' => dateFormat(date('Y-m-d')).' '.date('H:i'),
]).'"); ]).'");
}else{ }else{
$.post("'.$checklist_module->fileurl('ajax.php').'", { $.post("'.$checklist_module->fileurl('ajax.php').'", {
op: "remove_checkbox", op: "remove_checkbox",
@ -289,20 +317,11 @@ $(".check-impianto .checkbox").click(function(){
$(this).parent().parent().find(".verificato").addClass("hidden"); $(this).parent().parent().find(".verificato").addClass("hidden");
} }
}) })
},
function delete_check(id){ error: function() {
if(confirm("Eliminare questa checklist?")){ renderMessages();
$.post("'.$checklist_module->fileurl('ajax.php').'", {
op: "delete_check",
id: id,
}, function(){
location.reload();
});
} }
} });
function edit_check(id){
launch_modal("Modifica checklist", "'.$checklist_module->fileurl('components/edit-check.php').'?id_record="+id, 1);
} }
</script>'; </script>';