Sort subcategories alphabetically with Muut always last
Applied sortSubcategories() to submission form picker, admin category list, and admin subcategory checkboxes. Added the helper function to admin.html since it's a standalone file. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
13
admin.html
13
admin.html
@@ -576,6 +576,15 @@
|
|||||||
// ===========================
|
// ===========================
|
||||||
// CATEGORY HELPERS
|
// CATEGORY HELPERS
|
||||||
// ===========================
|
// ===========================
|
||||||
|
function sortSubcategories(subs) {
|
||||||
|
return [...subs].sort((a, b) => {
|
||||||
|
const aM = a.fi.toLowerCase() === 'muut' ? 1 : 0;
|
||||||
|
const bM = b.fi.toLowerCase() === 'muut' ? 1 : 0;
|
||||||
|
if (aM !== bM) return aM - bM;
|
||||||
|
return a.fi.localeCompare(b.fi, 'fi');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
function getCatLabel(id) {
|
function getCatLabel(id) {
|
||||||
const cat = ADMIN.categories.find(c => c.id === id);
|
const cat = ADMIN.categories.find(c => c.id === id);
|
||||||
return cat ? cat.fi : id;
|
return cat ? cat.fi : id;
|
||||||
@@ -589,7 +598,7 @@
|
|||||||
const el = document.getElementById('catList');
|
const el = document.getElementById('catList');
|
||||||
if (!cats.length) { el.innerHTML = `<p class="empty-state">${at('cat_empty')}</p>`; return; }
|
if (!cats.length) { el.innerHTML = `<p class="empty-state">${at('cat_empty')}</p>`; return; }
|
||||||
el.innerHTML = cats.map(c => {
|
el.innerHTML = cats.map(c => {
|
||||||
const subs = (c.subcategories || []).map(s =>
|
const subs = sortSubcategories(c.subcategories || []).map(s =>
|
||||||
`<span class="subcat-tag">${s.fi} <button onclick="removeSubcat('${c.id}','${s.id}')" class="subcat-remove">✕</button></span>`
|
`<span class="subcat-tag">${s.fi} <button onclick="removeSubcat('${c.id}','${s.id}')" class="subcat-remove">✕</button></span>`
|
||||||
).join('');
|
).join('');
|
||||||
return `
|
return `
|
||||||
@@ -670,7 +679,7 @@
|
|||||||
function updateAdminSubcategories(checked = []) {
|
function updateAdminSubcategories(checked = []) {
|
||||||
const catId = document.getElementById('postCategory').value;
|
const catId = document.getElementById('postCategory').value;
|
||||||
const cat = ADMIN.categories.find(c => c.id === catId);
|
const cat = ADMIN.categories.find(c => c.id === catId);
|
||||||
const subs = cat?.subcategories || [];
|
const subs = sortSubcategories(cat?.subcategories || []);
|
||||||
const group = document.getElementById('adminSubcatGroup');
|
const group = document.getElementById('adminSubcatGroup');
|
||||||
const box = document.getElementById('adminSubcatCheckboxes');
|
const box = document.getElementById('adminSubcatCheckboxes');
|
||||||
if (!subs.length) { group.style.display = 'none'; box.innerHTML = ''; return; }
|
if (!subs.length) { group.style.display = 'none'; box.innerHTML = ''; return; }
|
||||||
|
|||||||
16
script.js
16
script.js
@@ -81,6 +81,18 @@ function applyTranslations() {
|
|||||||
document.querySelectorAll('[data-i18n-ph]').forEach(el => { el.placeholder = t(el.dataset.i18nPh); });
|
document.querySelectorAll('[data-i18n-ph]').forEach(el => { el.placeholder = t(el.dataset.i18nPh); });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ===========================
|
||||||
|
// HELPERS
|
||||||
|
// ===========================
|
||||||
|
function sortSubcategories(subs) {
|
||||||
|
return [...subs].sort((a, b) => {
|
||||||
|
const aM = a.fi.toLowerCase() === 'muut' ? 1 : 0;
|
||||||
|
const bM = b.fi.toLowerCase() === 'muut' ? 1 : 0;
|
||||||
|
if (aM !== bM) return aM - bM;
|
||||||
|
return a.fi.localeCompare(b.fi, 'fi');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
// ===========================
|
// ===========================
|
||||||
// API
|
// API
|
||||||
// ===========================
|
// ===========================
|
||||||
@@ -256,7 +268,7 @@ function renderSubFilters() {
|
|||||||
if (!container) return;
|
if (!container) return;
|
||||||
if (currentFilter === 'all') { container.innerHTML = ''; return; }
|
if (currentFilter === 'all') { container.innerHTML = ''; return; }
|
||||||
const cat = APP.categories.find(c => c.id === currentFilter);
|
const cat = APP.categories.find(c => c.id === currentFilter);
|
||||||
const subs = (cat?.subcategories || []).filter(s => countPostsInSubcategory(currentFilter, s.id) > 0);
|
const subs = sortSubcategories((cat?.subcategories || []).filter(s => countPostsInSubcategory(currentFilter, s.id) > 0));
|
||||||
if (!subs.length) { container.innerHTML = ''; return; }
|
if (!subs.length) { container.innerHTML = ''; return; }
|
||||||
container.innerHTML =
|
container.innerHTML =
|
||||||
`<button class="sub-filter-btn ${currentSubFilter === 'all' ? 'active' : ''}" onclick="setSubFilter('all',this)">Kaikki</button>` +
|
`<button class="sub-filter-btn ${currentSubFilter === 'all' ? 'active' : ''}" onclick="setSubFilter('all',this)">Kaikki</button>` +
|
||||||
@@ -453,7 +465,7 @@ function setSubmitType(type) {
|
|||||||
function updateSubcategoryPicker() {
|
function updateSubcategoryPicker() {
|
||||||
const catId = document.getElementById('sub-category').value;
|
const catId = document.getElementById('sub-category').value;
|
||||||
const cat = APP.categories.find(c => c.id === catId);
|
const cat = APP.categories.find(c => c.id === catId);
|
||||||
const subs = cat?.subcategories || [];
|
const subs = sortSubcategories(cat?.subcategories || []);
|
||||||
const group = document.getElementById('sub-subcategory-group');
|
const group = document.getElementById('sub-subcategory-group');
|
||||||
const sel = document.getElementById('sub-subcategory');
|
const sel = document.getElementById('sub-subcategory');
|
||||||
if (!subs.length) {
|
if (!subs.length) {
|
||||||
|
|||||||
Reference in New Issue
Block a user