Actualiser js/admin.js

This commit is contained in:
2026-06-23 09:03:51 +02:00
parent ae0cc842bf
commit 17e70f7b9b
+23 -16
View File
@@ -67,7 +67,6 @@ document.addEventListener('DOMContentLoaded', () => {
function initEventListeners() { 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);
const csvInput = document.getElementById('csv-file'); const csvInput = document.getElementById('csv-file');
if (csvInput) { if (csvInput) {
csvInput.addEventListener('change', (e) => { csvInput.addEventListener('change', (e) => {
@@ -110,21 +109,27 @@ function renderAdminTable() {
const tbody = document.getElementById('admin-table-body'); const tbody = document.getElementById('admin-table-body');
if (!tbody) return; if (!tbody) return;
tbody.innerHTML = ''; tbody.innerHTML = '';
const searchInput = document.getElementById('search-input'); const searchInput = document.getElementById('search-input');
const currentSearch = searchInput ? searchInput.value.toLowerCase() : ''; const currentSearch = searchInput ? searchInput.value.toLowerCase() : '';
const physicalFilter = document.getElementById('admin-physical-checkbox'); const physicalFilter = document.getElementById('admin-physical-checkbox');
let filtered = allItems.filter(item => item.type === currentAdminTab); let filtered = allItems.filter(item => item.type === currentAdminTab);
if (physicalFilter && physicalFilter.checked) { if (physicalFilter && physicalFilter.checked) {
filtered = filtered.filter(f => { filtered = filtered.filter(f => {
// Pour les critiques : vérifier le champ streaming
if (f.type === 'critique') { if (f.type === 'critique') {
return f.streaming && f.streaming.toLowerCase().includes('support physique'); return f.streaming && f.streaming.toLowerCase().includes('support physique');
} }
return true; // ✅ FIX : On garde les éléments de la vidéothèque si le filtre est coché par erreur
}); });
} }
if (currentSearch) { if (currentSearch) {
filtered = filtered.filter(f => f.title.toLowerCase().includes(currentSearch) || (f.director && f.director.toLowerCase().includes(currentSearch))); filtered = filtered.filter(f =>
f.title.toLowerCase().includes(currentSearch) ||
(f.director && f.director.toLowerCase().includes(currentSearch))
);
} }
const countLabel = document.getElementById('admin-count-label'); const countLabel = document.getElementById('admin-count-label');
@@ -155,6 +160,7 @@ function renderAdminTable() {
}); });
renderPagination(totalPages, filtered.length); renderPagination(totalPages, filtered.length);
const selectAll = document.getElementById('select-all-checkbox'); const selectAll = document.getElementById('select-all-checkbox');
if (selectAll) selectAll.checked = pageItems.length > 0 && pageItems.every(f => selectedIds.has(String(f.id))); if (selectAll) selectAll.checked = pageItems.length > 0 && pageItems.every(f => selectedIds.has(String(f.id)));
} }
@@ -258,7 +264,6 @@ function switchAdminTab(tabName) {
physicalFilter.checked = false; physicalFilter.checked = false;
const wrapper = document.querySelector('.physical-filter-admin'); const wrapper = document.querySelector('.physical-filter-admin');
if (wrapper) wrapper.style.display = (tabName === 'videotheque') ? 'none' : 'flex'; if (wrapper) wrapper.style.display = (tabName === 'videotheque') ? 'none' : 'flex';
document.querySelectorAll('.tab-btn').forEach(b => b.classList.remove('active')); document.querySelectorAll('.tab-btn').forEach(b => b.classList.remove('active'));
document.getElementById(`btn-tab-${tabName}`).classList.add('active'); document.getElementById(`btn-tab-${tabName}`).classList.add('active');
@@ -294,7 +299,7 @@ function openEditModal(id) {
document.getElementById('f-aspect').value = item.aspect_ratio || ''; document.getElementById('f-aspect').value = item.aspect_ratio || '';
document.getElementById('f-ean').value = item.ean_isbn13 || ''; document.getElementById('f-ean').value = item.ean_isbn13 || '';
document.getElementById('f-discs').value = item.number_of_discs || 1; document.getElementById('f-discs').value = item.number_of_discs || 1;
document.getElementById('f-actors').value = item.actors || ''; // 🔥 NOUVEAU document.getElementById('f-actors').value = item.actors || '';
document.getElementById('f-description').value = item.description || ''; document.getElementById('f-description').value = item.description || '';
} }
document.getElementById('admin-modal').classList.add('open'); document.getElementById('admin-modal').classList.add('open');
@@ -311,6 +316,7 @@ async function openConfigModal() {
document.getElementById('tmdb-key-input').placeholder = data.tmdb_api_key ? '✅ Clé configurée (laisser vide pour garder)' : 'Entrez votre clé TMDB'; document.getElementById('tmdb-key-input').placeholder = data.tmdb_api_key ? '✅ Clé configurée (laisser vide pour garder)' : 'Entrez votre clé TMDB';
} catch(e) { console.error(e); } } catch(e) { console.error(e); }
} }
function closeConfigModal() { document.getElementById('config-modal').classList.remove('open'); } function closeConfigModal() { document.getElementById('config-modal').classList.remove('open'); }
function openPasswordModal() { function openPasswordModal() {
@@ -319,6 +325,7 @@ function openPasswordModal() {
document.getElementById('new-password-confirm').value = ''; document.getElementById('new-password-confirm').value = '';
document.getElementById('password-modal').classList.add('open'); document.getElementById('password-modal').classList.add('open');
} }
function closePasswordModal() { document.getElementById('password-modal').classList.remove('open'); } function closePasswordModal() { document.getElementById('password-modal').classList.remove('open'); }
function logout() { localStorage.removeItem('token'); window.location.href = 'login.html'; } function logout() { localStorage.removeItem('token'); window.location.href = 'login.html'; }
@@ -328,12 +335,21 @@ async function saveFilmForm(e) {
const payload = { const payload = {
type: currentAdminTab, type: currentAdminTab,
id: document.getElementById('f-id').value, id: document.getElementById('f-id').value,
// ... autres champs ... title: document.getElementById('f-title').value,
year: document.getElementById('f-year').value,
director: document.getElementById('f-director').value,
poster: document.getElementById('f-poster').value,
rating: document.getElementById('f-rating') ? document.getElementById('f-rating').value : '',
review: document.getElementById('f-review') ? document.getElementById('f-review').value : '',
streaming: document.getElementById('f-streaming') ? document.getElementById('f-streaming').value : '',
format: document.getElementById('f-format') ? document.getElementById('f-format').value : '',
length: document.getElementById('f-length') ? document.getElementById('f-length').value : '',
publisher: document.getElementById('f-publisher') ? document.getElementById('f-publisher').value : '',
aspect_ratio: document.getElementById('f-aspect') ? document.getElementById('f-aspect').value : '', aspect_ratio: document.getElementById('f-aspect') ? document.getElementById('f-aspect').value : '',
ean_isbn13: document.getElementById('f-ean') ? document.getElementById('f-ean').value : '', ean_isbn13: document.getElementById('f-ean') ? document.getElementById('f-ean').value : '',
number_of_discs: document.getElementById('f-discs') ? document.getElementById('f-discs').value : 1, number_of_discs: document.getElementById('f-discs') ? document.getElementById('f-discs').value : 1,
description: document.getElementById('f-description') ? document.getElementById('f-description').value : '', description: document.getElementById('f-description') ? document.getElementById('f-description').value : '',
actors: document.getElementById('f-actors') ? document.getElementById('f-actors').value : '' // 🔥 NOUVEAU actors: document.getElementById('f-actors') ? document.getElementById('f-actors').value : ''
}; };
try { try {
await fetch(`${API_URL}?action=save_film`, { method: 'POST', headers: { 'Authorization': localStorage.getItem('token'), 'Content-Type': 'application/json' }, body: JSON.stringify(payload) }); await fetch(`${API_URL}?action=save_film`, { method: 'POST', headers: { 'Authorization': localStorage.getItem('token'), 'Content-Type': 'application/json' }, body: JSON.stringify(payload) });
@@ -341,15 +357,11 @@ async function saveFilmForm(e) {
} catch (err) { console.error(err); } } catch (err) { console.error(err); }
} }
// ══════════════════════════════════════════════════════════════
// IMPORT CRITIQUE
// ══════════════════════════════════════════════════════════════
async function handleCritiqueUpload(input) { async function handleCritiqueUpload(input) {
if (!input.files || input.files.length === 0) return; if (!input.files || input.files.length === 0) return;
let allData = []; let allData = [];
for (const file of input.files) { try { allData = allData.concat(parseCSV(await file.text())); } catch(e) {} } for (const file of input.files) { try { allData = allData.concat(parseCSV(await file.text())); } catch(e) {} }
if (allData.length === 0) { input.value = ''; return alert('❌ Fichier vide.'); } if (allData.length === 0) { input.value = ''; return alert('❌ Fichier vide.'); }
showImportModal(allData.length, 'critique'); showImportModal(allData.length, 'critique');
let processed = 0; let processed = 0;
for (let i = 0; i < allData.length; i += 10) { for (let i = 0; i < allData.length; i += 10) {
@@ -366,15 +378,11 @@ async function handleCritiqueUpload(input) {
loadDashboardData(); loadDashboardData();
} }
// ══════════════════════════════════════════════════════════════
// IMPORT VIDÉOTHÈQUE
// ══════════════════════════════════════════════════════════════
async function handleVideothequeUpload(input) { async function handleVideothequeUpload(input) {
if (!input.files || input.files.length === 0) return; if (!input.files || input.files.length === 0) return;
let allData = []; let allData = [];
for (const file of input.files) { try { allData = allData.concat(parseCSV(await file.text())); } catch(e) {} } for (const file of input.files) { try { allData = allData.concat(parseCSV(await file.text())); } catch(e) {} }
if (allData.length === 0) { input.value = ''; return alert('❌ Fichier vide.'); } if (allData.length === 0) { input.value = ''; return alert('❌ Fichier vide.'); }
showImportModal(allData.length, 'videotheque'); showImportModal(allData.length, 'videotheque');
let processed = 0; let processed = 0;
for (let i = 0; i < allData.length; i += 10) { for (let i = 0; i < allData.length; i += 10) {
@@ -444,7 +452,6 @@ function updateImportInterface() {
} }
} }
// 🔥 FONCTIONS DE LA POP-UP DE SUCCÈS (CORRIGÉES)
function showSuccessModal(message) { function showSuccessModal(message) {
const msgEl = document.getElementById('success-modal-message'); const msgEl = document.getElementById('success-modal-message');
const modalEl = document.getElementById('success-modal'); const modalEl = document.getElementById('success-modal');