Доделал модалку на создание занятий. Добавил поля выбора аудитории, типа и формата занятий.

This commit is contained in:
ProstoDenya01
2026-03-11 12:43:42 +03:00
parent 01ea7a8dc1
commit 0216dfaa40
2 changed files with 65 additions and 1 deletions

View File

@@ -14,6 +14,10 @@ export async function initUsers() {
const addLessonForm = document.getElementById('add-lesson-form');
const lessonGroupSelect = document.getElementById('lesson-group');
const lessonDisciplineSelect = document.getElementById('lesson-discipline');
const lessonClassroomSelect = document.getElementById('lesson-classroom');
const lessonTypeSelect = document.getElementById('lesson-type');
const lessonOnlineFormat = document.getElementById('format-online');
const lessonOfflineFormat = document.getElementById('format-offline');
const lessonUserId = document.getElementById('lesson-user-id');
const lessonDaySelect = document.getElementById('lesson-day');
const weekUpper = document.getElementById('week-upper');
@@ -24,6 +28,7 @@ export async function initUsers() {
// Переменные для хранения загруженных данных
let groups = [];
let subjects = [];
let classrooms = [];
// NEW: массивы с временными слотами
const weekdaysTimes = [
@@ -63,6 +68,15 @@ export async function initUsers() {
}
}
async function loadClassrooms() {
try {
classrooms = await api.get('/api/classrooms');
renderClassroomsOptions();
} catch (e) {
console.error('Ошибка загрузки аудиторий:', e);
}
}
// Заполнение select группами
function renderGroupOptions() {
lessonGroupSelect.innerHTML = '<option value="">Выберите группу</option>' +
@@ -75,6 +89,11 @@ export async function initUsers() {
subjects.map(s => `<option value="${s.id}">${escapeHtml(s.name)}</option>`).join('');
}
function renderClassroomsOptions() {
lessonClassroomSelect.innerHTML = '<option value="">Выберите аудиторию</option>' +
classrooms.map(c => `<option value="${c.id}">${escapeHtml(c.name)}</option>`).join('');
}
// NEW: функция обновления списка времени в зависимости от дня
function updateTimeOptions(dayValue) {
let times = [];
@@ -124,6 +143,8 @@ export async function initUsers() {
if (weekUpper) weekUpper.checked = false;
if (weekLower) weekLower.checked = false;
// NEW: сбрасываем селект времени
if (lessonOfflineFormat) lessonOfflineFormat.checked = true;
if (lessonOnlineFormat) lessonOnlineFormat.checked = false;
lessonTimeSelect.innerHTML = '<option value="">Сначала выберите день</option>';
lessonTimeSelect.disabled = true;
hideAlert('add-lesson-alert');
@@ -146,9 +167,13 @@ export async function initUsers() {
const userId = lessonUserId.value;
const groupId = lessonGroupSelect.value;
const subjectId = lessonDisciplineSelect.value;
const classroomId = lessonClassroomSelect.value;
const lessonType = lessonTypeSelect.value;
const dayOfWeek = lessonDaySelect.value;
const timeSlot = lessonTimeSelect.value; // NEW: получаем выбранное время
const lessonFormat = document.querySelector('input[name="lessonFormat"]:checked')?.value;
// Проверка обязательных полей
if (!groupId) {
showAlert('add-lesson-alert', 'Выберите группу', 'error');
@@ -158,6 +183,10 @@ export async function initUsers() {
showAlert('add-lesson-alert', 'Выберите дисциплину', 'error');
return;
}
if (!classroomId) {
showAlert('add-lesson-alert', 'Выберите аудиторию', 'error')
return;
}
if (!dayOfWeek) {
showAlert('add-lesson-alert', 'Выберите день недели', 'error');
return;
@@ -186,6 +215,9 @@ export async function initUsers() {
teacherId: parseInt(userId),
groupId: parseInt(groupId),
subjectId: parseInt(subjectId),
classroomId: parseInt(classroomId),
typeLesson: lessonType,
lessonFormat: lessonFormat,
day: dayOfWeek,
week: weekType,
time: timeSlot // передаём время
@@ -265,5 +297,5 @@ export async function initUsers() {
}
// Загружаем все данные при инициализации
await Promise.all([loadUsers(), loadGroups(), loadSubjects()]);
await Promise.all([loadUsers(), loadGroups(), loadSubjects(), loadClassrooms()]);
}