haikal/templates/modal/delete_modal.html
2025-09-07 13:52:05 +03:00

84 lines
3.2 KiB
HTML

{% load i18n %}
<div class="modal fade"
id="deleteModal"
data-bs-backdrop="static"
data-bs-keyboard="false"
tabindex="-1"
aria-labelledby="deleteModalLabel"
aria-hidden="true">
<div class="modal-dialog modal-sm">
<div class="modal-content">
<div class="modal-header justify-content-between align-items-start gap-5 px-4 pt-4 pb-3 border-0">
<h4 class="mb-0 me-2 text-danger">
{{ _("Delete") }}
<i class="fas fa-exclamation-circle text-danger ms-2"></i>
</h4>
<button class="btn p-0 text-body-quaternary fs-6"
data-bs-dismiss="modal"
aria-label="Close">
<span class="fas fa-times"></span>
</button>
</div>
<div class="modal-body p-4">
<p id="deleteModalText"></p>
</div>
<div class="modal-footer flex justify-content-center border-top-0">
<a id="deleteModalConfirm"
hx-boost="true"
hx-select-oob="#notesTable:outerHTML,#toast-container:outerHTML"
hx-on::after-request="{ $('#deleteModal').modal('hide'); }"
hx-swap="none show:#notesTable"
type="button"
class="btn btn-sm btn-phoenix-danger w-100"
href="">{{ _("Delete") }}</a>
</div>
</div>
</div>
</div>
<script>
// Initialize when page loads and after HTMX swaps
document.addEventListener('DOMContentLoaded', initDeleteModals);
document.addEventListener('htmx:afterSwap', initDeleteModals);
function initDeleteModals() {
const deleteModal = document.getElementById("deleteModal");
const confirmDeleteBtn = document.getElementById("deleteModalConfirm");
const deleteModalMessage = document.getElementById("deleteModalText");
// Clean up previous listeners if any
document.querySelectorAll(".delete-btn").forEach(btn => {
btn.removeEventListener("click", handleDeleteClick);
});
// Add new listeners to all delete buttons
document.querySelectorAll(".delete-btn").forEach(button => {
button.addEventListener("click", handleDeleteClick);
});
function handleDeleteClick() {
if (!deleteModal || !confirmDeleteBtn || !deleteModalMessage) return;
const deleteUrl = this.getAttribute("data-url");
console.log(deleteUrl)
const deleteMessage = this.getAttribute("data-message") || "Are you sure you want to delete this item?";
// Update modal content
confirmDeleteBtn.setAttribute("href", deleteUrl);
deleteModalMessage.textContent = deleteMessage; // Use textContent instead of innerHTML for security
// Process with HTMX if available
if (typeof htmx !== 'undefined') {
htmx.process(confirmDeleteBtn);
}
// Show the modal
/*if (typeof bootstrap !== 'undefined') {
const modal = new bootstrap.Modal(deleteModal);
modal.show();
}*/
}
}
</script>