small update
This commit is contained in:
parent
2045c5e5a7
commit
0ec2b29861
@ -1,13 +1,14 @@
|
||||
var as = {};
|
||||
|
||||
as.toggleSidebar = function () {
|
||||
$(".sidebar").toggleClass('expanded');
|
||||
$(".sidebar").toggleClass("expanded");
|
||||
$("body").toggleClass("sidebar-enable"); // Permette di aggiungere uno stato globale
|
||||
};
|
||||
|
||||
as.hideNotifications = function () {
|
||||
$(".alert-notification").slideUp(600, function () {
|
||||
$(this).remove();
|
||||
})
|
||||
});
|
||||
};
|
||||
|
||||
as.updateSidebarSize = function () {
|
||||
@ -19,12 +20,14 @@ as.updateSidebarSize = function () {
|
||||
};
|
||||
|
||||
as.init = function () {
|
||||
|
||||
$.ajaxSetup({
|
||||
headers: { 'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content') }
|
||||
headers: {
|
||||
"X-CSRF-TOKEN": $('meta[name="csrf-token"]').attr("content"),
|
||||
},
|
||||
});
|
||||
|
||||
$("#sidebar-toggle").click(as.toggleSidebar);
|
||||
// Aggiunto supporto per il tasto hamburger
|
||||
$(".button-menu-mobile").click(as.toggleSidebar);
|
||||
|
||||
$('[data-toggle="tooltip"]').tooltip();
|
||||
$('[data-toggle="popover"]').popover();
|
||||
@ -34,9 +37,9 @@ as.init = function () {
|
||||
setTimeout(as.hideNotifications, 3500);
|
||||
|
||||
$("a[data-toggle=loader], button[data-toggle=loader]").click(function () {
|
||||
if ($(this).parents('form').valid()) {
|
||||
as.btn.loading($(this), $(this).data('loading-text'));
|
||||
$(this).parents('form').submit();
|
||||
if ($(this).parents("form").valid()) {
|
||||
as.btn.loading($(this), $(this).data("loading-text"));
|
||||
$(this).parents("form").submit();
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@ -326,13 +326,20 @@ while ($row = $queryPages->fetch_assoc()) {
|
||||
|
||||
<!-- Area Drag & Drop per il caricamento -->
|
||||
<div class="dropzone-container collapse" id="dropzone-<?php echo $document['document_id']; ?>">
|
||||
<div class="dropzone mb-3">
|
||||
<div class="dropzone mb-3" id="dropzone-area-<?php echo $document['document_id']; ?>">
|
||||
<div class="dz-message">
|
||||
<i class="fas fa-cloud-upload-alt"></i><br>
|
||||
Trascina qui i documenti o clicca per caricare
|
||||
Trascina qui i documenti o clicca per caricarli
|
||||
</div>
|
||||
</div>
|
||||
<div class="text-center mt-3">
|
||||
<label class="btn btn-outline-primary btn-sm">
|
||||
<i class="fas fa-camera"></i> Scatta una foto
|
||||
<input type="file" accept="image/*" capture="camera" id="cameraInput-<?php echo $document['document_id']; ?>" class="d-none" onchange="uploadFromCamera(this, '<?php echo $document['document_id']; ?>')">
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Tabella dei documenti già caricati -->
|
||||
<h6 class="mt-4">Documenti già caricati:</h6>
|
||||
<?php if (isset($loadedDocuments[$document['document_id']]) && count($loadedDocuments[$document['document_id']]) > 0) { ?>
|
||||
@ -386,19 +393,18 @@ while ($row = $queryPages->fetch_assoc()) {
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/dropzone/5.9.2/dropzone.min.js"></script>
|
||||
|
||||
<script>
|
||||
// Disabilita l'auto-discover di Dropzone
|
||||
Dropzone.autoDiscover = false;
|
||||
|
||||
// Inizializza Dropzone per ciascun documento
|
||||
<?php foreach ($documents as $section => $sectionDocuments) { ?>
|
||||
<?php foreach ($sectionDocuments as $document) { ?>
|
||||
new Dropzone("#dropzone-<?php echo $document['document_id']; ?>", {
|
||||
url: "upload-document.php", // URL per il caricamento
|
||||
paramName: "file", // Nome del campo per il file
|
||||
maxFiles: <?php echo $document['max_documents']; ?>, // Numero massimo di file
|
||||
maxFilesize: 5, // Dimensione massima del file in MB
|
||||
addRemoveLinks: true, // Permette di rimuovere i file
|
||||
acceptedFiles: "image/*,application/pdf", // Tipi di file accettati
|
||||
let dropzone_<?php echo $document['document_id']; ?> = new Dropzone("#dropzone-area-<?php echo $document['document_id']; ?>", {
|
||||
url: "upload-document.php",
|
||||
paramName: "file",
|
||||
maxFiles: <?php echo $document['max_documents']; ?>,
|
||||
maxFilesize: 5,
|
||||
addRemoveLinks: true,
|
||||
acceptedFiles: "image/*,application/pdf",
|
||||
dictDefaultMessage: "Trascina qui i file o clicca per caricarli",
|
||||
dictRemoveFile: "Rimuovi",
|
||||
previewTemplate: `
|
||||
@ -426,7 +432,6 @@ while ($row = $queryPages->fetch_assoc()) {
|
||||
let parsedResponse = typeof response === "string" ? JSON.parse(response) : response;
|
||||
|
||||
if (parsedResponse.success) {
|
||||
// Aggiungi il file alla tabella
|
||||
let tableId = "#table-<?php echo $document['document_id']; ?> tbody";
|
||||
let row = `
|
||||
<tr>
|
||||
@ -458,7 +463,7 @@ while ($row = $queryPages->fetch_assoc()) {
|
||||
title: "Errore",
|
||||
text: errorMessage || "Si è verificato un problema.",
|
||||
});
|
||||
this.removeFile(file); // Rimuovi il file in caso di errore
|
||||
this.removeFile(file);
|
||||
});
|
||||
},
|
||||
sending: function(file, xhr, formData) {
|
||||
@ -468,6 +473,67 @@ while ($row = $queryPages->fetch_assoc()) {
|
||||
});
|
||||
<?php } ?>
|
||||
<?php } ?>
|
||||
|
||||
// Funzione per caricare un file dalla fotocamera
|
||||
function uploadFromCamera(input, documentId) {
|
||||
if (input.files && input.files[0]) {
|
||||
let formData = new FormData();
|
||||
formData.append("file", input.files[0]);
|
||||
formData.append("idhome", "<?php echo $idhome; ?>");
|
||||
formData.append("document_id", documentId);
|
||||
|
||||
$.ajax({
|
||||
url: "upload-document.php",
|
||||
type: "POST",
|
||||
data: formData,
|
||||
processData: false,
|
||||
contentType: false,
|
||||
success: function(response) {
|
||||
try {
|
||||
let parsedResponse = typeof response === "string" ? JSON.parse(response) : response;
|
||||
|
||||
if (parsedResponse.success) {
|
||||
let tableId = "#table-" + documentId + " tbody";
|
||||
let row = `
|
||||
<tr>
|
||||
<td><a href="homedocuments/${parsedResponse.fileName}" target="_blank">${parsedResponse.fileName}</a></td>
|
||||
<td>${parsedResponse.uploadDate}</td>
|
||||
<td><button class="btn btn-danger btn-sm delete-document" data-id="${parsedResponse.documentId}" data-file="${parsedResponse.fileName}">Elimina</button></td>
|
||||
</tr>`;
|
||||
$(tableId).append(row);
|
||||
Swal.fire({
|
||||
icon: "success",
|
||||
title: "Caricamento completato",
|
||||
text: "La foto è stata caricata con successo.",
|
||||
timer: 1500,
|
||||
showConfirmButton: false
|
||||
});
|
||||
} else {
|
||||
Swal.fire({
|
||||
icon: "error",
|
||||
title: "Errore",
|
||||
text: parsedResponse.message || "Errore nel caricamento",
|
||||
});
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("Errore nel parsing della risposta:", error);
|
||||
Swal.fire({
|
||||
icon: "error",
|
||||
title: "Errore",
|
||||
text: "Risposta dal server non valida.",
|
||||
});
|
||||
}
|
||||
},
|
||||
error: function() {
|
||||
Swal.fire({
|
||||
icon: "error",
|
||||
title: "Errore",
|
||||
text: "Si è verificato un problema con il caricamento.",
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<script>
|
||||
|
||||
BIN
public/userportal/homedocuments/1-1738661310-CS.png
Normal file
BIN
public/userportal/homedocuments/1-1738661310-CS.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 93 KiB |
Loading…
x
Reference in New Issue
Block a user