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
|
||||
// ===========================
|
||||
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) {
|
||||
const cat = ADMIN.categories.find(c => c.id === id);
|
||||
return cat ? cat.fi : id;
|
||||
@@ -589,7 +598,7 @@
|
||||
const el = document.getElementById('catList');
|
||||
if (!cats.length) { el.innerHTML = `<p class="empty-state">${at('cat_empty')}</p>`; return; }
|
||||
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>`
|
||||
).join('');
|
||||
return `
|
||||
@@ -670,7 +679,7 @@
|
||||
function updateAdminSubcategories(checked = []) {
|
||||
const catId = document.getElementById('postCategory').value;
|
||||
const cat = ADMIN.categories.find(c => c.id === catId);
|
||||
const subs = cat?.subcategories || [];
|
||||
const subs = sortSubcategories(cat?.subcategories || []);
|
||||
const group = document.getElementById('adminSubcatGroup');
|
||||
const box = document.getElementById('adminSubcatCheckboxes');
|
||||
if (!subs.length) { group.style.display = 'none'; box.innerHTML = ''; return; }
|
||||
|
||||
Reference in New Issue
Block a user