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:
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); });
|
||||
}
|
||||
|
||||
// ===========================
|
||||
// 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
|
||||
// ===========================
|
||||
@@ -256,7 +268,7 @@ function renderSubFilters() {
|
||||
if (!container) return;
|
||||
if (currentFilter === 'all') { container.innerHTML = ''; return; }
|
||||
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; }
|
||||
container.innerHTML =
|
||||
`<button class="sub-filter-btn ${currentSubFilter === 'all' ? 'active' : ''}" onclick="setSubFilter('all',this)">Kaikki</button>` +
|
||||
@@ -453,7 +465,7 @@ function setSubmitType(type) {
|
||||
function updateSubcategoryPicker() {
|
||||
const catId = document.getElementById('sub-category').value;
|
||||
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 sel = document.getElementById('sub-subcategory');
|
||||
if (!subs.length) {
|
||||
|
||||
Reference in New Issue
Block a user