feat:galerie avant/apres backoffice

This commit is contained in:
2025-12-09 12:45:03 +01:00
parent 735bc334af
commit baf730af3e
13 changed files with 681 additions and 0 deletions

View File

@@ -0,0 +1,90 @@
<!DOCTYPE html>
<html lang="fr">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Ajouter une paire avant/après</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 {
max-width: 800px;
margin-top: 100px;
}
.img-preview {
max-width: 150px;
border-radius: 8px;
display: none; /* cachée tant qu'il n'y a pas d'image */
}
</style>
</head>
<body>
<div class="container">
<h2 class="mb-5 text-center">Ajouter une paire avant/après</h2>
<!-- 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>
<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>
</body>
</html>

View File

@@ -0,0 +1,94 @@
// ===============================
// Données simulées (sera remplacée par BDD )
// ===============================
let galleryPairs = [
{
id: 1,
titre: "Petit chien poils longs",
type: "Chien",
avant: "../../img/avant1.jpg",
apres: "../../img/apres1.jpg"
},
{
id: 2,
titre: "Coupe ciseaux",
type: "Chat",
avant: "../../img/avant2.jpg",
apres: "../../img/apres2.jpg"
}
];
// Sélecteurs
const form = document.getElementById("addPairForm");
const titleInput = document.getElementById("pairTitle");
const typeInput = document.getElementById("pairType");
const beforeInput = document.getElementById("beforeImage");
const afterInput = document.getElementById("afterImage");
const beforePreview = document.getElementById("beforePreview");
const afterPreview = document.getElementById("afterPreview");
const successMsg = document.getElementById("successMsg");
const errorMsg = document.getElementById("errorMsg");
// ===============================
// Prévisualisation images
// ===============================
beforeInput.addEventListener("change", function () {
const file = this.files[0];
if (!file) return;
const reader = new FileReader();
reader.onload = e => {
beforePreview.src = e.target.result;
beforePreview.style.display = "block";
};
reader.readAsDataURL(file);
});
afterInput.addEventListener("change", function () {
const file = this.files[0];
if (!file) return;
const reader = new FileReader();
reader.onload = e => {
afterPreview.src = e.target.result;
afterPreview.style.display = "block";
};
reader.readAsDataURL(file);
});
// ===============================
// Soumission formulaire
// ===============================
form.addEventListener("submit", function (e) {
e.preventDefault();
// Reset messages
errorMsg.classList.add("d-none");
successMsg.classList.add("d-none");
// Validation simple
if (!titleInput.value.trim() || !typeInput.value.trim() || !beforeInput.files[0] || !afterInput.files[0]) {
errorMsg.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])
};
galleryPairs.push(newPair);
successMsg.classList.remove("d-none");
// Redirige après 1 seconde
setTimeout(() => {
window.location.href = "../liste_avant_apres/liste_avant_apres.html";
}, 1000);
});

View File

@@ -0,0 +1,60 @@
<!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>
</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>
<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>
<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

@@ -0,0 +1,90 @@
// ===============================
// Données simulées (à remplacer plus tard par une BDD)
// ===============================
let galleryPairs = [
{
id: 1,
titre: "Petit chien poils longs",
type: "Chien",
avant: "../../img/avant1.jpg",
apres: "../../img/apres1.jpg"
},
{
id: 2,
titre: "Coupe ciseaux",
type: "Chat",
avant: "../../img/avant2.jpg",
apres: "../../img/apres2.jpg"
}
];
// Sélecteurs
const tableBody = document.getElementById("prestationTableBody");
const succesDeleteMsg = document.getElementById("succesDeleteMsg");
// ===============================
// Fonction d'affichage
// ===============================
function displayPairs() {
tableBody.innerHTML = ""; // reset tableau
galleryPairs.forEach(pair => {
const row = document.createElement("tr");
row.innerHTML = `
<td>${pair.titre}</td>
<td>${pair.type}</td>
<td>
<img src="${pair.avant}" width="80" class="rounded">
</td>
<td>
<img src="${pair.apres}" width="80" class="rounded">
</td>
<td class="text-center action-btns">
<!-- 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 Supprimer -->
<button class="btn btn-danger btn-sm" onclick="deletePair(${pair.id})">
Supprimer
</button>
</td>
`;
tableBody.appendChild(row);
});
}
// ===============================
// Fonction de suppression
// ===============================
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);
}
// ===============================
// Chargement initial
// ===============================
displayPairs();

View File

@@ -0,0 +1,104 @@
<!DOCTYPE html>
<html lang="fr">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Modifier une paire avant/après</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;
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>
<!-- Messages -->
<div id="successMsg" class="alert alert-success d-none">
La paire avant/après a été modifiée avec succès.
</div>
<div id="errorMsg" class="alert alert-danger d-none">
Une erreur est survenue. Merci de vérifier le formulaire.
</div>
<!-- Formulaire de modification -->
<form id="editPairForm">
<!-- 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>
<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">
<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>
</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">
</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>
</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>
</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

