From 8eee5ee0ca72a203ccabdfd092acf364c480a88a Mon Sep 17 00:00:00 2001 From: Jukka Lampikoski Date: Sun, 8 Mar 2026 13:32:48 +0200 Subject: [PATCH] Add owner dropdown to admin for linking posts to registered users Allows reassigning posts to registered users via submittedBy field. Shows validated badge and bold author name for linked posts. Co-Authored-By: Claude Opus 4.6 --- admin.html | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/admin.html b/admin.html index cc4a086..f2663d6 100644 --- a/admin.html +++ b/admin.html @@ -281,6 +281,13 @@ +
+ + +
+
@@ -492,6 +499,7 @@ document.getElementById('backLink').textContent = at('back'); document.getElementById('saveBtn').textContent = at('save'); populateCategorySelect(); + populateOwnerSelect(); renderCatList(); renderPostList(); renderUserList(); @@ -676,6 +684,13 @@ updateAdminSubcategories(); } + function populateOwnerSelect(currentUserId = '') { + const sel = document.getElementById('postOwner'); + sel.innerHTML = `` + + (ADMIN.users || []).map(u => ``).join(''); + if (currentUserId) sel.value = currentUserId; + } + function updateAdminSubcategories(checked = []) { const catId = document.getElementById('postCategory').value; const cat = ADMIN.categories.find(c => c.id === catId); @@ -755,6 +770,20 @@ ].filter(Boolean); const post = { title, emoji, category, subcategory, author, desc, images, type: currentType }; + // Omistaja / submittedBy + const ownerId = document.getElementById('postOwner').value; + if (ownerId) { + const owner = (ADMIN.users || []).find(u => u.id === ownerId); + post.submittedBy = { userId: ownerId, nickname: owner?.nickname || author, validated: true }; + if (!author && owner) post.author = owner.nickname; + } else { + // Keep existing submittedBy if editing unless explicitly cleared + if (editingId) { + const existing = ADMIN.posts.find(p => p.id === editingId); + if (existing?.submittedBy && !ownerId) post.submittedBy = null; + } + } + if (currentType === 'recipe') { post.time = document.getElementById('postTime').value.trim(); post.servings = document.getElementById('postServings').value.trim(); @@ -795,6 +824,7 @@ document.getElementById('postTitle').value = p.title; document.getElementById('postCategory').value = p.category; document.getElementById('postAuthor').value = p.author || ''; + populateOwnerSelect(p.submittedBy?.userId || ''); // Load subcategory checkboxes with existing values const existingSubs = Array.isArray(p.subcategory) ? p.subcategory : (p.subcategory ? [p.subcategory] : []); updateAdminSubcategories(existingSubs); @@ -833,6 +863,7 @@ editingId = null; document.getElementById('postTitle').value = ''; document.getElementById('postAuthor').value = ''; + populateOwnerSelect(''); updateAdminSubcategories([]); document.getElementById('postDesc').value = ''; document.getElementById('postTime').value = '';