",
{
href: $(this).attr("rel"),
download: $(this).val()
})
.appendTo("body")
.get(0)
.click();
e.preventDefault();
});
if(callback && typeof(callback) === "function") callback(callback_parametri[0], callback_parametri[1], callback_parametri[2], callback_parametri[3]);
//if(file_gestione=="clienti_sedi_operative" && idsede_operativa!=0 && sezione_documento!="") contenuti('#clienti_sedi_operative', '', idsede_operativa, sezione_documento);
}
else
{
$("#messaggio").fadeIn("fast").html('
× '+risposta_array[1]+'
');
}
}
});
});
}
function update(event, tabella, callback, callback_parametri)
{
if(tabella===undefined) tabella=sezione;
//var form = $('form')[0]; // You need to use standard javascript object here
//var formData = new FormData(form);
form="#"+$(event).closest('form').attr('id');
var formData = new FormData($(form)[0]);
if($('.summernote').length) formData.append('testo', encodeURIComponent($('.summernote').summernote('code')));
//console.log(form_elementi);
Pace.track(function ()
{
$.ajax(
{
type: "POST",
url: tabella+".gestione.php",
data: formData,
dataType: "html",
contentType: false,
processData: false,
success: function(risposta)
{
//console.log(risposta);
var risposta_array = risposta.split("|");
if(risposta_array[0]=="0")
{
$(form+" #iddasalvare").val(risposta_array[2]);
$("#messaggio").fadeIn("fast").html('× '+risposta_array[1]+'
');
setTimeout(function() { $("#messaggio").fadeOut(); }, 5000);
//setTimeout(function() { clearInterval(intID); }, 10000);
//Ricordarsi di passare tutti i callback_parametri necessari al funzionamento della funzione callback
if(callback && typeof(callback) === "function")
{
if(tabella=="clienti" || tabella=="clienti_cessati")
{
callback(callback_parametri[0], callback_parametri[1], risposta_array[2], callback_parametri[3]);
}
else if(tabella=="clienti_sedi_operative")
{
callback(callback_parametri[0], callback_parametri[1], callback_parametri[2], callback_parametri[3]);
}
else if(tabella=="clienti_sedi_operative_sorveglianza_sanitaria" || tabella=="clienti_sedi_operative_verbali_consegna_dpi" || tabella=="clienti_sedi_operative_rappresentante_lavoratori" || tabella=="clienti_sedi_operative_dichiarazione_oggetto_provvedimenti")
{
callback(callback_parametri[0], $(form+" #iddasalvare").val());
}
else if(tabella=="clienti_sedi_operative_informazione_lavoratori" || tabella=="clienti_sedi_operative_nomina_rspp" || tabella=="clienti_sedi_operative_gestione_emergenze" || tabella=="clienti_sedi_operative_organigramma")
{
callback(callback_parametri[0], $(form+" #iddasalvare").val(), callback_parametri[1]);
}
else if(tabella=="cliente_dashboard")
{
callback(callback_parametri[0], callback_parametri[1], callback_parametri[2], callback_parametri[3]);
}
}
}
else
{
$("#messaggio").fadeIn("fast").html('× '+risposta_array[1]+'
');
}
}
});
});
}
//target: dove visualizzare i contenuti
//id: id dell'elemento da eliminare
//file_gestione: nome del file senza '.gestione.php' che effettua l'eliminazione
//idassociato: id per filtrare gli elementi legati a quell'id, es. moduli legati ai corsi
//callback: funzione da chiamare in callback
//callback_parametri: parametri della funzione callback
function elimina(target, id, file_gestione, idassociato, callback, callback_parametri, callback2, callback2_parametri)
{
if(confirm("Procedere con la cancellazione?"))
{
if(idassociato===undefined) idassociato=0;
var dati="action=delete&id="+id;
Pace.track(function ()
{
$.ajax(
{
type: "POST",
url: file_gestione+".gestione.php",
data: dati,
dataType: "html",
success: function(risposta)
{
var risposta_array = risposta.split("|");
if(risposta_array[0]=="0")
{
//contenuti(target, '× '+risposta_array[1]+'
', idassociato, file_gestione);
if(callback && typeof(callback) === "function") callback(callback_parametri[0], '× '+risposta_array[1]+'
', callback_parametri[2], callback_parametri[3]);
if(callback2 && typeof(callback2) === "function") callback2(callback2_parametri[0], '× '+risposta_array[1]+'
', callback2_parametri[2], callback2_parametri[3]);
}
else
{
$("#messaggio").fadeIn("fast").html('× '+risposta_array[1]+'
');
}
}
});
});
}
}
// Inizializzazione DataTable
function inizializza_DataTable(tabella)
{
if($('th.defaultSort').index()!=-1) defaultSort=$('th.defaultSort').index();
else defaultSort=0;
sorting="asc";
button_aggiungi="Nuovo";
tabella.DataTable(
{
"autoWidth": false,
"responsive": true,
"columnDefs": [
{
"orderable": false,
"targets": ['nosort']
},
{
"width": 50,
"targets": ['control']
},
{
"width": 100,
"targets": -1
}
],
"dom": '<"datatable-header"fBl><"datatable-scroll"t><"datatable-footer"ip>',
buttons: [
{
text: button_aggiungi,
className: 'btn bg-teal-400',
attr:
{
onclick: tabella.closest(".card").find("#hidden_button_aggiungi").val()
}
}
],
"language": {
"sEmptyTable": "Nessun dato presente nella tabella",
"sInfo": "Vista da _START_ a _END_ di _TOTAL_ elementi",
"sInfoEmpty": "Vista da 0 a 0 di 0 elementi",
"sInfoFiltered": "(filtrati da _MAX_ elementi totali)",
"sInfoPostFix": "",
"sInfoThousands": ".",
"sLengthMenu": "Visualizza _MENU_ elementi",
"sLoadingRecords": "Caricamento...",
"sProcessing": "Elaborazione...",
"sSearch": "Cerca: ",
"sZeroRecords": "La ricerca non ha portato alcun risultato.",
"oPaginate": {
"sFirst": "Inizio",
"sPrevious": "Precedente",
"sNext": "Successivo",
"sLast": "Fine"
},
"oAria": {
"sSortAscending": ": attiva per ordinare la colonna in ordine crescente",
"sSortDescending": ": attiva per ordinare la colonna in ordine decrescente"
}
},
order: [ [ defaultSort, sorting ] ]
});
}
// Inizializzazione DataTable Fine
// Upload immagine Summernote
function uploadImageContent(image, editor)
{
var data = new FormData();
data.append("image", image);
Pace.track(function ()
{
$.ajax(
{
url: "uploadImageContent.php",
cache: false,
contentType: false,
processData: false,
data: data,
type: "post",
success: function(url)
{
var image = $(" ").attr("src", url);
$(editor).summernote("insertNode", image[0]);
},
error: function(data)
{
console.log(data);
}
});
});
}
// Upload immagine Summernote Fine
// Delete file Summernote
function deleteFile(src)
{
var data = new FormData();
data.append("src", src);
Pace.track(function ()
{
$.ajax(
{
url: "deleteFile.php",
cache: false,
contentType: false,
processData: false,
data: data,
type: "post",
success: function(resp)
{
},
error: function(data)
{
alert(data);
}
});
});
}
// Delete file Summernote Fine
// Galleria selezione url Summernote
function galleriaSummernote(image, editor)
{
Pace.track(function ()
{
$.ajax(
{
url: "gallery.php",
cache: false,
success: function(galleria)
{
$(".note-image-url").after(galleria);
}
});
});
}
// Galleria selezione url Summernote Fine
function rspp_elimina_modulo(source, src, modulo_tipo, idrspp)
{
if(!confirm("Procedere con la cancellazione del file?")) return false;
var data = new FormData();
data.append("action", "modulo_elimina");
data.append("id", idrspp);
data.append("src", src);
data.append("modulo_tipo", modulo_tipo);
Pace.track(function ()
{
$.ajax(
{
url: "rspp.gestione.php",
cache: false,
contentType: false,
processData: false,
data: data,
type: "post",
success: function(risposta)
{
var risposta_array = risposta.split("|");
if(risposta_array[0]=="0")
{
source.parent().html('Seleziona il file ');
$('.custom-file input').change(function (e)
{
$(this).next('.custom-file-label').html(e.target.files[0].name);
});
}
else alert(risposta_array[1]);
},
error: function(data)
{
alert(data);
}
});
});
}
function documento_elimina(file_gestione, source, src, documento, idassociato)
{
if(!confirm("Procedere con la cancellazione del file?")) return false;
var data = new FormData();
data.append("action", "documento_elimina");
data.append("id", idassociato);
data.append("src", src);
data.append("documento", documento);
Pace.track(function ()
{
$.ajax(
{
url: file_gestione,
cache: false,
contentType: false,
processData: false,
data: data,
type: "post",
success: function(risposta)
{
var risposta_array = risposta.split("|");
if(risposta_array[0]=="0")
{
source.parent().html('Seleziona il file ');
$('.custom-file input').change(function (e)
{
$(this).next('.custom-file-label').html(e.target.files[0].name);
});
}
else alert(risposta_array[1]);
},
error: function(data)
{
alert(data);
}
});
});
}
function documento_genera(file_gestione, id, x)
{
window.open(file_gestione+'?action=documento_genera&id='+id+'&x='+x, '_blank');
}