Actualiser js/admin.js

This commit is contained in:
2026-06-18 16:58:05 +02:00
parent a5e4f90982
commit f550371731
+23 -7
View File
@@ -32,12 +32,14 @@ function initEventListeners() {
}); });
} }
/ Remplacez la fonction loadDashboardData existante par celle-ci
async function loadDashboardData() { async function loadDashboardData() {
try { try {
const res = await fetch(`${API_URL}?action=get_films`); // NOUVEAU : cache: 'no-store' oblige le navigateur à récupérer la vraie donnée
const res = await fetch(`${API_URL}?action=get_films`, { cache: 'no-store' });
allItems = await res.json(); allItems = await res.json();
const secRes = await fetch(`${API_URL}?action=check_security_status`); const secRes = await fetch(`${API_URL}?action=check_security_status`, { cache: 'no-store' });
const secData = await secRes.json(); const secData = await secRes.json();
const banner = document.getElementById('security-banner'); const banner = document.getElementById('security-banner');
if (banner) banner.style.display = secData.is_blank ? 'flex' : 'none'; if (banner) banner.style.display = secData.is_blank ? 'flex' : 'none';
@@ -114,35 +116,49 @@ function closeConfirmModal() {
pendingDeleteAction = null; pendingDeleteAction = null;
} }
// ── ACTIONS CRUD (SUPPRESSION) ── // Remplacez la fonction executeBulkDelete existante par celle-ci
async function executeBulkDelete() { async function executeBulkDelete() {
const ids = Array.from(document.querySelectorAll('.film-checkbox:checked')).map(cb => cb.value); const ids = Array.from(document.querySelectorAll('.film-checkbox:checked')).map(cb => cb.value);
if (ids.length === 0) return; if (ids.length === 0) return;
showConfirmModal(async () => { showConfirmModal(async () => {
try { try {
await fetch(`${API_URL}?action=bulk_delete`, { const res = await fetch(`${API_URL}?action=bulk_delete`, {
method: 'POST', method: 'POST',
headers: { 'Authorization': localStorage.getItem('token'), 'Content-Type': 'application/json' }, headers: { 'Authorization': localStorage.getItem('token'), 'Content-Type': 'application/json' },
body: JSON.stringify({ ids, type: currentAdminTab }) body: JSON.stringify({ ids, type: currentAdminTab })
}); });
// NOUVEAU : Si le serveur renvoie une erreur, on lève une exception
if (!res.ok) throw new Error("Erreur du serveur lors de la suppression");
document.getElementById('bulk-actions-bar').style.display = 'none'; document.getElementById('bulk-actions-bar').style.display = 'none';
const selectAll = document.getElementById('select-all-checkbox'); const selectAll = document.getElementById('select-all-checkbox');
if(selectAll) selectAll.checked = false; if(selectAll) selectAll.checked = false;
loadDashboardData(); loadDashboardData();
} catch (err) { console.error('Erreur bulk delete :', err); } } catch (err) {
console.error('Erreur bulk delete :', err);
alert("Une erreur est survenue lors de la suppression.");
}
}); });
} }
// Remplacez la fonction deleteSingleFilm existante par celle-ci
async function deleteSingleFilm(id) { async function deleteSingleFilm(id) {
showConfirmModal(async () => { showConfirmModal(async () => {
try { try {
await fetch(`${API_URL}?action=delete_film&id=${id}&type=${currentAdminTab}`, { const res = await fetch(`${API_URL}?action=delete_film&id=${id}&type=${currentAdminTab}`, {
method: 'DELETE', method: 'DELETE',
headers: { 'Authorization': localStorage.getItem('token') } headers: { 'Authorization': localStorage.getItem('token') }
}); });
if (!res.ok) throw new Error("Erreur du serveur lors de la suppression unique");
loadDashboardData(); loadDashboardData();
} catch (err) { console.error('Erreur delete :', err); } } catch (err) {
console.error('Erreur delete :', err);
alert("Une erreur est survenue lors de la suppression.");
}
}); });
} }