added sweetalert
This commit is contained in:
parent
e4b472f0c1
commit
ad68941b0d
@ -363,6 +363,8 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action'])) {
|
|||||||
|
|
||||||
<!-- Quill.js CDN -->
|
<!-- Quill.js CDN -->
|
||||||
<link href="https://cdn.jsdelivr.net/npm/quill@2.0.2/dist/quill.snow.css" rel="stylesheet" />
|
<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>
|
<style>
|
||||||
#map {
|
#map {
|
||||||
@ -982,10 +984,13 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action'])) {
|
|||||||
previewContainer.appendChild(wrapper);
|
previewContainer.appendChild(wrapper);
|
||||||
}
|
}
|
||||||
|
|
||||||
function deletePhoto(btn) {
|
async function deletePhoto(btn) {
|
||||||
const wrapper = btn.closest('.position-relative');
|
const wrapper = btn.closest('.position-relative'); // (fix selettore)
|
||||||
|
if (!wrapper) return;
|
||||||
|
|
||||||
const photoId = wrapper.dataset.photoId;
|
const photoId = wrapper.dataset.photoId;
|
||||||
|
|
||||||
|
// Se non c'è photoId (caso preview locale), rimuovo senza chiamare server
|
||||||
if (!photoId) {
|
if (!photoId) {
|
||||||
wrapper.remove();
|
wrapper.remove();
|
||||||
remainingPhotos++;
|
remainingPhotos++;
|
||||||
@ -993,14 +998,34 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action'])) {
|
|||||||
return;
|
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('', {
|
fetch('', {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/x-www-form-urlencoded'
|
'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(r => r.json())
|
||||||
.then(data => {
|
.then(data => {
|
||||||
@ -1008,13 +1033,32 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action'])) {
|
|||||||
wrapper.remove();
|
wrapper.remove();
|
||||||
remainingPhotos++;
|
remainingPhotos++;
|
||||||
updateRemainingCount();
|
updateRemainingCount();
|
||||||
|
|
||||||
|
Swal.fire({
|
||||||
|
title: 'Eliminata!',
|
||||||
|
text: 'La foto è stata rimossa correttamente.',
|
||||||
|
icon: 'success',
|
||||||
|
timer: 1400,
|
||||||
|
showConfirmButton: false
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
alert('Errore durante l\'eliminazione');
|
Swal.fire({
|
||||||
|
title: 'Errore',
|
||||||
|
text: data.error || 'Errore durante l’eliminazione.',
|
||||||
|
icon: 'error'
|
||||||
|
});
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.catch(() => alert('Errore di connessione'));
|
.catch(() => {
|
||||||
|
Swal.fire({
|
||||||
|
title: 'Errore di connessione',
|
||||||
|
text: 'Controlla la rete e riprova.',
|
||||||
|
icon: 'error'
|
||||||
|
});
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Eventi
|
// Eventi
|
||||||
if (dropzone) {
|
if (dropzone) {
|
||||||
dropzone.addEventListener('click', (e) => {
|
dropzone.addEventListener('click', (e) => {
|
||||||
@ -1221,6 +1265,8 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action'])) {
|
|||||||
|
|
||||||
updateRemainingCount();
|
updateRemainingCount();
|
||||||
</script>
|
</script>
|
||||||
|
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>
|
||||||
|
|
||||||
</body>
|
</body>
|
||||||
|
|
||||||
</html>
|
</html>
|
||||||
Loading…
x
Reference in New Issue
Block a user