feat:avant apres+media queries+modale de suppression

This commit is contained in:
2025-12-10 09:44:44 +01:00
parent 4f85fe3250
commit 9a8891fc9d
7 changed files with 365 additions and 219 deletions

View File

@@ -1,5 +1,6 @@
<!DOCTYPE html>
<html lang="fr">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
@@ -8,14 +9,6 @@
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css">
<style>
body {
background: #f4f6f9;
padding: 30px;
}
.container {
max-width: 800px;
margin-top: 100px;
}
.img-preview {
max-width: 150px;
border-radius: 8px;
@@ -23,68 +16,83 @@
}
</style>
</head>
<body>
<div class="container">
<body class="bg-light py-4 py-md-5">
<h2 class="mb-5 text-center">Ajouter une paire avant/après</h2>
<div class="container" style="max-width: 800px;">
<!-- Message succès -->
<div id="successMsg" class="alert alert-success d-none">
Nouvelle paire ajoutée avec succès !
<h1 class="mb-4 mb-md-5 text-center">Ajouter une paire avant/après</h1>
<!-- Message succès -->
<div id="successMsg" class="alert alert-success d-none">
Nouvelle paire ajoutée avec succès !
</div>
<!-- Message erreur -->
<div id="errorMsg" class="alert alert-danger d-none">
Merci de remplir tous les champs obligatoires.
</div>
<!-- Erreur : format invalide -->
<div id="errorFormat" class="alert alert-danger d-none">
Format d'image invalide. Formats acceptés : JPG, PNG, WEBP.
</div>
<form id="addPairForm" class="mt-3">
<!-- Titre / label -->
<div class="mb-3">
<label class="form-label" for="pairTitle">Titre de la paire (obligatoire)</label>
<input type="text" id="pairTitle" class="form-control" required>
</div>
<!-- Type -->
<div class="mb-3">
<label class="form-label" for="pairType">Type (obligatoire)</label>
<select id="pairType" class="form-select" required>
<option value="">-- Choisir --</option>
<option value="Chien">Chien</option>
<option value="Chat">Chat</option>
</select>
</div>
<!-- Image AVANT -->
<div class="mb-4">
<label class="form-label" for="beforeImage">Image AVANT (obligatoire)</label>
<input type="file" id="beforeImage" class="form-control" accept="image/*" required>
<img id="beforePreview" class="img-preview border mt-2" src="#" alt="image avant">
</div>
<!-- Image APRÈS -->
<div class="mb-4">
<label class="form-label" for="afterImage">Image APRÈS (obligatoire)</label>
<input type="file" id="afterImage" class="form-control" accept="image/*" required>
<img id="afterPreview" class="img-preview border mt-2" src="#" alt="image après">
</div>
<!-- Boutons : empilés en mobile, côte à côte en md+ -->
<div class="row mt-4 g-3">
<div class="col-12 col-md-6">
<a href="../liste_avant_apres/liste_avant_apres.html" class="btn btn-secondary w-100">
Annuler
</a>
</div>
<div class="col-12 col-md-6">
<button type="submit" class="btn btn-primary w-100">
Ajouter
</button>
</div>
</div>
</form>
</div>
<!-- Message erreur -->
<div id="errorMsg" class="alert alert-danger d-none">
Merci de remplir tous les champs obligatoires.
</div>
<form id="addPairForm">
<!-- Titre / label -->
<div class="mb-3">
<label class="form-label">Titre de la paire *</label>
<input type="text" id="pairTitle" class="form-control" required>
</div>
<!-- Type -->
<div class="mb-3">
<label class="form-label">Type *</label>
<select id="pairType" class="form-select" required>
<option value="">-- Choisir --</option>
<option value="Chien">Chien</option>
<option value="Chat">Chat</option>
<option value="Autre">Autre</option>
</select>
</div>
<!-- Image AVANT -->
<div class="mb-4">
<label class="form-label">Image AVANT *</label>
<input type="file" id="beforeImage" class="form-control" accept="image/*">
<img id="beforePreview" class="img-preview border mt-2">
</div>
<!-- Image APRÈS -->
<div class="mb-4">
<label class="form-label">Image APRÈS *</label>
<input type="file" id="afterImage" class="form-control" accept="image/*">
<img id="afterPreview" class="img-preview border mt-2">
</div>
<!-- Boutons -->
<div class="d-flex justify-content-between">
<a href="../liste_avant_apres/liste_avant_apres.html" class="btn btn-secondary">Annuler</a>
<button type="submit" class="btn btn-primary">Ajouter</button>
</div>
</form>
</div>
<script src="ajouter_avant_apres.js"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"></script>
<script src="ajouter_avant_apres.js"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>

