From b313d96bfc40e358bfdbc2500c2ffa2c22bfb825 Mon Sep 17 00:00:00 2001 From: mirivlad Date: Thu, 2 Apr 2026 09:51:30 +0800 Subject: [PATCH] =?UTF-8?q?Feat:=20=D0=92=D1=8B=D0=B1=D0=BE=D1=80=20=D1=82?= =?UTF-8?q?=D0=B8=D0=BF=D0=B0=20=D0=BF=D0=BE=D0=BB=D1=83=D1=87=D0=B0=D1=82?= =?UTF-8?q?=D0=B5=D0=BB=D1=8F=20=D0=B2=20=D0=B7=D0=B0=D1=8F=D0=B2=D0=BA?= =?UTF-8?q?=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ✅ Select: Пользователь/Группа/Организация ✅ Динамическое переключение полей ✅ Валидация выбора получателя ✅ Убрано поле Организация из info блока Co-authored-by: Qwen-Coder --- .../Admin/CourseRequestController.php | 11 +- .../admin/course-requests/create.blade.php | 112 +++++++++++++----- .../admin/course-requests/show.blade.php | 1 - 3 files changed, 88 insertions(+), 36 deletions(-) diff --git a/app/Http/Controllers/Admin/CourseRequestController.php b/app/Http/Controllers/Admin/CourseRequestController.php index 2fca551..1053026 100755 --- a/app/Http/Controllers/Admin/CourseRequestController.php +++ b/app/Http/Controllers/Admin/CourseRequestController.php @@ -80,9 +80,14 @@ class CourseRequestController extends Controller DB::beginTransaction(); try { - // Берём organization_id из первого элемента или null - $firstItem = reset($items); - $organizationId = $firstItem['organization_id'] ?? null; + // Берём organization_id из ПЕРВОГО элемента у которого он есть + $organizationId = null; + foreach ($items as $item) { + if (!empty($item['organization_id'])) { + $organizationId = $item['organization_id']; + break; + } + } // Создаём заявку $courseRequest = CourseRequest::create([ diff --git a/resources/views/admin/course-requests/create.blade.php b/resources/views/admin/course-requests/create.blade.php index 793ea49..45a4869 100644 --- a/resources/views/admin/course-requests/create.blade.php +++ b/resources/views/admin/course-requests/create.blade.php @@ -79,23 +79,32 @@ - -
- - - И -
-
- - - И -
-
- - + +
+ +
- + + + + + +
@@ -127,6 +136,14 @@ let elementCounter = 0; let courseSelect = null, orgSelect = null, groupTags = null, userTags = null; let modalInitialized = false; +// Переключение полей получателей +window.toggleRecipientFields = function() { + const type = document.getElementById('element_recipient_type').value; + document.getElementById('recipient_user_field').style.display = (type === 'user') ? 'block' : 'none'; + document.getElementById('recipient_group_field').style.display = (type === 'group') ? 'block' : 'none'; + document.getElementById('recipient_organization_field').style.display = (type === 'organization') ? 'block' : 'none'; +}; + // Инициализация TomSelect при ПЕРВОМ открытии modal document.getElementById('addElementModal').addEventListener('show.bs.modal', function() { if (modalInitialized) return; @@ -217,9 +234,7 @@ document.getElementById('addElementModal').addEventListener('hidden.bs.modal', f // Добавление элемента document.getElementById('addElementBtn').addEventListener('click', function() { const courseId = courseSelect.getValue(); - const organizationId = orgSelect.getValue(); - const groupIds = groupTags.getValue() || []; - const userIds = userTags.getValue() || []; + const recipientType = document.getElementById('element_recipient_type').value; const startDate = document.getElementById('element_start_date').value; const endDate = document.getElementById('element_end_date').value; @@ -228,32 +243,65 @@ document.getElementById('addElementBtn').addEventListener('click', function() { alert('Выберите курс'); return; } + if (!recipientType) { + alert('Выберите тип получателя'); + return; + } if (!startDate) { alert('Укажите дату начала'); return; } - // Получаем названия + // Получаем выбранных получателей в зависимости от типа + let organizationId = null, organizationName = null; + let groupIds = [], groupNames = []; + let userIds = [], userNames = []; + + if (recipientType === 'user') { + userIds = userTags.getValue() || []; + if (!userIds || (Array.isArray(userIds) && userIds.length === 0)) { + alert('Выберите хотя бы одного пользователя'); + return; + } + userIds = Array.isArray(userIds) ? userIds : [userIds]; + userNames = userIds.map(id => { + const opt = userTags.options[id]; + return opt ? opt.text : 'Пользователь #' + id; + }).filter(Boolean); + } else if (recipientType === 'group') { + groupIds = groupTags.getValue() || []; + if (!groupIds || (Array.isArray(groupIds) && groupIds.length === 0)) { + alert('Выберите хотя бы одну группу'); + return; + } + groupIds = Array.isArray(groupIds) ? groupIds : [groupIds]; + groupNames = groupIds.map(id => { + const opt = groupTags.options[id]; + return opt ? opt.text : 'Группа #' + id; + }).filter(Boolean); + } else if (recipientType === 'organization') { + organizationId = orgSelect.getValue(); + if (!organizationId) { + alert('Выберите организацию'); + return; + } + const orgOption = orgSelect.options[organizationId]; + organizationName = orgOption ? orgOption.text : null; + } + const courseOption = courseSelect.options[courseId]; - const orgOption = organizationId ? orgSelect.options[organizationId] : null; // Добавляем элемент items.push({ id: elementCounter++, course_id: courseId, course_name: courseOption ? courseOption.text : 'Курс #' + courseId, - organization_id: organizationId || null, - organization_name: orgOption ? orgOption.text : null, - group_ids: Array.isArray(groupIds) ? groupIds : [groupIds], - group_names: (Array.isArray(groupIds) ? groupIds : [groupIds]).map(id => { - const opt = groupTags.options[id]; - return opt ? opt.text : 'Группа #' + id; - }).filter(Boolean), - user_ids: Array.isArray(userIds) ? userIds : [userIds], - user_names: (Array.isArray(userIds) ? userIds : [userIds]).map(id => { - const opt = userTags.options[id]; - return opt ? opt.text : 'Пользователь #' + id; - }).filter(Boolean), + organization_id: organizationId, + organization_name: organizationName, + group_ids: groupIds, + group_names: groupNames, + user_ids: userIds, + user_names: userNames, start_date: startDate, end_date: endDate || null }); diff --git a/resources/views/admin/course-requests/show.blade.php b/resources/views/admin/course-requests/show.blade.php index 6285530..add56d7 100644 --- a/resources/views/admin/course-requests/show.blade.php +++ b/resources/views/admin/course-requests/show.blade.php @@ -33,7 +33,6 @@
Информация
-
Организация: {{ $courseRequest->organization?->name ?? 'Без организации' }}
Статус: @if($courseRequest->isPending()) Ожидает