website fonctional / front=ok / back=ok / docker=ok
This commit is contained in:
@@ -388,4 +388,15 @@
|
||||
|
||||
.dark .right-column {
|
||||
background-color: #2d2d2d;
|
||||
}
|
||||
}
|
||||
|
||||
.postit {
|
||||
background-color: #fff475;
|
||||
color: #333;
|
||||
padding: 0.8rem;
|
||||
margin-bottom: 0.8rem;
|
||||
border-radius: 8px;
|
||||
box-shadow: 2px 2px 6px rgba(0,0,0,0.15);
|
||||
font-family: 'Comic Sans MS', sans-serif;
|
||||
font-size: 0.95rem;
|
||||
}
|
||||
@@ -80,4 +80,74 @@
|
||||
if (e.target === contactModal) {
|
||||
contactModal.style.display = 'none';
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
// Gestion des annonces
|
||||
|
||||
let isAdmin = false;
|
||||
|
||||
fetch("/api/is_admin")
|
||||
.then(res => res.json())
|
||||
.then(data => {
|
||||
isAdmin = data.admin;
|
||||
if (isAdmin) {
|
||||
document.getElementById("admin-tools").style.display = "block";
|
||||
}
|
||||
});
|
||||
|
||||
fetch("/api/annonces")
|
||||
.then(res => res.json())
|
||||
.then(data => {
|
||||
const container = document.getElementById("annonces-container");
|
||||
container.innerHTML = "";
|
||||
|
||||
data.forEach(item => {
|
||||
const div = document.createElement("div");
|
||||
div.className = "postit";
|
||||
div.dataset.id = item.id;
|
||||
div.innerHTML = `
|
||||
<span class="annonce-text">${item.text}</span>
|
||||
<br><small>${item.author}</small>
|
||||
`;
|
||||
|
||||
if (isAdmin) {
|
||||
const editBtn = document.createElement("button");
|
||||
editBtn.textContent = "✏️";
|
||||
editBtn.onclick = () => editAnnonce(item.id, item.text);
|
||||
div.appendChild(editBtn);
|
||||
|
||||
const delBtn = document.createElement("button");
|
||||
delBtn.textContent = "🗑️";
|
||||
delBtn.onclick = () => deleteAnnonce(item.id);
|
||||
div.appendChild(delBtn);
|
||||
}
|
||||
|
||||
container.appendChild(div);
|
||||
});
|
||||
});
|
||||
|
||||
function submitAnnonce() {
|
||||
const txt = document.getElementById("annonce-text").value;
|
||||
fetch("/api/annonces", {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({ text: txt })
|
||||
}).then(() => location.reload());
|
||||
}
|
||||
|
||||
function deleteAnnonce(id) {
|
||||
fetch(`/api/annonces/${id}`, {
|
||||
method: "DELETE"
|
||||
}).then(() => location.reload());
|
||||
}
|
||||
|
||||
function editAnnonce(id, oldText) {
|
||||
const newText = prompt("Modifier l'annonce :", oldText);
|
||||
if (newText && newText !== oldText) {
|
||||
fetch(`/api/annonces/${id}`, {
|
||||
method: "PUT",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({ text: newText })
|
||||
}).then(() => location.reload());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user