Actualiser js/admin.js
This commit is contained in:
+33
-32
@@ -64,46 +64,47 @@ document.addEventListener('change', (e) => {
|
|||||||
|
|
||||||
// Remplacez les deux fonctions de suppression par celles-ci :
|
// Remplacez les deux fonctions de suppression par celles-ci :
|
||||||
|
|
||||||
async function deleteSingleFilm(id) {
|
// Variable pour stocker la fonction à appeler après confirmation
|
||||||
if (!confirm('Supprimer ce film ?')) return;
|
let pendingDeleteAction = null;
|
||||||
|
|
||||||
const token = localStorage.getItem('token');
|
function showConfirmModal(actionFn) {
|
||||||
const res = await fetch(`${API_URL}?action=delete_film&id=${id}&type=${currentAdminTab}`, {
|
pendingDeleteAction = actionFn;
|
||||||
method: 'DELETE',
|
document.getElementById('confirm-modal').classList.add('open');
|
||||||
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();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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() {
|
async function executeBulkDelete() {
|
||||||
const checked = document.querySelectorAll('.film-checkbox:checked');
|
showConfirmModal(async () => {
|
||||||
const ids = Array.from(checked).map(cb => cb.value);
|
const ids = Array.from(document.querySelectorAll('.film-checkbox:checked')).map(cb => cb.value);
|
||||||
|
await fetch(`${API_URL}?action=bulk_delete`, {
|
||||||
if (ids.length === 0) return;
|
|
||||||
if (!confirm(`Supprimer ces ${ids.length} films ?`)) return;
|
|
||||||
|
|
||||||
try {
|
|
||||||
const res = await fetch(`${API_URL}?action=bulk_delete`, {
|
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
headers: { 'Authorization': localStorage.getItem('token'), 'Content-Type': 'application/json' },
|
||||||
'Authorization': localStorage.getItem('token'),
|
body: JSON.stringify({ ids, type: currentAdminTab })
|
||||||
'Content-Type': 'application/json'
|
|
||||||
},
|
|
||||||
body: JSON.stringify({ ids: ids, type: currentAdminTab })
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const data = await res.json();
|
|
||||||
if (data.success) {
|
|
||||||
document.getElementById('bulk-actions-bar').style.display = 'none';
|
|
||||||
loadDashboardData();
|
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) {
|
function switchAdminTab(tabName) {
|
||||||
|
|||||||
Reference in New Issue
Block a user