small update
This commit is contained in:
parent
2045c5e5a7
commit
0ec2b29861
@ -1,13 +1,14 @@
|
|||||||
var as = {};
|
var as = {};
|
||||||
|
|
||||||
as.toggleSidebar = function () {
|
as.toggleSidebar = function () {
|
||||||
$(".sidebar").toggleClass('expanded');
|
$(".sidebar").toggleClass("expanded");
|
||||||
|
$("body").toggleClass("sidebar-enable"); // Permette di aggiungere uno stato globale
|
||||||
};
|
};
|
||||||
|
|
||||||
as.hideNotifications = function () {
|
as.hideNotifications = function () {
|
||||||
$(".alert-notification").slideUp(600, function () {
|
$(".alert-notification").slideUp(600, function () {
|
||||||
$(this).remove();
|
$(this).remove();
|
||||||
})
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
as.updateSidebarSize = function () {
|
as.updateSidebarSize = function () {
|
||||||
@ -19,12 +20,14 @@ as.updateSidebarSize = function () {
|
|||||||
};
|
};
|
||||||
|
|
||||||
as.init = function () {
|
as.init = function () {
|
||||||
|
|
||||||
$.ajaxSetup({
|
$.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="tooltip"]').tooltip();
|
||||||
$('[data-toggle="popover"]').popover();
|
$('[data-toggle="popover"]').popover();
|
||||||
@ -34,9 +37,9 @@ as.init = function () {
|
|||||||
setTimeout(as.hideNotifications, 3500);
|
setTimeout(as.hideNotifications, 3500);
|
||||||
|
|
||||||
$("a[data-toggle=loader], button[data-toggle=loader]").click(function () {
|
$("a[data-toggle=loader], button[data-toggle=loader]").click(function () {
|
||||||
if ($(this).parents('form').valid()) {
|
if ($(this).parents("form").valid()) {
|
||||||
as.btn.loading($(this), $(this).data('loading-text'));
|
as.btn.loading($(this), $(this).data("loading-text"));
|
||||||
$(this).parents('form').submit();
|
$(this).parents("form").submit();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@ -326,13 +326,20 @@ while ($row = $queryPages->fetch_assoc()) {
|
|||||||
|
|
||||||
<!-- Area Drag & Drop per il caricamento -->
|
<!-- Area Drag & Drop per il caricamento -->
|
||||||
<div class="dropzone-container collapse" id="dropzone-<?php echo $document['document_id']; ?>">
|
<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">
|
<div class="dz-message">
|
||||||
<i class="fas fa-cloud-upload-alt"></i><br>
|
<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>
|
</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>
|
</div>
|
||||||
|
|
||||||
<!-- Tabella dei documenti già caricati -->
|
<!-- Tabella dei documenti già caricati -->
|
||||||
<h6 class="mt-4">Documenti già caricati:</h6>
|
<h6 class="mt-4">Documenti già caricati:</h6>
|
||||||
<?php if (isset($loadedDocuments[$document['document_id']]) && count($loadedDocuments[$document['document_id']]) > 0) { ?>
|
<?php if (isset($loadedDocuments[$document['document_id']]) && count($loadedDocuments[$document['document_id']]) > 0) { ?>
|
||||||
@ -386,54 +393,52 @@ while ($row = $queryPages->fetch_assoc()) {
|
|||||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/dropzone/5.9.2/dropzone.min.js"></script>
|
<script src="https://cdnjs.cloudflare.com/ajax/libs/dropzone/5.9.2/dropzone.min.js"></script>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
// Disabilita l'auto-discover di Dropzone
|
|
||||||
Dropzone.autoDiscover = false;
|
Dropzone.autoDiscover = false;
|
||||||
|
|
||||||
// Inizializza Dropzone per ciascun documento
|
// Inizializza Dropzone per ciascun documento
|
||||||
<?php foreach ($documents as $section => $sectionDocuments) { ?>
|
<?php foreach ($documents as $section => $sectionDocuments) { ?>
|
||||||
<?php foreach ($sectionDocuments as $document) { ?>
|
<?php foreach ($sectionDocuments as $document) { ?>
|
||||||
new Dropzone("#dropzone-<?php echo $document['document_id']; ?>", {
|
let dropzone_<?php echo $document['document_id']; ?> = new Dropzone("#dropzone-area-<?php echo $document['document_id']; ?>", {
|
||||||
url: "upload-document.php", // URL per il caricamento
|
url: "upload-document.php",
|
||||||
paramName: "file", // Nome del campo per il file
|
paramName: "file",
|
||||||
maxFiles: <?php echo $document['max_documents']; ?>, // Numero massimo di file
|
maxFiles: <?php echo $document['max_documents']; ?>,
|
||||||
maxFilesize: 5, // Dimensione massima del file in MB
|
maxFilesize: 5,
|
||||||
addRemoveLinks: true, // Permette di rimuovere i file
|
addRemoveLinks: true,
|
||||||
acceptedFiles: "image/*,application/pdf", // Tipi di file accettati
|
acceptedFiles: "image/*,application/pdf",
|
||||||
dictDefaultMessage: "Trascina qui i file o clicca per caricarli",
|
dictDefaultMessage: "Trascina qui i file o clicca per caricarli",
|
||||||
dictRemoveFile: "Rimuovi",
|
dictRemoveFile: "Rimuovi",
|
||||||
previewTemplate: `
|
previewTemplate: `
|
||||||
<div class="dz-preview dz-file-preview">
|
<div class="dz-preview dz-file-preview">
|
||||||
<div class="dz-image"><img data-dz-thumbnail /></div>
|
<div class="dz-image"><img data-dz-thumbnail /></div>
|
||||||
<div class="dz-details">
|
<div class="dz-details">
|
||||||
<div class="dz-filename"><span data-dz-name></span></div>
|
<div class="dz-filename"><span data-dz-name></span></div>
|
||||||
<div class="dz-size"><span data-dz-size></span></div>
|
<div class="dz-size"><span data-dz-size></span></div>
|
||||||
</div>
|
</div>
|
||||||
<div class="dz-progress">
|
<div class="dz-progress">
|
||||||
<span class="dz-upload" data-dz-uploadprogress></span>
|
<span class="dz-upload" data-dz-uploadprogress></span>
|
||||||
</div>
|
</div>
|
||||||
<div class="dz-error-message"><span data-dz-errormessage></span></div>
|
<div class="dz-error-message"><span data-dz-errormessage></span></div>
|
||||||
<div class="dz-success-mark">
|
<div class="dz-success-mark">
|
||||||
<i class="fas fa-check-circle"></i>
|
<i class="fas fa-check-circle"></i>
|
||||||
</div>
|
</div>
|
||||||
<div class="dz-error-mark">
|
<div class="dz-error-mark">
|
||||||
<i class="fas fa-times-circle"></i>
|
<i class="fas fa-times-circle"></i>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
`,
|
`,
|
||||||
init: function() {
|
init: function() {
|
||||||
this.on("success", function(file, response) {
|
this.on("success", function(file, response) {
|
||||||
try {
|
try {
|
||||||
let parsedResponse = typeof response === "string" ? JSON.parse(response) : response;
|
let parsedResponse = typeof response === "string" ? JSON.parse(response) : response;
|
||||||
|
|
||||||
if (parsedResponse.success) {
|
if (parsedResponse.success) {
|
||||||
// Aggiungi il file alla tabella
|
|
||||||
let tableId = "#table-<?php echo $document['document_id']; ?> tbody";
|
let tableId = "#table-<?php echo $document['document_id']; ?> tbody";
|
||||||
let row = `
|
let row = `
|
||||||
<tr>
|
<tr>
|
||||||
<td><a href="homedocuments/${parsedResponse.fileName}" target="_blank">${parsedResponse.fileName}</a></td>
|
<td><a href="homedocuments/${parsedResponse.fileName}" target="_blank">${parsedResponse.fileName}</a></td>
|
||||||
<td>${parsedResponse.uploadDate}</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>
|
<td><button class="btn btn-danger btn-sm delete-document" data-id="${parsedResponse.documentId}" data-file="${parsedResponse.fileName}">Elimina</button></td>
|
||||||
</tr>`;
|
</tr>`;
|
||||||
$(tableId).append(row);
|
$(tableId).append(row);
|
||||||
} else {
|
} else {
|
||||||
Swal.fire({
|
Swal.fire({
|
||||||
@ -458,7 +463,7 @@ while ($row = $queryPages->fetch_assoc()) {
|
|||||||
title: "Errore",
|
title: "Errore",
|
||||||
text: errorMessage || "Si è verificato un problema.",
|
text: errorMessage || "Si è verificato un problema.",
|
||||||
});
|
});
|
||||||
this.removeFile(file); // Rimuovi il file in caso di errore
|
this.removeFile(file);
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
sending: function(file, xhr, formData) {
|
sending: function(file, xhr, formData) {
|
||||||
@ -468,6 +473,67 @@ while ($row = $queryPages->fetch_assoc()) {
|
|||||||
});
|
});
|
||||||
<?php } ?>
|
<?php } ?>
|
||||||
<?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>
|
||||||
|
|
||||||
<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