View File

@@ -1,60 +1,84 @@
<!DOCTYPE html>
<html lang="fr">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Liste des paires avant/apres</title>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css">
<style>
body {
background: #f4f6f9;
padding: 30px;
}
.container {
margin-top: 100px;
}
.action-btns button,
.action-btns a {
margin-right: 100px;
}
</style>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Liste des paires avant/après</title>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css">
</head>
<body>
<div class="container">
<h2 class="mb-5 text-center">Liste des paires avant/apres</h2>
<!--Message succès-->
<div id="succesDeleteMsg" class="alert alert-success d-none">Paire supprimée avec succès !</div>
<div class="d-flex justify-content-end mb-4">
<a href="../ajouter_avant_apres/ajouter_avant_apres.html" class="btn btn-primary">Ajouter une paire</a>
</div>
<body class="bg-light py-4 py-md-5">
<table class="table table-striped table-hover align-middle">
<thead class="table-dark">
<tr>
<th>Titre paire</th>
<th>Type</th>
<th>Avant</th>
<th>Apres</th>
<th class="text-center">Actions</th>
</tr>
</thead>
<tbody id="prestationTableBody">
<!--JS-->
</tbody>
</table>
<div class="container" style="max-width: 1000px;">
<h1 class="mb-4 mb-md-5 text-center">Liste des paires avant/après</h1>
<!-- Message succès -->
<div id="succesDeleteMsg" class="alert alert-success d-none">
Paire supprimée avec succès !
</div>
<script src="liste_avant_apres.js"></script>
<div class="d-flex justify-content-end mb-4">
<a href="../ajouter_avant_apres/ajouter_avant_apres.html" class="btn btn-primary">
Ajouter une paire
</a>
</div>
<!-- Table responsive -->
<div class="table-responsive">
<table class="table table-striped table-hover align-middle mb-0">
<thead class="table-dark">
<tr>
<th>Titre paire</th>
<th>Type</th>
<th>Avant</th>
<th>Après</th>
<th class="text-center">Actions</th>
</tr>
</thead>
<tbody id="prestationTableBody">
<!-- JS -->
</tbody>
</table>
</div>
</div>
<div class="modal fade" id="deleteModal" tabindex="-1" role="dialog" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h2 class="modal-title" id="deleteModalLabel">Confirmer la suppression</h2>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Fermer"></button>
</div>
<div class="modal-body">
Voulez-vous vraiment supprimer cette paire avant/après ?
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Annuler</button>
<button type="button" class="btn btn-danger" id="confirmDeleteBtn">Supprimer</button>
</div>
</div>
</div>
</div>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"></script>
<script src="liste_avant_apres.js"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>

View File