@@ -0,0 +1,115 @@
// ===============================
// Données simulées
// (mêmes IDs que dans la liste !)
// ===============================
const galleryPairs = [
{
id: 1,
titre: "Petit chien poils longs",
type: "Chien",
avant: "../../img/avant1.jpg",
apres: "../../img/apres1.jpg"
},
{
id: 2,
titre: "Coupe ciseaux",
type: "Chat",
avant: "../../img/avant2.jpg",
apres: "../../img/apres2.jpg"
}
];
// Sélecteurs
const editForm = document.getElementById("editPairForm");
const pairIdInput = document.getElementById("pairId");
const titleInput = document.getElementById("pairTitle");
const typeSelect = document.getElementById("pairType");
const beforeInput = document.getElementById("beforeImage");
const afterInput = document.getElementById("afterImage");
const beforePreview = document.getElementById("beforePreview");
const afterPreview = document.getElementById("afterPreview");
const successMsg = document.getElementById("successMsg");
const errorMsg = document.getElementById("errorMsg");
// ===============================
// Récup ID dans l'URL
// ===============================
function getPairIdFromUrl() {
const params = new URLSearchParams(window.location.search);
const idParam = params.get("id");
if (!idParam) {
// pas d'id → retour à la liste
window.location.href = "../liste_avant_apres/liste_avant_apres.html";
return null;
}
return parseInt(idParam, 10);
}
// ===============================
// Charger la paire
// ===============================
function loadPairData() {
const id = getPairIdFromUrl();
if (!id) return;
const pair = galleryPairs.find(p => p.id === id);
if (!pair) {
errorMsg.textContent = "Paire introuvable.";
errorMsg.classList.remove("d-none");
editForm.classList.add("d-none");
return;
}
pairIdInput.value = pair.id;
titleInput.value = pair.titre;
typeSelect.value = pair.type;
beforePreview.src = pair.avant;
afterPreview.src = pair.apres;
}
// Prévisu des nouvelles images
beforeInput.addEventListener("change", function () {
const file = this.files[0];
if (!file) return;
const reader = new FileReader();
reader.onload = e => beforePreview.src = e.target.result;
reader.readAsDataURL(file);
});
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);
});
// Soumission
editForm.addEventListener("submit", function (e) {
e.preventDefault();
errorMsg.classList.add("d-none");
successMsg.classList.add("d-none");
if (!titleInput.value.trim()) {
errorMsg.textContent = "Le titre est obligatoire.";
errorMsg.classList.remove("d-none");
return;
}
// Ici ce serait un fetch vers l'API en vrai.
successMsg.classList.remove("d-none");
setTimeout(() => {
window.location.href = "../liste_avant_apres/liste_avant_apres.html";
}, 1500);
});
// Init
loadPairData();

View File

@@ -0,0 +1,70 @@
<!DOCTYPE html>
<html lang="fr">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Voir la paire avant/après</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 {
max-width: 800px;
margin-top: 100px;
}
.img-preview {
max-width: 250px;
border-radius: 10px;
}
</style>
</head>
<body>
<div class="container">
<h2 class="mb-5 text-center">Détails de la paire avant/après</h2>
<!-- Message erreur -->
<div id="errorMsg" class="alert alert-danger d-none">
Impossible d'afficher cette paire.
</div>
<div id="detailsSection">
<!-- Titre -->
<h4 id="pairTitle" class="text-center mb-4"></h4>
<div class="d-flex justify-content-around align-items-center mb-4">
<div class="text-center">
<p class="fw-bold">AVANT</p>
<img id="beforePreview" class="img-preview border" src="">
</div>
<div class="text-center">
<p class="fw-bold">APRÈS</p>
<img id="afterPreview" class="img-preview border" src="">
</div>
</div>
<!-- Bouton retour -->
<div class="text-center mt-4">
<a href="../liste_avant_apres/liste_avant_apres.html" class="btn btn-secondary">
Retour à la liste
</a>
</div>
</div>
</div>
<script src="voir_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

@@ -0,0 +1,58 @@
// ===============================
// Données simulées (à remplacer plus tard par BDD / API)
// ===============================
let galleryPairs = [
{
id: 1,
titre: "Petit chien poils longs",
type: "Chien",
avant: "../../img/avant1.jpg",
apres: "../../img/apres1.jpg"
},
{
id: 2,
titre: "Coupe ciseaux",
type: "Chat",
avant: "../../img/avant2.jpg",
apres: "../../img/apres2.jpg"
}
];
// Sélecteurs
const titleEl = document.getElementById("pairTitle");
const beforePreview = document.getElementById("beforePreview");
const afterPreview = document.getElementById("afterPreview");
const errorMsg = document.getElementById("errorMsg");
const detailsSection = document.getElementById("detailsSection");
// ===============================
// Récup ID dans l'URL
// ===============================
function getIdFromUrl() {
const params = new URLSearchParams(window.location.search);
return parseInt(params.get("id"));
}
// ===============================
// Charger les infos de la paire
// ===============================
function loadPairDetails() {
const id = getIdFromUrl();
const pair = galleryPairs.find(p => p.id === id);
if (!pair) {
errorMsg.classList.remove("d-none");
detailsSection.classList.add("d-none");
return;
}
// Affichage du titre
titleEl.textContent = pair.titre;
// Affichage des images
beforePreview.src = pair.avant;
afterPreview.src = pair.apres;
}
// Initialisation
loadPairDetails();