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(),
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");
});

View File

@ -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;
}

View File

@ -111,7 +111,7 @@ foreach ($impianti_collegati as $impianto) {
echo '
<tr data-id="'.$impianto['id'].'">
<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>
</button>
@ -137,11 +137,8 @@ foreach ($impianti_collegati as $impianto) {
<tr style="display: none">
<td colspan="7">
<table class="table">
<tbody class="sort check-impianto" data-sonof="0">';
foreach ($checks as $check) {
echo renderChecklist($check);
}
echo '
<tbody class="sort check-impianto" data-sonof="0" id="checklist_'.$impianto['id'].'">
<span class="text-muted" id="loading-checks_'.$impianto['id'].'"><i class="fa fa-spin fa-spinner"></i> '.tr('Caricamento checklist').'...</span>
</tbody>
</table>
</td>
@ -209,6 +206,49 @@ function updateImpianto(id) {
});
}
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",
handle: ".handle",
@ -238,18 +278,6 @@ $("textarea[name=\'note_checklist\']").keyup(function() {
$(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').'", {
@ -290,19 +318,10 @@ $(".check-impianto .checkbox").click(function(){
$(this).parent().parent().find(".verificato").addClass("hidden");
}
})
function delete_check(id){
if(confirm("Eliminare questa checklist?")){
$.post("'.$checklist_module->fileurl('ajax.php').'", {
op: "delete_check",
id: id,
}, function(){
location.reload();
},
error: function() {
renderMessages();
}
});
}
}
function edit_check(id){
launch_modal("Modifica checklist", "'.$checklist_module->fileurl('components/edit-check.php').'?id_record="+id, 1);
}
</script>';