@@ -1,5 +1,6 @@
<!DOCTYPE html>
<html lang="fr">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
@@ -7,24 +8,17 @@
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css">
<style>
body {
background: #f4f6f9;
padding: 30px;
}
.container {
margin-top: 100px;
max-width: 800px;
}
.img-preview {
max-width: 150px;
border-radius: 8px;
}
</style>
</head>
<body>
<div class="container">
<h2 class="mb-5 text-center">Modifier une paire avant/après</h2>
<body class="bg-light py-4 py-md-5">
<div class="container" style="max-width: 800px;">
<h2 class="mb-4 mb-md-5 text-center">Modifier une paire avant/après</h2>
<!-- Messages -->
<div id="successMsg" class="alert alert-success d-none">
@@ -34,71 +28,71 @@
Une erreur est survenue. Merci de vérifier le formulaire.
</div>
<!-- Erreur : format invalide -->
<div id="errorFormat" class="alert alert-danger d-none">
Format d'image invalide. Formats acceptés : JPG, PNG, WEBP.
</div>
<!-- Formulaire de modification -->
<form id="editPairForm">
<form id="editPairForm" class="mt-3">
<!-- ID caché -->
<input type="hidden" id="pairId">
<!-- Titre / label -->
<div class="mb-3">
<label for="pairTitle" class="form-label">Titre / label de la paire *</label>
<label for="pairTitle" class="form-label">Titre / label de la paire (obligatoire)</label>
<input type="text" class="form-control" id="pairTitle" required>
</div>
<!-- Type -->
<div class="mb-3">
<label for="pairType" class="form-label">Type</label>
<select id="pairType" class="form-select">
<label class="form-label" for="pairType">Type (obligatoire)</label>
<select id="pairType" class="form-select" required>
<option value="">-- Choisir --</option>
<option value="Chien">Chien</option>
<option value="Chat">Chat</option>
<option value="Autre">Autre</option>
</select>
</div>
<!-- Image AVANT -->
<div class="mb-4 row">
<div class="col-md-6">
<label class="form-label" for="beforeImage">Image AVANT</label>
<input type="file" class="form-control" id="beforeImage" accept="image/*">
<div class="form-text">
Laisser vide pour conserver l'image actuelle.
</div>
<!-- Images AVANT / APRÈS sur une ligne en md+, empilées en mobile -->
<div class="row gy-4 mb-4">
<!-- Image AVANT -->
<div class="col-12 col-md-6">
<label class="form-label" for="beforeImage">Image AVANT (obligatoire)</label>
<input type="file" class="form-control" id="beforeImage" accept="image/*" required>
<!-- Aperçu éventuel -->
<img id="beforePreview" class="img-preview mt-2 d-none" src="#" alt="Aperçu avant">
</div>
<div class="col-md-6 text-center">
<p class="mb-1">Aperçu actuel AVANT</p>
<img id="beforePreview" src="" alt="Image avant" class="img-preview border">
<!-- Image APRÈS -->
<div class="col-12 col-md-6">
<label class="form-label" for="afterImage">Image APRÈS (obligatoire)</label>
<input type="file" class="form-control" id="afterImage" accept="image/*" required>
<!-- Aperçu éventuel -->
<img id="afterPreview" class="img-preview mt-2 d-none" src="#" alt="Aperçu après">
</div>
</div>
<!-- Image APRES -->
<div class="mb-4 row">
<div class="col-md-6">
<label class="form-label" for="afterImage">Image APRÈS</label>
<input type="file" class="form-control" id="afterImage" accept="image/*">
<div class="form-text">
Laisser vide pour conserver l'image actuelle.
</div>
<!-- Boutons : empilés en mobile, côte à côte en md+ -->
<div class="row mt-4 g-3">
<div class="col-12 col-md-6">
<a href="../liste_avant_apres/liste_avant_apres.html" class="btn btn-secondary w-100">
Annuler
</a>
</div>
<div class="col-md-6 text-center">
<p class="mb-1">Aperçu actuel APRÈS</p>
<img id="afterPreview" src="" alt="Image après" class="img-preview border">
<div class="col-12 col-md-6">
<button type="submit" class="btn btn-primary w-100">
Enregistrer les modifications
</button>
</div>
</div>
<!-- Boutons -->
<div class="d-flex justify-content-between">
<a href="../liste_avant_apres/liste_avant_apres.html" class="btn btn-secondary">
Annuler
</a>
<button type="submit" class="btn btn-primary">
Enregistrer les modifications
</button>
</div>
</form>
</div>
<script src="modifier_avant_apres.js"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>

View File

@@ -8,46 +8,39 @@
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css">
<style>
body {
background: #f4f6f9;
padding: 30px;
}
.container {
max-width: 800px;
margin-top: 100px;
}
.img-preview {
max-width: 250px;
border-radius: 10px;
}
</style>
</head>
<body>
<body class="bg-light py-4 py-md-5">
<div class="container">
<div class="container" style="max-width: 800px;">
<h2 class="mb-5 text-center">Détails de la paire avant/après</h2>
<h1 class="mb-4 mb-md-5 text-center">Détails de la paire avant/après</h1>
<!-- Message erreur -->
<div id="errorMsg" class="alert alert-danger d-none">
Impossible d'afficher cette paire.
</div>
<div id="detailsSection">
<div id="detailsSection" class="mt-3">
<!-- Titre -->
<h4 id="pairTitle" class="text-center mb-4"></h4>
<h2 id="pairTitle" class="text-center mb-4" aria-live="polite">Chargement...</h2>
<div class="d-flex justify-content-around align-items-center mb-4">
<div class="text-center">
<!-- AVANT / APRÈS : empilés en mobile, côte à côte en md+ -->
<div class="row justify-content-center align-items-start mb-4 g-4">
<div class="col-12 col-md-6 text-center">
<p class="fw-bold">AVANT</p>
<img id="beforePreview" class="img-preview border" src="">
<img id="beforePreview" class="img-preview border img-fluid" src="#" alt="Photo avant">
</div>
<div class="text-center">
<div class="col-12 col-md-6 text-center">
<p class="fw-bold">APRÈS</p>
<img id="afterPreview" class="img-preview border" src="">
<img id="afterPreview" class="img-preview border img-fluid" src="#" alt="Photo après" >
</div>
</div>
@@ -68,3 +61,4 @@
</body>
</html>

View File

