98 lines
3.1 KiB
JavaScript
98 lines
3.1 KiB
JavaScript
function showSendModal() {
|
|
document.getElementById('notificationModal').style.display = 'flex';
|
|
}
|
|
|
|
function closeModal() {
|
|
document.getElementById('notificationModal').style.display = 'none';
|
|
}
|
|
|
|
function sendNotification() {
|
|
const form = document.getElementById('notificationForm');
|
|
const formData = new FormData(form);
|
|
const btn = document.querySelector('#notificationModal .btn-primary');
|
|
btn.disabled = true;
|
|
btn.innerHTML = '<i class="fas fa-spinner fa-spin"></i> Sending...';
|
|
|
|
fetch('/admin/notifications/send', {
|
|
method: 'POST',
|
|
headers: {
|
|
'X-CSRF-Token': document.querySelector('meta[name="csrf-token"]')?.content || '',
|
|
},
|
|
body: new URLSearchParams(formData),
|
|
})
|
|
.then(r => r.json())
|
|
.then(data => {
|
|
if (data.success) {
|
|
showToast('success', data.message);
|
|
setTimeout(() => location.reload(), 1000);
|
|
} else {
|
|
showToast('error', data.message);
|
|
}
|
|
closeModal();
|
|
btn.disabled = false;
|
|
btn.innerHTML = '<i class="fas fa-paper-plane"></i> Send';
|
|
})
|
|
.catch(() => {
|
|
showToast('error', 'Failed to send notification');
|
|
btn.disabled = false;
|
|
btn.innerHTML = '<i class="fas fa-paper-plane"></i> Send';
|
|
});
|
|
}
|
|
|
|
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/' + deleteId + '/delete', {
|
|
method: 'POST',
|
|
headers: {
|
|
'Content-Type': 'application/x-www-form-urlencoded',
|
|
'X-CSRF-Token': csrf,
|
|
},
|
|
body: '_csrf_token=' + encodeURIComponent(csrf),
|
|
})
|
|
.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');
|
|
closeDeleteModal();
|
|
});
|
|
}
|
|
|
|
function confirmResend(id) {
|
|
const csrf = document.querySelector('meta[name="csrf-token"]')?.content || '';
|
|
fetch('/admin/notifications/' + id + '/resend', {
|
|
method: 'POST',
|
|
headers: {
|
|
'Content-Type': 'application/x-www-form-urlencoded',
|
|
'X-CSRF-Token': csrf,
|
|
},
|
|
body: '_csrf_token=' + encodeURIComponent(csrf),
|
|
})
|
|
.then(r => r.json())
|
|
.then(data => {
|
|
showToast(data.success ? 'success' : 'error', data.message);
|
|
})
|
|
.catch(() => showToast('error', 'Failed to resend notification'));
|
|
}
|