Add Syllabus (Ders Programı) with station filtering and weekly auto-refresh
This commit is contained in:
parent
8acc77e441
commit
d0fd394fbd
10 changed files with 1196 additions and 3 deletions
106
public/js/syllabus.js
Normal file
106
public/js/syllabus.js
Normal file
|
|
@ -0,0 +1,106 @@
|
|||
document.addEventListener('DOMContentLoaded', () => {
|
||||
const stationPills = document.getElementById('stationPills');
|
||||
const viewTogglePills = document.getElementById('viewTogglePills');
|
||||
const dayTabs = document.getElementById('dayTabs');
|
||||
const dayViewContainer = document.getElementById('dayViewContainer');
|
||||
const weekViewContainer = document.getElementById('weekViewContainer');
|
||||
const btnSyncSyllabus = document.getElementById('btnSyncSyllabus');
|
||||
const syllabusAlert = document.getElementById('syllabusAlert');
|
||||
|
||||
// 1. Station Pill Selection (AJAX)
|
||||
if (stationPills) {
|
||||
stationPills.addEventListener('click', async (e) => {
|
||||
const btn = e.target.closest('.station-btn');
|
||||
if (!btn) return;
|
||||
|
||||
const station = btn.dataset.station;
|
||||
stationPills.querySelectorAll('.station-btn').forEach(b => b.classList.remove('active'));
|
||||
btn.classList.add('active');
|
||||
|
||||
try {
|
||||
const res = await fetch('/api/syllabus/station', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ station })
|
||||
});
|
||||
const data = await res.json();
|
||||
if (data.success) {
|
||||
// Fast reload to render both day & week grids accurately
|
||||
window.location.reload();
|
||||
}
|
||||
} catch (err) {
|
||||
console.error('Failed to change station:', err);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// 2. View Toggle (Day View vs Full Week Grid)
|
||||
if (viewTogglePills) {
|
||||
viewTogglePills.addEventListener('click', (e) => {
|
||||
const btn = e.target.closest('.view-btn');
|
||||
if (!btn) return;
|
||||
|
||||
const viewMode = btn.dataset.view;
|
||||
viewTogglePills.querySelectorAll('.view-btn').forEach(b => b.classList.remove('active'));
|
||||
btn.classList.add('active');
|
||||
|
||||
if (viewMode === 'day') {
|
||||
if (dayViewContainer) dayViewContainer.classList.remove('hidden');
|
||||
if (weekViewContainer) weekViewContainer.classList.add('hidden');
|
||||
} else {
|
||||
if (dayViewContainer) dayViewContainer.classList.add('hidden');
|
||||
if (weekViewContainer) weekViewContainer.classList.remove('hidden');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// 3. Day Tabs Switching
|
||||
if (dayTabs) {
|
||||
dayTabs.addEventListener('click', (e) => {
|
||||
const btn = e.target.closest('.day-tab-btn');
|
||||
if (!btn) return;
|
||||
|
||||
const dayNumber = btn.dataset.day;
|
||||
dayTabs.querySelectorAll('.day-tab-btn').forEach(b => b.classList.remove('active'));
|
||||
btn.classList.add('active');
|
||||
|
||||
// Hide all panels, show target panel
|
||||
document.querySelectorAll('.day-schedule-panel').forEach(p => p.classList.add('hidden'));
|
||||
const activePanel = document.getElementById(`panelDay${dayNumber}`);
|
||||
if (activePanel) activePanel.classList.remove('hidden');
|
||||
});
|
||||
}
|
||||
|
||||
// 4. Sync Syllabus
|
||||
if (btnSyncSyllabus) {
|
||||
btnSyncSyllabus.addEventListener('click', async () => {
|
||||
btnSyncSyllabus.disabled = true;
|
||||
btnSyncSyllabus.textContent = 'Syncing...';
|
||||
showAlert('Fetching weekly timetable across all 5 days...', 'info');
|
||||
|
||||
try {
|
||||
const res = await fetch('/api/syllabus/sync', { method: 'POST' });
|
||||
const data = await res.json();
|
||||
if (data.success) {
|
||||
showAlert('Syllabus updated successfully!', 'info');
|
||||
window.location.reload();
|
||||
} else {
|
||||
showAlert(`Sync failed: ${data.error}`, 'danger');
|
||||
btnSyncSyllabus.disabled = false;
|
||||
btnSyncSyllabus.textContent = 'Sync Syllabus';
|
||||
}
|
||||
} catch (err) {
|
||||
showAlert('Network error while syncing syllabus.', 'danger');
|
||||
btnSyncSyllabus.disabled = false;
|
||||
btnSyncSyllabus.textContent = 'Sync Syllabus';
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function showAlert(msg, type = 'info') {
|
||||
if (!syllabusAlert) return;
|
||||
syllabusAlert.className = `alert alert-${type}`;
|
||||
syllabusAlert.textContent = msg;
|
||||
syllabusAlert.classList.remove('hidden');
|
||||
}
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue