fix: replace confirm() with proper delete confirmation modal
This commit is contained in:
@@ -39,11 +39,27 @@ function sendNotification() {
|
||||
});
|
||||
}
|
||||
|
||||
function confirmDelete(id, title) {
|
||||
if (!confirm('Delete notification "' + title + '"? This action cannot be undone.')) return;
|
||||
let deleteId = null;
|
||||
|
||||
function showDeleteModal(id, title) {
|
||||
deleteId = id;
|
||||
document.getElementById('deleteModalTitle').textContent = '"' + title + '"';
|
||||
document.getElementById('deleteModal').style.display = 'flex';
|
||||
}
|
||||
|
||||
function closeDeleteModal() {
|
||||
deleteId = null;
|
||||
document.getElementById('deleteModal').style.display = 'none';
|
||||
}
|
||||
|
||||
function executeDelete() {
|
||||
if (!deleteId) return;
|
||||
const btn = document.getElementById('deleteConfirmBtn');
|
||||
btn.disabled = true;
|
||||
btn.innerHTML = '<i class="fas fa-spinner fa-spin"></i> Deleting...';
|
||||
|
||||
const csrf = document.querySelector('meta[name="csrf-token"]')?.content || '';
|
||||
fetch('/admin/notifications/' + id + '/delete', {
|
||||
fetch('/admin/notifications/' + deleteId + '/delete', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/x-www-form-urlencoded',
|
||||
@@ -54,9 +70,13 @@ function confirmDelete(id, title) {
|
||||
.then(r => r.json())
|
||||
.then(data => {
|
||||
showToast(data.success ? 'success' : 'error', data.message);
|
||||
closeDeleteModal();
|
||||
if (data.success) location.reload();
|
||||
})
|
||||
.catch(() => showToast('error', 'Failed to delete notification'));
|
||||
.catch(() => {
|
||||
showToast('error', 'Failed to delete notification');
|
||||
closeDeleteModal();
|
||||
});
|
||||
}
|
||||
|
||||
function confirmResend(id) {
|
||||
|
||||
@@ -74,7 +74,7 @@ $data = $notifications['data'] ?? [];
|
||||
<i class="fas fa-redo"></i>
|
||||
</button>
|
||||
<button class="btn btn-icon btn-xs" title="Delete"
|
||||
onclick="confirmDelete(<?= $note['id'] ?>, '<?= htmlspecialchars(addslashes($note['title'] ?? '')) ?>')"
|
||||
onclick="showDeleteModal(<?= $note['id'] ?>, '<?= htmlspecialchars(addslashes($note['title'] ?? '')) ?>')"
|
||||
style="color:var(--danger)">
|
||||
<i class="fas fa-trash"></i>
|
||||
</button>
|
||||
@@ -154,4 +154,29 @@ $data = $notifications['data'] ?? [];
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Delete Confirmation Modal -->
|
||||
<div class="modal" id="deleteModal" onclick="if (event.target === this) closeDeleteModal()">
|
||||
<div class="modal-dialog" style="max-width: 400px;">
|
||||
<div class="modal-header">
|
||||
<h3><i class="fas fa-trash" style="color:var(--danger);margin-right:0.5rem"></i>Delete Notification</h3>
|
||||
<button class="modal-close" onclick="closeDeleteModal()">×</button>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<p style="margin-bottom:0.5rem;font-size:0.92rem">
|
||||
Are you sure you want to delete this notification?
|
||||
</p>
|
||||
<p id="deleteModalTitle" style="font-size:0.88rem;color:var(--text-muted);background:var(--bg-tertiary);padding:0.5rem 0.75rem;border-radius:var(--radius-sm)"></p>
|
||||
<p style="margin-top:0.75rem;font-size:0.82rem;color:var(--text-muted)">
|
||||
This action cannot be undone. The notification will be removed for all users.
|
||||
</p>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button class="btn btn-secondary" onclick="closeDeleteModal()">Cancel</button>
|
||||
<button class="btn btn-danger" id="deleteConfirmBtn" onclick="executeDelete()">
|
||||
<i class="fas fa-trash"></i> Delete
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script src="/assets/js/admin-notifications.js?v=<?= asset_version() ?>"></script>
|
||||
|
||||
Reference in New Issue
Block a user