Actualiser js/admin.js
This commit is contained in:
+24
-17
@@ -67,7 +67,6 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||
function initEventListeners() {
|
||||
const filmForm = document.getElementById('film-form');
|
||||
if (filmForm) filmForm.addEventListener('submit', saveFilmForm);
|
||||
|
||||
const csvInput = document.getElementById('csv-file');
|
||||
if (csvInput) {
|
||||
csvInput.addEventListener('change', (e) => {
|
||||
@@ -110,21 +109,27 @@ function renderAdminTable() {
|
||||
const tbody = document.getElementById('admin-table-body');
|
||||
if (!tbody) return;
|
||||
tbody.innerHTML = '';
|
||||
|
||||
const searchInput = document.getElementById('search-input');
|
||||
const currentSearch = searchInput ? searchInput.value.toLowerCase() : '';
|
||||
const physicalFilter = document.getElementById('admin-physical-checkbox');
|
||||
|
||||
let filtered = allItems.filter(item => item.type === currentAdminTab);
|
||||
|
||||
if (physicalFilter && physicalFilter.checked) {
|
||||
filtered = filtered.filter(f => {
|
||||
// Pour les critiques : vérifier le champ streaming
|
||||
if (f.type === 'critique') {
|
||||
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) {
|
||||
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');
|
||||
@@ -155,6 +160,7 @@ function renderAdminTable() {
|
||||
});
|
||||
|
||||
renderPagination(totalPages, filtered.length);
|
||||
|
||||
const selectAll = document.getElementById('select-all-checkbox');
|
||||
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;
|
||||
const wrapper = document.querySelector('.physical-filter-admin');
|
||||
if (wrapper) wrapper.style.display = (tabName === 'videotheque') ? 'none' : 'flex';
|
||||
|
||||
document.querySelectorAll('.tab-btn').forEach(b => b.classList.remove('active'));
|
||||
document.getElementById(`btn-tab-${tabName}`).classList.add('active');
|
||||
|
||||
@@ -294,11 +299,11 @@ function openEditModal(id) {
|
||||
document.getElementById('f-aspect').value = item.aspect_ratio || '';
|
||||
document.getElementById('f-ean').value = item.ean_isbn13 || '';
|
||||
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('admin-modal').classList.add('open');
|
||||
}
|
||||
}
|
||||
|
||||
function closeAdminModal() { document.getElementById('admin-modal').classList.remove('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';
|
||||
} catch(e) { console.error(e); }
|
||||
}
|
||||
|
||||
function closeConfigModal() { document.getElementById('config-modal').classList.remove('open'); }
|
||||
|
||||
function openPasswordModal() {
|
||||
@@ -319,6 +325,7 @@ function openPasswordModal() {
|
||||
document.getElementById('new-password-confirm').value = '';
|
||||
document.getElementById('password-modal').classList.add('open');
|
||||
}
|
||||
|
||||
function closePasswordModal() { document.getElementById('password-modal').classList.remove('open'); }
|
||||
|
||||
function logout() { localStorage.removeItem('token'); window.location.href = 'login.html'; }
|
||||
@@ -328,12 +335,21 @@ async function saveFilmForm(e) {
|
||||
const payload = {
|
||||
type: currentAdminTab,
|
||||
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 : '',
|
||||
ean_isbn13: document.getElementById('f-ean') ? document.getElementById('f-ean').value : '',
|
||||
number_of_discs: document.getElementById('f-discs') ? document.getElementById('f-discs').value : 1,
|
||||
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 {
|
||||
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); }
|
||||
}
|
||||
|
||||
// ══════════════════════════════════════════════════════════════
|
||||
// IMPORT CRITIQUE
|
||||
// ══════════════════════════════════════════════════════════════
|
||||
async function handleCritiqueUpload(input) {
|
||||
if (!input.files || input.files.length === 0) return;
|
||||
let allData = [];
|
||||
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.'); }
|
||||
|
||||
showImportModal(allData.length, 'critique');
|
||||
let processed = 0;
|
||||
for (let i = 0; i < allData.length; i += 10) {
|
||||
@@ -366,15 +378,11 @@ async function handleCritiqueUpload(input) {
|
||||
loadDashboardData();
|
||||
}
|
||||
|
||||
// ══════════════════════════════════════════════════════════════
|
||||
// IMPORT VIDÉOTHÈQUE
|
||||
// ══════════════════════════════════════════════════════════════
|
||||
async function handleVideothequeUpload(input) {
|
||||
if (!input.files || input.files.length === 0) return;
|
||||
let allData = [];
|
||||
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.'); }
|
||||
|
||||
showImportModal(allData.length, 'videotheque');
|
||||
let processed = 0;
|
||||
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) {
|
||||
const msgEl = document.getElementById('success-modal-message');
|
||||
const modalEl = document.getElementById('success-modal');
|
||||
|
||||
Reference in New Issue
Block a user