-
Notifications
You must be signed in to change notification settings - Fork 1
/
admin.js
66 lines (63 loc) · 2.08 KB
/
admin.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
document.addEventListener('DOMContentLoaded', () => {
fetch('/pending-events')
.then(response => response.json())
.then(events => {
const tableBody = document.querySelector('#pending-events-table tbody');
tableBody.innerHTML = ''; // Clear existing rows
events.forEach(event => {
const row = document.createElement('tr');
row.innerHTML = `
<td>${event.name}</td>
<td>${event.eventName}</td>
<td>${event.date}</td>
<td>${event.startTime}</td>
<td>${event.endTime}</td>
<td>${event.type}</td>
<td><a href="${event.link}" target="_blank">${event.link}</a></td>
<td>${event.description}</td>
<td>
<button onclick="approveEvent(${event.id})">Approve</button>
<button onclick="rejectEvent(${event.id})">Reject</button>
</td>
`;
tableBody.appendChild(row);
});
});
document.getElementById('back-to-calendar-button').addEventListener('click', () => {
window.location.href = '/';
});
});
function approveEvent(eventId) {
fetch('/approve-event', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({ id: eventId }),
})
.then(response => response.json())
.then(data => {
if (data.success) {
window.location.reload();
} else {
alert('Error approving event');
}
});
}
function rejectEvent(eventId) {
fetch('/reject-event', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({ id: eventId }),
})
.then(response => response.json())
.then(data => {
if (data.success) {
window.location.reload();
} else {
alert('Error rejecting event');
}
});
}