Simplify delete confirmation to native window.confirm
Bootstrap Modal async was unreliable. Replace with synchronous window.confirm() which always works and needs no dependencies. Co-authored-by: Copilot <[email protected]>
This commit is contained in:
@@ -107,41 +107,10 @@
|
|||||||
<script src="{{ url_for('static', filename='js/bs-init.js') }}"></script>
|
<script src="{{ url_for('static', filename='js/bs-init.js') }}"></script>
|
||||||
<script src="{{ url_for('static', filename='js/theme.js') }}"></script>
|
<script src="{{ url_for('static', filename='js/theme.js') }}"></script>
|
||||||
|
|
||||||
{# ── Shared confirmation modal ─────────────────────────────────────────── #}
|
{# ── Shared confirmation helper ────────────────────────────────────────── #}
|
||||||
<div class="modal fade" id="confirm-modal" tabindex="-1" aria-labelledby="confirm-modal-label" aria-hidden="true">
|
|
||||||
<div class="modal-dialog modal-dialog-centered">
|
|
||||||
<div class="modal-content">
|
|
||||||
<div class="modal-header">
|
|
||||||
<h5 class="modal-title" id="confirm-modal-label">Confirm delete</h5>
|
|
||||||
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
|
|
||||||
</div>
|
|
||||||
<div class="modal-body" id="confirm-modal-body">Are you sure?</div>
|
|
||||||
<div class="modal-footer">
|
|
||||||
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Cancel</button>
|
|
||||||
<button type="button" class="btn btn-danger" id="confirm-modal-ok">Delete</button>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<script>
|
<script>
|
||||||
// Global helper: show confirmation modal, resolve true/false on user choice.
|
|
||||||
window.confirmDelete = function(message) {
|
window.confirmDelete = function(message) {
|
||||||
return new Promise(function(resolve) {
|
return Promise.resolve(window.confirm(message));
|
||||||
const modal = document.getElementById('confirm-modal');
|
|
||||||
document.getElementById('confirm-modal-body').textContent = message;
|
|
||||||
const bsModal = bootstrap.Modal.getOrCreate(modal);
|
|
||||||
const okBtn = document.getElementById('confirm-modal-ok');
|
|
||||||
function onOk() { cleanup(); resolve(true); }
|
|
||||||
function onHide() { cleanup(); resolve(false); }
|
|
||||||
function cleanup() {
|
|
||||||
okBtn.removeEventListener('click', onOk);
|
|
||||||
modal.removeEventListener('hidden.bs.modal', onHide);
|
|
||||||
bsModal.hide();
|
|
||||||
}
|
|
||||||
okBtn.addEventListener('click', onOk);
|
|
||||||
modal.addEventListener('hidden.bs.modal', onHide, { once: true });
|
|
||||||
bsModal.show();
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
{% block scripts %}{% endblock %}
|
{% block scripts %}{% endblock %}
|
||||||
|
|||||||
Reference in New Issue
Block a user