Показаны различия между двумя версиями страницы.
| Следующая версия | Предыдущая версия | ||
| teams:teams [2025/06/26 10:10] – создано super | teams:teams [2025/06/26 10:28] (текущий) – super | ||
|---|---|---|---|
| Строка 1: | Строка 1: | ||
| ====== Настройка команд ====== | ====== Настройка команд ====== | ||
| + | * [[teams: | ||
| + | |||
| + | < | ||
| + | < | ||
| + | body { | ||
| + | font-family: | ||
| + | margin: 0; | ||
| + | padding: 20px; | ||
| + | background-color: | ||
| + | } | ||
| + | .container { | ||
| + | max-width: 1000px; | ||
| + | margin: 0 auto; | ||
| + | background: white; | ||
| + | padding: 20px; | ||
| + | border-radius: | ||
| + | box-shadow: 0 0 10px rgba(0, | ||
| + | } | ||
| + | h1 { | ||
| + | color: #333; | ||
| + | text-align: center; | ||
| + | } | ||
| + | .teams-list { | ||
| + | margin-bottom: | ||
| + | } | ||
| + | .team-card { | ||
| + | border: 1px solid #ddd; | ||
| + | padding: 15px; | ||
| + | margin-bottom: | ||
| + | border-radius: | ||
| + | background-color: | ||
| + | transition: all 0.3s ease; | ||
| + | } | ||
| + | .team-card: | ||
| + | box-shadow: 0 0 5px rgba(0, | ||
| + | } | ||
| + | .team-header { | ||
| + | display: flex; | ||
| + | align-items: | ||
| + | margin-bottom: | ||
| + | } | ||
| + | .team-icon { | ||
| + | width: 40px; | ||
| + | height: 40px; | ||
| + | margin-right: | ||
| + | object-fit: contain; | ||
| + | } | ||
| + | .team-name { | ||
| + | font-size: 18px; | ||
| + | font-weight: | ||
| + | flex-grow: 1; | ||
| + | } | ||
| + | .team-dates { | ||
| + | font-size: 12px; | ||
| + | color: #666; | ||
| + | margin-bottom: | ||
| + | } | ||
| + | .form-group { | ||
| + | margin-bottom: | ||
| + | } | ||
| + | label { | ||
| + | display: block; | ||
| + | margin-bottom: | ||
| + | font-weight: | ||
| + | } | ||
| + | input, textarea { | ||
| + | width: 100%; | ||
| + | padding: 8px; | ||
| + | border: 1px solid #ddd; | ||
| + | border-radius: | ||
| + | box-sizing: border-box; | ||
| + | } | ||
| + | .buttons { | ||
| + | display: flex; | ||
| + | gap: 10px; | ||
| + | margin-top: 10px; | ||
| + | } | ||
| + | button { | ||
| + | padding: 8px 15px; | ||
| + | border: none; | ||
| + | border-radius: | ||
| + | cursor: pointer; | ||
| + | font-weight: | ||
| + | } | ||
| + | .save-btn { | ||
| + | background-color: | ||
| + | color: white; | ||
| + | } | ||
| + | .cancel-btn { | ||
| + | background-color: | ||
| + | color: white; | ||
| + | } | ||
| + | .edit-btn { | ||
| + | background-color: | ||
| + | color: white; | ||
| + | } | ||
| + | .add-team-btn { | ||
| + | background-color: | ||
| + | color: white; | ||
| + | padding: 10px 20px; | ||
| + | margin-bottom: | ||
| + | } | ||
| + | .form-container { | ||
| + | display: none; | ||
| + | border: 1px solid #ddd; | ||
| + | padding: 20px; | ||
| + | margin-bottom: | ||
| + | border-radius: | ||
| + | background-color: | ||
| + | } | ||
| + | .active { | ||
| + | display: block; | ||
| + | } | ||
| + | </ | ||
| + | <div class=" | ||
| + | <button class=" | ||
| + | | ||
| + | <!-- Форма добавления новой команды --> | ||
| + | <div id=" | ||
| + | < | ||
| + | <div class=" | ||
| + | <label for=" | ||
| + | <input type=" | ||
| + | </ | ||
| + | <div class=" | ||
| + | <label for=" | ||
| + | <input type=" | ||
| + | </ | ||
| + | <div class=" | ||
| + | <label for=" | ||
| + | <input type=" | ||
| + | </ | ||
| + | <div class=" | ||
| + | <button class=" | ||
| + | <button class=" | ||
| + | </ | ||
| + | </ | ||
| + | | ||
| + | <!-- Список команд --> | ||
| + | <div class=" | ||
| + | < | ||
| + | <!-- Здесь будут отображаться команды --> | ||
| + | </ | ||
| + | </ | ||
| + | |||
| + | < | ||
| + | // Загрузка данных при открытии страницы | ||
| + | document.addEventListener(' | ||
| + | | ||
| + | // Загрузка списка команд | ||
| + | async function loadTeams() { | ||
| + | try { | ||
| + | const response = await fetch('/ | ||
| + | const data = await response.json(); | ||
| + | | ||
| + | if (data.success) { | ||
| + | renderTeams(data.data); | ||
| + | } else { | ||
| + | alert(' | ||
| + | } | ||
| + | } catch (error) { | ||
| + | console.error(' | ||
| + | alert(' | ||
| + | } | ||
| + | } | ||
| + | | ||
| + | // Отображение списка команд | ||
| + | function renderTeams(teams) { | ||
| + | const teamsList = document.getElementById(' | ||
| + | teamsList.innerHTML = '< | ||
| + | | ||
| + | if (teams.length === 0) { | ||
| + | teamsList.innerHTML += '< | ||
| + | return; | ||
| + | } | ||
| + | | ||
| + | teams.forEach(team => { | ||
| + | const teamCard = document.createElement(' | ||
| + | teamCard.className = ' | ||
| + | teamCard.id = `team-${team.id}`; | ||
| + | | ||
| + | // Если команда в режиме редактирования | ||
| + | if (team.editing) { | ||
| + | teamCard.innerHTML = ` | ||
| + | < | ||
| + | <div class=" | ||
| + | <label for=" | ||
| + | <input type=" | ||
| + | </ | ||
| + | <div class=" | ||
| + | <label for=" | ||
| + | <input type=" | ||
| + | </ | ||
| + | <div class=" | ||
| + | <label for=" | ||
| + | <input type=" | ||
| + | </ | ||
| + | <div class=" | ||
| + | <button class=" | ||
| + | <button class=" | ||
| + | </ | ||
| + | `; | ||
| + | } else { | ||
| + | // Отображение информации о команде | ||
| + | teamCard.innerHTML = ` | ||
| + | <div class=" | ||
| + | ${team.icon ? `<img src=" | ||
| + | <div class=" | ||
| + | <button class=" | ||
| + | </ | ||
| + | <div class=" | ||
| + | ${team.foundationDate ? `Дата основания: | ||
| + | Создано: | ||
| + | Обновлено: | ||
| + | </ | ||
| + | `; | ||
| + | } | ||
| + | | ||
| + | teamsList.appendChild(teamCard); | ||
| + | }); | ||
| + | } | ||
| + | | ||
| + | // Форматирование даты для отображения | ||
| + | function formatDate(dateString) { | ||
| + | if (!dateString) return 'не указано'; | ||
| + | const date = new Date(dateString); | ||
| + | return date.toLocaleDateString(' | ||
| + | } | ||
| + | | ||
| + | // Показать форму добавления | ||
| + | function showAddForm() { | ||
| + | document.getElementById(' | ||
| + | document.getElementById(' | ||
| + | } | ||
| + | | ||
| + | // Скрыть форму добавления | ||
| + | function hideAddForm() { | ||
| + | document.getElementById(' | ||
| + | // Очищаем поля формы | ||
| + | document.getElementById(' | ||
| + | document.getElementById(' | ||
| + | document.getElementById(' | ||
| + | } | ||
| + | | ||
| + | // Добавление новой команды | ||
| + | async function addTeam() { | ||
| + | const name = document.getElementById(' | ||
| + | const icon = document.getElementById(' | ||
| + | const foundationDate = document.getElementById(' | ||
| + | | ||
| + | if (!name) { | ||
| + | alert(' | ||
| + | return; | ||
| + | } | ||
| + | | ||
| + | try { | ||
| + | const response = await fetch('/ | ||
| + | method: ' | ||
| + | headers: { | ||
| + | ' | ||
| + | }, | ||
| + | body: JSON.stringify({ | ||
| + | table: ' | ||
| + | data: { | ||
| + | name: name, | ||
| + | icon: icon || null, | ||
| + | foundationDate: | ||
| + | } | ||
| + | }) | ||
| + | }); | ||
| + | | ||
| + | const data = await response.json(); | ||
| + | | ||
| + | if (data.success) { | ||
| + | alert(' | ||
| + | hideAddForm(); | ||
| + | loadTeams(); | ||
| + | } else { | ||
| + | alert(' | ||
| + | } | ||
| + | } catch (error) { | ||
| + | console.error(' | ||
| + | alert(' | ||
| + | } | ||
| + | } | ||
| + | | ||
| + | // Редактирование команды | ||
| + | function editTeam(id) { | ||
| + | // Находим карточку команды | ||
| + | const teamCard = document.getElementById(`team-${id}`); | ||
| + | if (!teamCard) return; | ||
| + | | ||
| + | // Получаем текущие данные | ||
| + | const teamName = teamCard.querySelector(' | ||
| + | const teamIcon = teamCard.querySelector(' | ||
| + | const foundationDate = teamCard.querySelector(' | ||
| + | | ||
| + | // Переводим в режим редактирования | ||
| + | teamCard.innerHTML = ` | ||
| + | < | ||
| + | <div class=" | ||
| + | <label for=" | ||
| + | <input type=" | ||
| + | </ | ||
| + | <div class=" | ||
| + | <label for=" | ||
| + | <input type=" | ||
| + | </ | ||
| + | <div class=" | ||
| + | <label for=" | ||
| + | <input type=" | ||
| + | </ | ||
| + | <div class=" | ||
| + | <button class=" | ||
| + | <button class=" | ||
| + | </ | ||
| + | `; | ||
| + | } | ||
| + | | ||
| + | // Форматирование даты для input[type=" | ||
| + | function formatDateForInput(dateString) { | ||
| + | if (!dateString) return ''; | ||
| + | const date = new Date(dateString); | ||
| + | return date.toISOString().split(' | ||
| + | } | ||
| + | | ||
| + | // Сохранение изменений команды | ||
| + | async function saveTeam(id) { | ||
| + | const name = document.getElementById(`edit-name-${id}`).value.trim(); | ||
| + | const icon = document.getElementById(`edit-icon-${id}`).value.trim(); | ||
| + | const foundationDate = document.getElementById(`edit-foundationDate-${id}`).value; | ||
| + | | ||
| + | if (!name) { | ||
| + | alert(' | ||
| + | return; | ||
| + | } | ||
| + | | ||
| + | try { | ||
| + | const response = await fetch('/ | ||
| + | method: ' | ||
| + | headers: { | ||
| + | ' | ||
| + | }, | ||
| + | body: JSON.stringify({ | ||
| + | table: ' | ||
| + | id: id, | ||
| + | data: { | ||
| + | name: name, | ||
| + | icon: icon || null, | ||
| + | foundationDate: | ||
| + | } | ||
| + | }) | ||
| + | }); | ||
| + | | ||
| + | const data = await response.json(); | ||
| + | | ||
| + | if (data.success) { | ||
| + | loadTeams(); | ||
| + | } else { | ||
| + | alert(' | ||
| + | } | ||
| + | } catch (error) { | ||
| + | console.error(' | ||
| + | alert(' | ||
| + | } | ||
| + | } | ||
| + | | ||
| + | // Отмена редактирования | ||
| + | function cancelEdit(id) { | ||
| + | loadTeams(); | ||
| + | } | ||
| + | </ | ||
| + | |||
| + | </ | ||