Actualiser js/public.js
This commit is contained in:
+22
-15
@@ -1,12 +1,11 @@
|
||||
let films = [];
|
||||
const API_URL = '../api.php';
|
||||
let films = [];
|
||||
let currentPubTab = 'critique';
|
||||
let activeRatingFilter = 0;
|
||||
let activeStreamingFilter = '';
|
||||
let searchQuery = '';
|
||||
let currentPage = 1;
|
||||
const itemsPerPage = 12;
|
||||
let physicalOnlyFilter = false;
|
||||
|
||||
function getStarsHTML(rating) {
|
||||
const r = parseFloat(rating) || 0;
|
||||
@@ -22,8 +21,8 @@ function getStarsHTML(rating) {
|
||||
function generateStreamingSelect() {
|
||||
const select = document.getElementById('pub-streaming-select');
|
||||
if (!select) return;
|
||||
const platforms = new Set(); // Fixed: S et -> Set
|
||||
films.forEach(f => { // Fixed: = > -> =>
|
||||
const platforms = new Set();
|
||||
films.forEach(f => {
|
||||
if (f.type === 'critique' && f.streaming &&
|
||||
f.streaming !== 'Disponible en support physique ou Cinéma' &&
|
||||
f.streaming.trim() !== '') {
|
||||
@@ -57,8 +56,7 @@ async function loadPublicData() {
|
||||
// Écouteur pour le filtre physique
|
||||
const physicalCheckbox = document.getElementById('physical-only-checkbox');
|
||||
if (physicalCheckbox) {
|
||||
physicalCheckbox.addEventListener('change', (e) => {
|
||||
physicalOnlyFilter = e.target.checked;
|
||||
physicalCheckbox.addEventListener('change', () => {
|
||||
currentPage = 1;
|
||||
renderPublicGrid();
|
||||
});
|
||||
@@ -81,6 +79,12 @@ function switchPubTab(tabName) {
|
||||
if (ratingBar) ratingBar.style.display = (tabName === 'critique') ? 'flex' : 'none';
|
||||
if (select) select.style.display = (tabName === 'critique') ? 'block' : 'none';
|
||||
|
||||
// 🔥 Cacher la case physique en mode vidéothèque
|
||||
const physicalBox = document.querySelector('.physical-filter-box');
|
||||
if (physicalBox) {
|
||||
physicalBox.style.display = (tabName === 'critique') ? 'block' : 'none';
|
||||
}
|
||||
|
||||
document.querySelectorAll('.rating-filter-btn').forEach(btn => {
|
||||
btn.classList.remove('active');
|
||||
btn.querySelectorAll('.rf-star').forEach(s => s.classList.remove('filled'));
|
||||
@@ -113,13 +117,16 @@ function renderPublicGrid() {
|
||||
|
||||
let filtered = films.filter(f => f.type === currentPubTab);
|
||||
|
||||
// FILTRE PHYSIQUE UNIQUENENT
|
||||
// 🔥 FILTRE PHYSIQUE UNIQUEMENT (CORRIGÉ)
|
||||
const physicalFilter = document.getElementById('physical-only-checkbox');
|
||||
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');
|
||||
}
|
||||
// Pour la vidéothèque : tout est physique par défaut
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
@@ -148,11 +155,11 @@ function renderPublicGrid() {
|
||||
}
|
||||
|
||||
if (countLabel) {
|
||||
countLabel.textContent = `${filtered.length} ${currentPubTab === 'critique' ? 'critique' : 'œuvre'}${filtered.length > 1 ? 's' : ''}`; // Fixed: filtere d -> filtered
|
||||
countLabel.textContent = `${filtered.length} ${currentPubTab === 'critique' ? 'critique' : 'œuvre'}${filtered.length > 1 ? 's' : ''}`;
|
||||
}
|
||||
|
||||
if (filtered.length === 0) {
|
||||
if (emptyState) emptyState.style.display = 'block'; // Fixed: di splay -> display
|
||||
if (emptyState) emptyState.style.display = 'block';
|
||||
renderPagination(0);
|
||||
return;
|
||||
}
|
||||
@@ -212,14 +219,14 @@ function renderPagination(totalPages) {
|
||||
info.textContent = `Page ${currentPage} / ${totalPages}`;
|
||||
container.appendChild(info);
|
||||
|
||||
const prevBtn = document.createElement('button'); // Fixed: p revBtn -> prevBtn
|
||||
const prevBtn = document.createElement('button');
|
||||
prevBtn.innerHTML = '<i class="ti ti-chevron-left"></i>';
|
||||
prevBtn.disabled = currentPage === 1;
|
||||
prevBtn.onclick = () => { currentPage--; renderPublicGrid(); window.scrollTo({ top: 0, behavior: 'smooth' }); };
|
||||
container.appendChild(prevBtn);
|
||||
|
||||
const maxButtons = 5;
|
||||
let startPage = Math.max(1, currentPage - Math.floor(maxButtons / 2)); // Fixed: curren tPage -> currentPage
|
||||
let startPage = Math.max(1, currentPage - Math.floor(maxButtons / 2));
|
||||
let endPage = Math.min(totalPages, startPage + maxButtons - 1);
|
||||
if (endPage - startPage + 1 < maxButtons) {
|
||||
startPage = Math.max(1, endPage - maxButtons + 1);
|
||||
@@ -237,7 +244,7 @@ function renderPagination(totalPages) {
|
||||
}
|
||||
|
||||
const nextBtn = document.createElement('button');
|
||||
nextBtn.innerHTML = '<i class="ti ti-chevron-right"></i>'; // Fixed: i nnerHTML -> innerHTML
|
||||
nextBtn.innerHTML = '<i class="ti ti-chevron-right"></i>';
|
||||
nextBtn.disabled = currentPage === totalPages;
|
||||
nextBtn.onclick = () => { currentPage++; renderPublicGrid(); window.scrollTo({ top: 0, behavior: 'smooth' }); };
|
||||
container.appendChild(nextBtn);
|
||||
@@ -267,14 +274,14 @@ function openDetail(id) {
|
||||
const dTitle = document.getElementById('d-title');
|
||||
const dMeta = document.getElementById('d-meta');
|
||||
const dBody = document.getElementById('d-body');
|
||||
const detailModalLayout = document.getElementById('detail-modal-layout'); // Fixed: detailModalLa yout
|
||||
const detailModalLayout = document.getElementById('detail-modal-layout');
|
||||
const detailOverlay = document.getElementById('detail-overlay');
|
||||
|
||||
if (f.poster) {
|
||||
if (dPoster) dPoster.src = f.poster;
|
||||
if (dPosterWrap) {
|
||||
dPosterWrap.style.display = 'block';
|
||||
dPosterWrap.className = `detail-poster poster-${f.type}`; // Fixed: poster-$ {f.type}
|
||||
dPosterWrap.className = `detail-poster poster-${f.type}`;
|
||||
}
|
||||
if (detailModalLayout) detailModalLayout.classList.remove('no-poster');
|
||||
} else {
|
||||
@@ -283,7 +290,7 @@ function openDetail(id) {
|
||||
}
|
||||
|
||||
if (dTitle) dTitle.textContent = f.title;
|
||||
if (dMeta) dMeta.textContent = `${f.year ? f.year + ' | ' : ''}${f.director || 'Réalisateur inconnu'}`; // Fixed: Réa lisateur
|
||||
if (dMeta) dMeta.textContent = `${f.year ? f.year + ' | ' : ''}${f.director || 'Réalisateur inconnu'}`;
|
||||
|
||||
if (dBody) {
|
||||
if (f.type === 'critique') {
|
||||
|
||||
Reference in New Issue
Block a user