working UGC content upload with multi-upload support
This commit is contained in:
@@ -135,6 +135,29 @@
|
||||
document.getElementById('tab-' + btn.dataset.tab).classList.add('active');
|
||||
});
|
||||
});
|
||||
|
||||
// Gallery deletion without a page reload, behind a confirmation dialog.
|
||||
document.querySelectorAll('.gallery-delete').forEach(link => {
|
||||
link.addEventListener('click', (e) => {
|
||||
e.preventDefault();
|
||||
if (!confirm('Delete this media? This cannot be undone.')) return;
|
||||
const xhr = new XMLHttpRequest();
|
||||
xhr.open('POST', link.getAttribute('href'));
|
||||
xhr.setRequestHeader('X-CSRFToken', getCookie('csrftoken'));
|
||||
xhr.onload = function () {
|
||||
if (xhr.status === 200) {
|
||||
const figure = link.closest('figure.gallery-item');
|
||||
if (figure) figure.remove();
|
||||
} else {
|
||||
alert('Could not delete media.');
|
||||
}
|
||||
};
|
||||
xhr.onerror = function () {
|
||||
alert('Network error while deleting media.');
|
||||
};
|
||||
xhr.send();
|
||||
});
|
||||
});
|
||||
})();
|
||||
</script>
|
||||
{% endblock %}
|
||||
|
||||
Reference in New Issue
Block a user