поправил паралель

This commit is contained in:
2026-04-14 11:47:29 +05:00
parent 29efe55c5b
commit 8c326ef06a
2 changed files with 20 additions and 20 deletions

View File

@@ -71,18 +71,18 @@
<div class="modal-content">
<span class="close">&times;</span>
<h3 id="modalTitle">Редактирование урока</h3>
<form id="lessonForm">
<input type="hidden" id="lessonId">
<label>Класс: <input type="text" id="className" required></label>
<label>Параллель (цифра): <input type="number" id="parallel" required></label>
<label>Предмет: <input type="text" id="subject" required></label>
<label>Учитель: <input type="text" id="teacher" required></label>
<label>Тема урока: <input type="text" id="topic"></label>
<label>Макс. мест: <input type="number" id="maxSlots" required></label>
<label>Дата: <input type="date" id="date"></label>
<label>Время: <input type="time" id="time"></label>
<button type="submit">Сохранить</button>
</form>
<form id="lessonForm">
<input type="hidden" id="lessonId">
<label>Параллель (цифра): <input type="number" id="parallel" required></label>
<label>Буква класса: <input type="text" id="classLetter" required maxlength="1" style="width: 70px;"></label>
<label>Предмет: <input type="text" id="subject" required></label>
<label>Учитель: <input type="text" id="teacher" required></label>
<label>Тема урока: <input type="text" id="topic"></label>
<label>Макс. мест: <input type="number" id="maxSlots" required></label>
<label>Дата: <input type="date" id="date" required></label>
<label>Время: <input type="time" id="time" required></label>
<button type="submit">Сохранить</button>
</form>
</div>
</div>

View File

@@ -174,18 +174,19 @@ 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) {
document.getElementById('lessonId').value = lesson.id;
document.getElementById('className').value = lesson.class_name;
document.getElementById('parallel').value = lesson.parallel;
// Извлекаем букву из class_name (например, "10А" → "А")
const match = lesson.class_name.match(/[А-Яа-я]+$/);
const classLetter = match ? match[0] : '';
document.getElementById('classLetter').value = classLetter;
document.getElementById('subject').value = lesson.subject;
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 || '';
}
@@ -198,8 +199,9 @@ 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 classLetter = document.getElementById('classLetter').value.trim();
const class_name = parallel + classLetter; // формируем полное имя класса
const subject = document.getElementById('subject').value.trim();
const teacher = document.getElementById('teacher').value.trim();
const topic = document.getElementById('topic').value;
@@ -207,9 +209,8 @@ document.getElementById('lessonForm')?.addEventListener('submit', async (e) => {
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('Пожалуйста, заполните все поля: класс, параллель, предмет, учитель, макс. мест, дата и время.');
if (!class_name || isNaN(parallel) || !classLetter || !subject || !teacher || isNaN(max_slots) || !date || !time) {
alert('Пожалуйста, заполните все поля: параллель, букву класса, предмет, учителя, макс. мест, дату и время.');
return;
}
@@ -237,7 +238,6 @@ document.getElementById('lessonForm')?.addEventListener('submit', async (e) => {
return;
}
document.getElementById('lessonModal').style.display = 'none';
// Сбрасываем фильтры, чтобы обновлённый урок точно отобразился
resetFilters();
loadLessons(getCurrentFilters());
} catch (err) {