commit 12.01
This commit is contained in:
@@ -171,21 +171,53 @@
|
||||
</div>
|
||||
|
||||
<script>
|
||||
const token = localStorage.getItem('auth_token');
|
||||
const token = localStorage.getItem('token');
|
||||
|
||||
if (!token) {
|
||||
window.location.href = '/register-login.html';
|
||||
window.location.href = 'register-login.html';
|
||||
}
|
||||
|
||||
fetch('/api/admin/availabilities', {
|
||||
headers: { 'Authorization': 'Bearer ' + token }
|
||||
})
|
||||
.then(r => r.json())
|
||||
.then(data => {
|
||||
const list = document.getElementById('schedule-list');
|
||||
data.forEach(avail => {
|
||||
list.innerHTML += `<p>${avail.employee_id} — ${avail.date} ${avail.starttime} - ${avail.endtime}</p>`;
|
||||
});
|
||||
});
|
||||
window.onload = loadSchedule;
|
||||
|
||||
async function loadSchedule() {
|
||||
try {
|
||||
const res = await fetch('/api/admin/availabilities', {
|
||||
headers: { 'Authorization': `Bearer ${token}` }
|
||||
});
|
||||
|
||||
const availabilities = await res.json();
|
||||
|
||||
const list = document.getElementById('schedule-list');
|
||||
availabilities.forEach(a => {
|
||||
list.innerHTML += `
|
||||
<div>
|
||||
<p>Сотрудник: ${a.employee_id} — ${a.date} ${a.start_time}–${a.end_time} — ${a.is_available ? 'Доступен' : 'Недоступен'}</p>
|
||||
<button onclick="deleteSlot(${a.id})">Удалить</button>
|
||||
</div>
|
||||
`;
|
||||
});
|
||||
} catch (err) {
|
||||
alert('Ошибка загрузки расписания');
|
||||
}
|
||||
}
|
||||
|
||||
async function deleteSlot(id) {
|
||||
if (confirm('Удалить слот?')) {
|
||||
try {
|
||||
const res = await fetch(`/api/admin/availabilities/${id}`, {
|
||||
method: 'DELETE',
|
||||
headers: { 'Authorization': `Bearer ${token}` }
|
||||
});
|
||||
|
||||
if (res.ok) {
|
||||
alert('Слот удалён');
|
||||
window.location.reload();
|
||||
}
|
||||
} catch (err) {
|
||||
alert('Ошибка');
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
Reference in New Issue
Block a user