diff --git a/backend/static/js/components/chatMessageTemplates.js b/backend/static/js/components/chatMessageTemplates.js index 85a9e990..3c5b508c 100644 --- a/backend/static/js/components/chatMessageTemplates.js +++ b/backend/static/js/components/chatMessageTemplates.js @@ -223,14 +223,42 @@ export function createMessageElement(msg, options = {}) { wrap.innerHTML = `${bubble}${ava}`; } - // Принудительно загружаем видео после добавления в DOM + // Принудительно создаём и загружаем видео элементы после добавления в DOM if (msg.has_attachments && msg.attachments && msg.attachments.length > 0) { - setTimeout(() => { - const videos = wrap.querySelectorAll('video'); - videos.forEach(video => { - video.load(); - }); - }, 100); + // Находим все video placeholder'ы и заменяем их реальными элементами + const videoContainers = wrap.querySelectorAll('.attachment-item'); + msg.attachments.forEach((att, index) => { + if (att.file_type === 'video') { + const container = videoContainers[index]; + if (container) { + // Очищаем контейнер + container.innerHTML = ''; + + // Создаём video элемент программно + const video = document.createElement('video'); + video.controls = true; + video.preload = 'metadata'; + video.className = 'w-100'; + video.style.maxWidth = '400px'; + + const source = document.createElement('source'); + source.src = att.file_url; + source.type = att.mime_type; + + video.appendChild(source); + + const textDiv = document.createElement('div'); + textDiv.className = 'small text-secondary'; + textDiv.textContent = att.file_name; + + container.appendChild(video); + container.appendChild(textDiv); + + // Загружаем видео + video.load(); + } + } + }); } return wrap; diff --git a/backend/templates/communications/chat_detail.html b/backend/templates/communications/chat_detail.html index 0e2d17b8..379feeac 100644 --- a/backend/templates/communications/chat_detail.html +++ b/backend/templates/communications/chat_detail.html @@ -200,8 +200,7 @@ id="id_content" class="form-control composer-textarea" rows="1" - placeholder="Напишите сообщение…" - required> + placeholder="Напишите сообщение…"> @@ -349,10 +348,17 @@ document.addEventListener('DOMContentLoaded', function() { const textarea = document.getElementById('id_content'); const content = textarea.value.trim(); + // Проверка: должен быть либо текст, либо файлы + if (!content && selectedFiles.length === 0) { + alert('Введите текст сообщения или прикрепите файл'); + return; + } + // Если есть вложения, отправляем через API if (selectedFiles.length > 0) { const formData = new FormData(); - formData.append('content', content || 'Вложение'); + // Если текст пустой, отправляем пустую строку + formData.append('content', content || ''); selectedFiles.forEach((file, index) => { formData.append(`file_${index}`, file);