@@ -30,13 +30,48 @@ const afterPreview = document.getElementById("afterPreview");
const successMsg = document.getElementById("successMsg");
const errorMsg = document.getElementById("errorMsg");
const errorFormat = document.getElementById("errorFormat");
// Formats autorisés
const allowedTypes = ["image/jpeg", "image/png", "image/webp"];
// ===============================
// Prévisualisation images
// Fonctions utilitaires
// ===============================
function hideMessages() {
successMsg.classList.add("d-none");
errorMsg.classList.add("d-none");
errorFormat.classList.add("d-none");
}
function isValidFormat(file) {
if (!file) return false;
return allowedTypes.includes(file.type);
}
// ===============================
// Prévisualisation image AVANT
// + contrôle du format
// ===============================
beforeInput.addEventListener("change", function () {
hideMessages();
const file = this.files[0];
if (!file) return;
if (!file) {
beforePreview.style.display = "none";
beforePreview.src = "#";
return;
}
// Vérif format
if (!isValidFormat(file)) {
errorFormat.classList.remove("d-none");
this.value = ""; // reset le champ
beforePreview.style.display = "none";
beforePreview.src = "#";
return;
}
const reader = new FileReader();
reader.onload = e => {
@@ -46,9 +81,29 @@ beforeInput.addEventListener("change", function () {
reader.readAsDataURL(file);
});
// ===============================
// Prévisualisation image APRÈS
// + contrôle du format
// ===============================
afterInput.addEventListener("change", function () {
hideMessages();
const file = this.files[0];
if (!file) return;
if (!file) {
afterPreview.style.display = "none";
afterPreview.src = "#";
return;
}
// Vérif format
if (!isValidFormat(file)) {
errorFormat.classList.remove("d-none");
this.value = ""; // reset le champ
afterPreview.style.display = "none";
afterPreview.src = "#";
return;
}
const reader = new FileReader();
reader.onload = e => {
@@ -64,23 +119,35 @@ afterInput.addEventListener("change", function () {
form.addEventListener("submit", function (e) {
e.preventDefault();
// Reset messages
errorMsg.classList.add("d-none");
successMsg.classList.add("d-none");
hideMessages();
// Validation simple
if (!titleInput.value.trim() || !typeInput.value.trim() || !beforeInput.files[0] || !afterInput.files[0]) {
// Champs obligatoires
if (
!titleInput.value.trim() ||
!typeInput.value.trim() ||
!beforeInput.files[0] ||
!afterInput.files[0]
) {
errorMsg.classList.remove("d-none");
return;
}
const beforeFile = beforeInput.files[0];
const afterFile = afterInput.files[0];
// Vérification format des deux images
if (!isValidFormat(beforeFile) || !isValidFormat(afterFile)) {
errorFormat.classList.remove("d-none");
return;
}
// Nouvelle entrée (simulation)
const newPair = {
id: galleryPairs.length + 1,
titre: titleInput.value.trim(),
type: typeInput.value.trim(),
avant: URL.createObjectURL(beforeInput.files[0]),
apres: URL.createObjectURL(afterInput.files[0])
avant: URL.createObjectURL(beforeFile),
apres: URL.createObjectURL(afterFile)
};
galleryPairs.push(newPair);

View File

@@ -22,6 +22,14 @@ let galleryPairs = [
const tableBody = document.getElementById("prestationTableBody");
const succesDeleteMsg = document.getElementById("succesDeleteMsg");
// Modal & bouton de confirmation
const deleteModalEl = document.getElementById("deleteModal");
const confirmDeleteBtn = document.getElementById("confirmDeleteBtn");
const deleteModal = new bootstrap.Modal(deleteModalEl);
// ID de la paire en attente de suppression
let pairIdToDelete = null;
// ===============================
// Fonction d'affichage
// ===============================
@@ -36,27 +44,33 @@ function displayPairs() {
<td>${pair.type}</td>
<td>
<img src="${pair.avant}" width="80" class="rounded">
<img src="${pair.avant}" class="img-thumbnail" style="max-width: 80px;">
</td>
<td>
<img src="${pair.apres}" width="80" class="rounded">
<img src="${pair.apres}" class="img-thumbnail" style="max-width: 80px;">
</td>
<td class="text-center action-btns">
<td class="text-center text-md-start">
<div class="d-flex flex-column flex-md-row justify-content-center justify-content-md-start gap-2">
<!-- Bouton Voir -->
<a href="../voir_avant_apres/voir_avant_apres.html?id=${pair.id}"
class="btn btn-info btn-sm">Voir</a>
<!-- Bouton Voir -->
<a href="../voir_avant_apres/voir_avant_apres.html?id=${pair.id}"
class="btn btn-info btn-sm">
Voir
</a>
<!-- Bouton Modifier -->
<a href="../modifier_avant_apres/modifier_avant_apres.html?id=${pair.id}"
class="btn btn-warning btn-sm">Modifier</a>
<!-- Bouton Modifier -->
<a href="../modifier_avant_apres/modifier_avant_apres.html?id=${pair.id}"
class="btn btn-warning btn-sm">
Modifier
</a>
<!-- Bouton Supprimer -->
<button class="btn btn-danger btn-sm" onclick="deletePair(${pair.id})">
Supprimer
</button>
<!-- Bouton Supprimer -->
<button class="btn btn-danger btn-sm" onclick="openDeleteModal(${pair.id})">
Supprimer
</button>
</div>
</td>
`;
@@ -65,26 +79,39 @@ function displayPairs() {
}
// ===============================
// Fonction de suppression
// Ouvrir le modal de suppression
// ===============================
function openDeleteModal(id) {
pairIdToDelete = id; // on mémorise l'id
deleteModal.show(); // on ouvre le modal
}
// ===============================
// Fonction de suppression réelle
// ===============================
function deletePair(id) {
if (!confirm("Voulez-vous vraiment supprimer cette paire ?")) {
return;
}
galleryPairs = galleryPairs.filter(pair => pair.id !== id);
displayPairs();
succesDeleteMsg.classList.remove("d-none");
// Disparaît après 2 secondes
setTimeout(() => {
succesDeleteMsg.classList.add("d-none");
}, 2000);
}
// ===============================
// Clic sur "Supprimer" dans le modal
// ===============================
confirmDeleteBtn.addEventListener("click", () => {
if (pairIdToDelete !== null) {
deletePair(pairIdToDelete);
pairIdToDelete = null;
}
deleteModal.hide();
});
// ===============================
// Chargement initial
// ===============================
displayPairs();

View File

@@ -19,6 +19,11 @@ const galleryPairs = [
}
];
// ===============================
// Formats d'images autorisés
// ===============================
const allowedTypes = ["image/jpeg", "image/png", "image/webp"];
// Sélecteurs
const editForm = document.getElementById("editPairForm");
const pairIdInput = document.getElementById("pairId");
@@ -31,6 +36,7 @@ const afterPreview = document.getElementById("afterPreview");
const successMsg = document.getElementById("successMsg");
const errorMsg = document.getElementById("errorMsg");
const errorFormat = document.getElementById("errorFormat");
// ===============================
// Récup ID dans l'URL
@@ -71,23 +77,39 @@ function loadPairData() {
afterPreview.src = pair.apres;
}
// Prévisu des nouvelles images
beforeInput.addEventListener("change", function () {
const file = this.files[0];
// ===============================
// Gestion du changement d'image
// ===============================
function handleImageChange(inputEl, previewEl) {
const file = inputEl.files[0];
if (!file) return;
// Vérification format
if (!allowedTypes.includes(file.type)) {
// Format non autorisé
errorFormat.classList.remove("d-none");
inputEl.value = ""; // reset du champ
previewEl.src = ""; // reset de la prévisu
return;
}
// Format OK → on cache le message d'erreur
errorFormat.classList.add("d-none");
const reader = new FileReader();
reader.onload = e => beforePreview.src = e.target.result;
reader.onload = e => {
previewEl.src = e.target.result;
};
reader.readAsDataURL(file);
}
// Prévisu des nouvelles images + contrôle format
beforeInput.addEventListener("change", function () {
handleImageChange(beforeInput, beforePreview);
});
afterInput.addEventListener("change", function () {
const file = this.files[0];
if (!file) return;
const reader = new FileReader();
reader.onload = e => afterPreview.src = e.target.result;
reader.readAsDataURL(file);
handleImageChange(afterInput, afterPreview);
});
// Soumission
@@ -96,6 +118,7 @@ editForm.addEventListener("submit", function (e) {
errorMsg.classList.add("d-none");
successMsg.classList.add("d-none");
errorFormat.classList.add("d-none");
if (!titleInput.value.trim()) {
errorMsg.textContent = "Le titre est obligatoire.";
@@ -103,7 +126,16 @@ editForm.addEventListener("submit", function (e) {
return;
}
// Ici ce serait un fetch vers l'API en vrai.
// Double check format côté submit (au cas où)
const filesToCheck = [beforeInput.files[0], afterInput.files[0]];
for (const file of filesToCheck) {
if (!file || !allowedTypes.includes(file.type)) {
errorFormat.classList.remove("d-none");
return;
}
}
successMsg.classList.remove("d-none");
setTimeout(() => {