feat(equipe): possibilité de modifier le nom d'une équipe directement depuis la liste
This commit is contained in:
@@ -63,6 +63,17 @@ public class EquipeController {
|
||||
return "redirect:/equipes";
|
||||
}
|
||||
|
||||
@PostMapping("/equipes/{id}/update")
|
||||
public String updateEquipe(@PathVariable Long id, @RequestParam String nom) {
|
||||
Equipe equipe = equipeRepository.findById(id)
|
||||
.orElseThrow(() -> new IllegalArgumentException("Équipe invalide : " + id));
|
||||
if (nom != null && !nom.trim().isEmpty()) {
|
||||
equipe.setNom(nom.trim());
|
||||
equipeRepository.save(equipe);
|
||||
}
|
||||
return "redirect:/equipes";
|
||||
}
|
||||
|
||||
@PostMapping("/equipes/{id}/delete")
|
||||
public String deleteEquipe(@PathVariable Long id) {
|
||||
Equipe equipe = equipeRepository.findById(id)
|
||||
|
||||
@@ -67,13 +67,53 @@
|
||||
<tr th:if="${#lists.isEmpty(equipes)}">
|
||||
<td colspan="4" class="py-8 text-center text-gray-500">Aucune équipe configurée pour le moment. Usez du formulaire à gauche pour en créer une.</td>
|
||||
</tr>
|
||||
<tr th:each="team : ${equipes}" class="hover:bg-gray-50 transition-colors">
|
||||
<td class="py-4 px-6 font-medium text-gray-900" th:text="${team.nom}">Équipe 1</td>
|
||||
<tr th:each="team : ${equipes}" class="hover:bg-gray-50 transition-colors" th:id="'team-row-' + ${team.id}">
|
||||
<td class="py-4 px-6 font-medium text-gray-900">
|
||||
<!-- Affichage Normal -->
|
||||
<div th:id="'team-name-display-' + ${team.id}" class="flex items-center gap-2">
|
||||
<span th:text="${team.nom}" class="font-semibold text-gray-900">Équipe 1</span>
|
||||
<button type="button"
|
||||
th:onclick="|enableEditTeam('${team.id}')|"
|
||||
class="text-gray-400 hover:text-indigo-600 p-1 rounded transition-colors"
|
||||
title="Modifier le nom">
|
||||
<svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15.232 5.232l3.536 3.536m-2.036-5.036a2.5 2.5 0 113.536 3.536L6.5 21.036H3v-3.572L16.732 3.732z"/></svg>
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<!-- Formulaire d'édition Inline (Masqué par défaut) -->
|
||||
<form th:id="'team-name-form-' + ${team.id}"
|
||||
th:action="@{/equipes/{id}/update(id=${team.id})}"
|
||||
method="post"
|
||||
class="hidden flex items-center gap-2 m-0">
|
||||
<input type="text"
|
||||
name="nom"
|
||||
th:value="${team.nom}"
|
||||
required
|
||||
class="border border-indigo-300 rounded-lg px-3 py-1 text-sm font-medium focus:ring-2 focus:ring-indigo-500 focus:border-indigo-500 outline-none w-48 shadow-sm">
|
||||
<button type="submit"
|
||||
class="bg-indigo-600 hover:bg-indigo-700 text-white p-1.5 rounded-lg text-xs font-semibold transition-colors shadow-sm"
|
||||
title="Enregistrer">
|
||||
<svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M5 13l4 4L19 7"/></svg>
|
||||
</button>
|
||||
<button type="button"
|
||||
th:onclick="|cancelEditTeam('${team.id}')|"
|
||||
class="bg-gray-100 hover:bg-gray-200 text-gray-600 p-1.5 rounded-lg text-xs font-semibold transition-colors"
|
||||
title="Annuler">
|
||||
<svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M6 18L18 6M6 6l12 12"/></svg>
|
||||
</button>
|
||||
</form>
|
||||
</td>
|
||||
<td class="py-4 px-6 text-gray-600">
|
||||
<span class="bg-blue-50 text-blue-700 px-2.5 py-1 rounded-full text-xs font-medium" th:text="${team.categorie.nom}">U15</span>
|
||||
</td>
|
||||
<td class="py-4 px-6 text-gray-500" th:text="${team.saison.nom}">2024-2025</td>
|
||||
<td class="py-4 px-6 text-right flex justify-end items-center">
|
||||
<td class="py-4 px-6 text-right flex justify-end items-center space-x-2">
|
||||
<button type="button"
|
||||
th:onclick="|enableEditTeam('${team.id}')|"
|
||||
class="text-indigo-600 hover:text-indigo-800 font-medium text-xs bg-indigo-50 hover:bg-indigo-100 px-2.5 py-1.5 rounded-lg transition-colors inline-flex items-center gap-1">
|
||||
<svg class="w-3.5 h-3.5" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15.232 5.232l3.536 3.536m-2.036-5.036a2.5 2.5 0 113.536 3.536L6.5 21.036H3v-3.572L16.732 3.732z"/></svg>
|
||||
Modifier
|
||||
</button>
|
||||
<form th:action="@{/equipes/{id}/delete(id=${team.id})}" method="post" onsubmit="return confirm('Supprimer cette équipe ? Elle sera dissociée de toutes ses licences.');">
|
||||
<button type="submit" class="text-red-500 hover:text-red-700 font-medium text-xs bg-red-50 hover:bg-red-100 px-2.5 py-1.5 rounded-lg transition-colors">
|
||||
Supprimer
|
||||
@@ -89,5 +129,23 @@
|
||||
</div>
|
||||
</div>
|
||||
</main>
|
||||
|
||||
<script>
|
||||
function enableEditTeam(teamId) {
|
||||
document.getElementById('team-name-display-' + teamId).classList.add('hidden');
|
||||
const form = document.getElementById('team-name-form-' + teamId);
|
||||
form.classList.remove('hidden');
|
||||
const input = form.querySelector('input[name="nom"]');
|
||||
if (input) {
|
||||
input.focus();
|
||||
input.select();
|
||||
}
|
||||
}
|
||||
|
||||
function cancelEditTeam(teamId) {
|
||||
document.getElementById('team-name-display-' + teamId).classList.remove('hidden');
|
||||
document.getElementById('team-name-form-' + teamId).classList.add('hidden');
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
Reference in New Issue
Block a user