Actualiser js/admin.js
This commit is contained in:
+15
-48
@@ -90,11 +90,10 @@ function initEventListeners() {
|
||||
const csvInput = document.getElementById('csv-file');
|
||||
if (csvInput) csvInput.addEventListener('change', (e) => handleCsvUpload(e.target));
|
||||
|
||||
// Ajoutez ceci pour la recherche
|
||||
const searchInput = document.getElementById('search-input');
|
||||
if (searchInput) {
|
||||
searchInput.addEventListener('input', (e) => {
|
||||
searchQuery = e.target.value;
|
||||
currentPage = 1;
|
||||
searchInput.addEventListener('input', () => {
|
||||
renderAdminTable();
|
||||
});
|
||||
}
|
||||
@@ -129,61 +128,36 @@ function renderAdminTable() {
|
||||
if (!tbody) return;
|
||||
tbody.innerHTML = '';
|
||||
|
||||
// 1. Filtrage par onglet
|
||||
// Récupérer la valeur de recherche
|
||||
const searchInput = document.getElementById('search-input');
|
||||
const searchQuery = searchInput ? searchInput.value.toLowerCase() : '';
|
||||
|
||||
// Filtrer les éléments
|
||||
let filtered = allItems.filter(item => item.type === currentAdminTab);
|
||||
|
||||
// 2. Filtrage par recherche
|
||||
if (searchQuery) {
|
||||
const q = searchQuery.toLowerCase();
|
||||
filtered = filtered.filter(f =>
|
||||
f.title.toLowerCase().includes(q) ||
|
||||
(f.director && f.director.toLowerCase().includes(q))
|
||||
f.title.toLowerCase().includes(searchQuery) ||
|
||||
(f.director && f.director.toLowerCase().includes(searchQuery))
|
||||
);
|
||||
}
|
||||
|
||||
// 3. Mise à jour du compteur
|
||||
const countLabel = document.getElementById('admin-count-label');
|
||||
if (countLabel) countLabel.textContent = `${filtered.length} élément(s)`;
|
||||
if(countLabel) countLabel.textContent = `${filtered.length} élément(s)`;
|
||||
|
||||
// 4. Pagination
|
||||
const totalPages = Math.ceil(filtered.length / itemsPerPage) || 1;
|
||||
if (currentPage > totalPages) currentPage = totalPages;
|
||||
const startIdx = (currentPage - 1) * itemsPerPage;
|
||||
const pageItems = filtered.slice(startIdx, startIdx + itemsPerPage);
|
||||
|
||||
// 5. Rendu
|
||||
pageItems.forEach(f => {
|
||||
filtered.forEach(f => {
|
||||
const tr = document.createElement('tr');
|
||||
|
||||
let infoHtml = '';
|
||||
if (currentAdminTab === 'critique') {
|
||||
infoHtml = `
|
||||
<div class="info-cell">
|
||||
<span class="tbl-stars">${getStarsHTML(f.rating)}</span>
|
||||
<span class="rating-badge">${parseFloat(f.rating).toFixed(1)}</span>
|
||||
</div>`;
|
||||
|
||||
if (f.streaming && f.streaming !== 'Disponible en support physique ou Cinéma') {
|
||||
infoHtml += `<span class="streaming-badge" title="${f.streaming}">${f.streaming}</span>`;
|
||||
} else {
|
||||
infoHtml += `<span class="physical-badge">🎟️ Cinéma / Physique</span>`;
|
||||
}
|
||||
} else {
|
||||
infoHtml = `<span class="badge-format">${f.format || '-'}</span>`;
|
||||
if (f.length) infoHtml += `<span style="font-size:0.8rem; color:var(--muted); margin-left:0.4rem;">${f.length}</span>`;
|
||||
}
|
||||
|
||||
tr.innerHTML = `
|
||||
<td>
|
||||
<input type="checkbox" class="film-checkbox" value="${f.id}" onclick="toggleSingleSelect('${f.id}', this)">
|
||||
<td style="text-align:center;">
|
||||
<input type="checkbox" class="film-checkbox" value="${f.id}" onclick="updateBulkBar()">
|
||||
</td>
|
||||
<td>
|
||||
<td style="text-align:center;">
|
||||
${f.poster ? `<img src="${f.poster}" class="thumb" alt="Affiche">` : '<div class="thumb-ph"><i class="ti ti-photo"></i></div>'}
|
||||
</td>
|
||||
<td><strong>${f.title}</strong></td>
|
||||
<td>${f.year || '-'}</td>
|
||||
<td>${f.director || '-'}</td>
|
||||
<td><div class="info-cell">${infoHtml}</div></td>
|
||||
<td>${currentAdminTab === 'critique' ? `<span class="tbl-stars">${'★'.repeat(f.rating || 0)}</span>` : `<span class="badge-format">${f.format || '-'}</span>`}</td>
|
||||
<td>
|
||||
<div class="tbl-actions">
|
||||
<button onclick="openEditModal('${f.id}')" title="Éditer"><i class="ti ti-edit"></i></button>
|
||||
@@ -192,13 +166,6 @@ function renderAdminTable() {
|
||||
</td>`;
|
||||
tbody.appendChild(tr);
|
||||
});
|
||||
|
||||
// Synchronisation checkboxes
|
||||
document.querySelectorAll('.film-checkbox').forEach(cb => {
|
||||
cb.checked = selectedIds.has(cb.value);
|
||||
});
|
||||
|
||||
renderPagination(totalPages, filtered.length);
|
||||
}
|
||||
|
||||
// ── SÉLECTION ─
|
||||
|
||||
Reference in New Issue
Block a user