cогласно расписания

This commit is contained in:
2026-04-13 18:06:41 +05:00
parent fe3824b9da
commit 5af0487869
3 changed files with 68 additions and 34 deletions

View File

@@ -174,6 +174,7 @@ function openLessonModal(id = null) {
document.getElementById('lessonId').value = '';
document.getElementById('modalTitle').innerText = id ? 'Редактирование урока' : 'Новый урок';
if (id) {
// Загружаем все уроки и находим нужный (можно было бы сделать отдельный запрос, но так проще)
fetch(`/api/admin/lessons`).then(res => res.json()).then(lessons => {
const lesson = lessons.find(l => l.id == id);
if (lesson) {
@@ -184,6 +185,7 @@ function openLessonModal(id = null) {
document.getElementById('teacher').value = lesson.teacher;
document.getElementById('topic').value = lesson.topic || '';
document.getElementById('maxSlots').value = lesson.max_slots;
// Заполняем дату и время, если они есть, иначе пустые строки
document.getElementById('date').value = lesson.date || '';
document.getElementById('time').value = lesson.time || '';
}
@@ -196,24 +198,51 @@ function openLessonModal(id = null) {
document.getElementById('lessonForm')?.addEventListener('submit', async (e) => {
e.preventDefault();
const id = document.getElementById('lessonId').value;
const class_name = document.getElementById('className').value.trim();
const parallel = parseInt(document.getElementById('parallel').value);
const subject = document.getElementById('subject').value.trim();
const teacher = document.getElementById('teacher').value.trim();
const topic = document.getElementById('topic').value;
const max_slots = parseInt(document.getElementById('maxSlots').value);
const date = document.getElementById('date').value;
const time = document.getElementById('time').value;
// Проверяем обязательные поля (дата и время теперь обязательны)
if (!class_name || isNaN(parallel) || !subject || !teacher || isNaN(max_slots) || !date || !time) {
alert('Пожалуйста, заполните все поля: класс, параллель, предмет, учитель, макс. мест, дата и время.');
return;
}
const payload = {
id: id || undefined,
class_name: document.getElementById('className').value,
parallel: parseInt(document.getElementById('parallel').value),
subject: document.getElementById('subject').value,
teacher: document.getElementById('teacher').value,
topic: document.getElementById('topic').value,
max_slots: parseInt(document.getElementById('maxSlots').value),
date: document.getElementById('date').value,
time: document.getElementById('time').value
class_name,
parallel,
subject,
teacher,
topic,
max_slots,
date,
time
};
await fetch('/api/admin/lessons', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(payload)
});
document.getElementById('lessonModal').style.display = 'none';
loadLessons(getCurrentFilters());
try {
const response = await fetch('/api/admin/lessons', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(payload)
});
const data = await response.json();
if (!response.ok) {
alert('Ошибка сохранения: ' + (data.error || 'Неизвестная ошибка'));
return;
}
document.getElementById('lessonModal').style.display = 'none';
// Сбрасываем фильтры, чтобы обновлённый урок точно отобразился
resetFilters();
loadLessons(getCurrentFilters());
} catch (err) {
alert('Ошибка соединения: ' + err.message);
}
});
function getCurrentFilters() {
@@ -225,6 +254,14 @@ function getCurrentFilters() {
};
}
function resetFilters() {
document.getElementById('filterClass').value = '';
document.getElementById('filterParallel').value = '';
document.getElementById('filterTeacher').value = '';
document.getElementById('filterTopic').value = '';
updateDependentFilters();
}
function setupEventListeners() {
const classSelect = document.getElementById('filterClass');
const teacherSelect = document.getElementById('filterTeacher');
@@ -244,11 +281,7 @@ function setupEventListeners() {
});
document.getElementById('resetFilters')?.addEventListener('click', () => {
document.getElementById('filterClass').value = '';
document.getElementById('filterParallel').value = '';
document.getElementById('filterTeacher').value = '';
document.getElementById('filterTopic').value = '';
updateDependentFilters();
resetFilters();
loadLessons({});
});
@@ -276,7 +309,7 @@ function setupEventListeners() {
}
});
// Импорт (теперь XLSX всегда глобально доступен)
// Импорт (XLSX)
function parseExcelToRecords(file) {
return new Promise((resolve, reject) => {
const reader = new FileReader();