Actualiser js/admin.js

This commit is contained in:
2026-06-18 13:41:19 +02:00
parent 98e9cfe320
commit d038b23e39
+33 -32
View File
@@ -64,46 +64,47 @@ document.addEventListener('change', (e) => {
// Remplacez les deux fonctions de suppression par celles-ci :
async function deleteSingleFilm(id) {
if (!confirm('Supprimer ce film ?')) return;
// Variable pour stocker la fonction à appeler après confirmation
let pendingDeleteAction = null;
const token = localStorage.getItem('token');
const res = await fetch(`${API_URL}?action=delete_film&id=${id}&type=${currentAdminTab}`, {
method: 'DELETE',
headers: { 'Authorization': token } // <-- Vérifiez que ce token est bien présent
});
const data = await res.json();
console.log("Réponse suppression simple :", data);
loadDashboardData();
function showConfirmModal(actionFn) {
pendingDeleteAction = actionFn;
document.getElementById('confirm-modal').classList.add('open');
}
// 3. Suppression
function closeConfirmModal() {
document.getElementById('confirm-modal').classList.remove('open');
}
// Bouton supprimer dans la modale
document.getElementById('confirm-btn').addEventListener('click', () => {
if (pendingDeleteAction) pendingDeleteAction();
closeConfirmModal();
});
// Mise à jour de la suppression de masse
async function executeBulkDelete() {
const checked = document.querySelectorAll('.film-checkbox:checked');
const ids = Array.from(checked).map(cb => cb.value);
if (ids.length === 0) return;
if (!confirm(`Supprimer ces ${ids.length} films ?`)) return;
try {
const res = await fetch(`${API_URL}?action=bulk_delete`, {
showConfirmModal(async () => {
const ids = Array.from(document.querySelectorAll('.film-checkbox:checked')).map(cb => cb.value);
await fetch(`${API_URL}?action=bulk_delete`, {
method: 'POST',
headers: {
'Authorization': localStorage.getItem('token'),
'Content-Type': 'application/json'
},
body: JSON.stringify({ ids: ids, type: currentAdminTab })
headers: { 'Authorization': localStorage.getItem('token'), 'Content-Type': 'application/json' },
body: JSON.stringify({ ids, type: currentAdminTab })
});
const data = await res.json();
if (data.success) {
document.getElementById('bulk-actions-bar').style.display = 'none';
loadDashboardData();
document.getElementById('bulk-actions-bar').style.display = 'none';
});
}
} catch (err) {
console.error('Erreur bulk delete :', err);
}
// Mise à jour de la suppression unitaire
async function deleteSingleFilm(id) {
showConfirmModal(async () => {
await fetch(`${API_URL}?action=delete_film&id=${id}&type=${currentAdminTab}`, {
method: 'DELETE',
headers: { 'Authorization': localStorage.getItem('token') }
});
loadDashboardData();
});
}
function switchAdminTab(tabName) {