added sweetalert

This commit is contained in:
Claudio 2026-01-29 09:03:13 +01:00
parent e4b472f0c1
commit ad68941b0d

View File

@ -363,6 +363,8 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action'])) {
<!-- Quill.js CDN -->
<link href="https://cdn.jsdelivr.net/npm/quill@2.0.2/dist/quill.snow.css" rel="stylesheet" />
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/sweetalert2@11/dist/sweetalert2.min.css">
<style>
#map {
@ -982,10 +984,13 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action'])) {
previewContainer.appendChild(wrapper);
}
function deletePhoto(btn) {
const wrapper = btn.closest('.position-relative');
async function deletePhoto(btn) {
const wrapper = btn.closest('.position-relative'); // (fix selettore)
if (!wrapper) return;
const photoId = wrapper.dataset.photoId;
// Se non c'è photoId (caso preview locale), rimuovo senza chiamare server
if (!photoId) {
wrapper.remove();
remainingPhotos++;
@ -993,14 +998,34 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action'])) {
return;
}
if (!confirm('Vuoi eliminare questa foto?')) return;
const result = await Swal.fire({
title: 'Eliminare questa foto?',
text: 'Questa azione non può essere annullata.',
icon: 'warning',
showCancelButton: true,
confirmButtonText: 'Sì, elimina',
cancelButtonText: 'Annulla',
reverseButtons: true,
focusCancel: true,
confirmButtonColor: '#dc3545'
});
if (!result.isConfirmed) return;
// piccolo loader
Swal.fire({
title: 'Eliminazione…',
allowOutsideClick: false,
allowEscapeKey: false,
didOpen: () => Swal.showLoading()
});
fetch('', {
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
},
body: 'action=delete_photo&photo_id=' + photoId
body: 'action=delete_photo&photo_id=' + encodeURIComponent(photoId)
})
.then(r => r.json())
.then(data => {
@ -1008,13 +1033,32 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action'])) {
wrapper.remove();
remainingPhotos++;
updateRemainingCount();
Swal.fire({
title: 'Eliminata!',
text: 'La foto è stata rimossa correttamente.',
icon: 'success',
timer: 1400,
showConfirmButton: false
});
} else {
alert('Errore durante l\'eliminazione');
Swal.fire({
title: 'Errore',
text: data.error || 'Errore durante leliminazione.',
icon: 'error'
});
}
})
.catch(() => alert('Errore di connessione'));
.catch(() => {
Swal.fire({
title: 'Errore di connessione',
text: 'Controlla la rete e riprova.',
icon: 'error'
});
});
}
// Eventi
if (dropzone) {
dropzone.addEventListener('click', (e) => {
@ -1221,6 +1265,8 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action'])) {
updateRemainingCount();
</script>
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>
</body>
</html>