Actualiser js/admin.js
This commit is contained in:
+17
-29
@@ -20,7 +20,9 @@ function initEventListeners() {
|
|||||||
const filmForm = document.getElementById('film-form');
|
const filmForm = document.getElementById('film-form');
|
||||||
if (filmForm) filmForm.addEventListener('submit', saveFilmForm);
|
if (filmForm) filmForm.addEventListener('submit', saveFilmForm);
|
||||||
|
|
||||||
// Fermeture des modales en cliquant sur le fond ou la croix
|
const csvInput = document.getElementById('csv-file');
|
||||||
|
if (csvInput) csvInput.addEventListener('change', (e) => handleCsvUpload(e.target));
|
||||||
|
|
||||||
document.addEventListener('click', (e) => {
|
document.addEventListener('click', (e) => {
|
||||||
if (e.target.classList.contains('modal-close') || e.target.closest('.modal-close')) {
|
if (e.target.classList.contains('modal-close') || e.target.closest('.modal-close')) {
|
||||||
const overlay = e.target.closest('.overlay');
|
const overlay = e.target.closest('.overlay');
|
||||||
@@ -32,10 +34,9 @@ function initEventListeners() {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/ Remplacez la fonction loadDashboardData existante par celle-ci
|
// ── CHARGEMENT DES DONNÉES (Anti-cache) ──
|
||||||
async function loadDashboardData() {
|
async function loadDashboardData() {
|
||||||
try {
|
try {
|
||||||
// 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' });
|
const res = await fetch(`${API_URL}?action=get_films`, { cache: 'no-store' });
|
||||||
allItems = await res.json();
|
allItems = await res.json();
|
||||||
|
|
||||||
@@ -116,7 +117,7 @@ function closeConfirmModal() {
|
|||||||
pendingDeleteAction = null;
|
pendingDeleteAction = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Remplacez la fonction executeBulkDelete existante par celle-ci
|
// ── ACTIONS CRUD (SUPPRESSION SÉCURISÉE) ──
|
||||||
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;
|
||||||
@@ -128,9 +129,7 @@ async function executeBulkDelete() {
|
|||||||
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 })
|
||||||
});
|
});
|
||||||
|
if (!res.ok) throw new Error("Erreur serveur lors de la suppression multiple.");
|
||||||
// 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');
|
||||||
@@ -143,7 +142,6 @@ async function executeBulkDelete() {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Remplacez la fonction deleteSingleFilm existante par celle-ci
|
|
||||||
async function deleteSingleFilm(id) {
|
async function deleteSingleFilm(id) {
|
||||||
showConfirmModal(async () => {
|
showConfirmModal(async () => {
|
||||||
try {
|
try {
|
||||||
@@ -151,9 +149,7 @@ async function deleteSingleFilm(id) {
|
|||||||
method: 'DELETE',
|
method: 'DELETE',
|
||||||
headers: { 'Authorization': localStorage.getItem('token') }
|
headers: { 'Authorization': localStorage.getItem('token') }
|
||||||
});
|
});
|
||||||
|
if (!res.ok) throw new Error("Erreur serveur lors de la suppression.");
|
||||||
if (!res.ok) throw new Error("Erreur du serveur lors de la suppression unique");
|
|
||||||
|
|
||||||
loadDashboardData();
|
loadDashboardData();
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error('Erreur delete :', err);
|
console.error('Erreur delete :', err);
|
||||||
@@ -261,9 +257,7 @@ async function saveFilmForm(e) {
|
|||||||
});
|
});
|
||||||
closeAdminModal();
|
closeAdminModal();
|
||||||
loadDashboardData();
|
loadDashboardData();
|
||||||
} catch (err) {
|
} catch (err) { console.error('Erreur sauvegarde :', err); }
|
||||||
console.error('Erreur lors de la sauvegarde :', err);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ── IMPORT CSV ──
|
// ── IMPORT CSV ──
|
||||||
@@ -282,23 +276,22 @@ async function handleCsvUpload(input) {
|
|||||||
body: formData
|
body: formData
|
||||||
});
|
});
|
||||||
input.value = '';
|
input.value = '';
|
||||||
|
closeConfigModal();
|
||||||
loadDashboardData();
|
loadDashboardData();
|
||||||
} catch (err) {
|
} catch (err) { console.error('Erreur import CSV :', err); }
|
||||||
console.error('Erreur lors de l\'import CSV :', err);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ── SAUVEGARDE DE LA CLÉ TMDB ──
|
// ── SAUVEGARDE CLÉ TMDB ──
|
||||||
function saveTmdbKey() {
|
function saveTmdbKey() {
|
||||||
const input = document.getElementById('tmdb-key-input');
|
const input = document.getElementById('tmdb-key-input');
|
||||||
if (input && input.value) {
|
if (input && input.value) {
|
||||||
localStorage.setItem('tmdb_key', input.value);
|
localStorage.setItem('tmdb_key', input.value);
|
||||||
alert('Clé TMDB sauvegardée localement avec succès.');
|
alert('Clé sauvegardée localement.');
|
||||||
closeConfigModal();
|
closeConfigModal();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ── MISE A JOUR DU MOT DE PASSE ──
|
// ── SAUVEGARDE MOT DE PASSE ──
|
||||||
async function saveNewPassword() {
|
async function saveNewPassword() {
|
||||||
const pwdInput = document.getElementById('new-password-input');
|
const pwdInput = document.getElementById('new-password-input');
|
||||||
const pwdConfirm = document.getElementById('new-password-confirm');
|
const pwdConfirm = document.getElementById('new-password-confirm');
|
||||||
@@ -321,10 +314,7 @@ async function saveNewPassword() {
|
|||||||
try {
|
try {
|
||||||
const response = await fetch(`${API_URL}?action=update_password`, {
|
const response = await fetch(`${API_URL}?action=update_password`, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
headers: { 'Authorization': localStorage.getItem('token'), 'Content-Type': 'application/json' },
|
||||||
'Authorization': localStorage.getItem('token'),
|
|
||||||
'Content-Type': 'application/json'
|
|
||||||
},
|
|
||||||
body: JSON.stringify({ new_password: pwdInput.value })
|
body: JSON.stringify({ new_password: pwdInput.value })
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -334,10 +324,8 @@ async function saveNewPassword() {
|
|||||||
pwdConfirm.value = '';
|
pwdConfirm.value = '';
|
||||||
errorMsg.style.display = "none";
|
errorMsg.style.display = "none";
|
||||||
closePasswordModal();
|
closePasswordModal();
|
||||||
alert('Mot de passe mis à jour avec succès.');
|
alert('Mot de passe mis à jour.');
|
||||||
loadDashboardData(); // Recharge pour faire disparaître le bandeau orange si existant
|
loadDashboardData();
|
||||||
}
|
|
||||||
} catch (err) {
|
|
||||||
console.error('Erreur lors de la mise à jour du mot de passe :', err);
|
|
||||||
}
|
}
|
||||||
|
} catch (err) { console.error('Erreur mise à jour mot de passe :', err); }
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user