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 <noreply@anthropic.com>
This commit is contained in:
31
admin.html
31
admin.html
@@ -281,6 +281,13 @@
|
||||
<input type="text" id="postAuthor" placeholder="esim. Anna K." />
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label>Omistaja <small style="color:#7a5c3e;font-weight:normal;text-transform:none">(linkitä rekisteröityneeseen käyttäjään)</small></label>
|
||||
<select id="postOwner">
|
||||
<option value="">— Ei linkitetty —</option>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label id="lbl_desc">Kuvaus</label>
|
||||
<textarea id="postDesc" rows="2" placeholder="Lyhyt houkutteleva kuvaus..."></textarea>
|
||||
@@ -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 = `<option value="">— Ei linkitetty —</option>` +
|
||||
(ADMIN.users || []).map(u => `<option value="${u.id}">${u.nickname}${u.email ? ' (' + u.email + ')' : ''}</option>`).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 = '';
|
||||
|
||||
Reference in New Issue
Block a user