Mercurial Hosting > chat
changeset 38:436216d17a1b
fix edit and delete
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Tue, 12 Nov 2024 21:53:03 -0700 |
parents | cfd1f92c264f |
children | 471b13e6ce2c |
files | src/chat.js src/index.html.luan |
diffstat | 2 files changed, 15 insertions(+), 6 deletions(-) [+] |
line wrap: on
line diff
--- a/src/chat.js Tue Nov 12 20:01:48 2024 -0700 +++ b/src/chat.js Tue Nov 12 21:53:03 2024 -0700 @@ -96,8 +96,17 @@ let currentPostId; -function deletePost(postId) { - currentPostId = postId; +function getPostId(el) { + while(true) { + let postId = el.getAttribute('post'); + if( postId ) + return postId; + el = el.parentNode; + } +} + +function deletePost(el) { + currentPostId = getPostId(el); let dialog = document.querySelector('dialog[delete_post]'); openModal(dialog); } @@ -113,8 +122,8 @@ div.outerHTML = ''; } -function editPost(postId) { - ajax(`edit_post.js?post=${postId}`); +function editPost(el) { + ajax(`edit_post.js?post=${getPostId(el)}`); } function openEditPost(postId,text) {
--- a/src/index.html.luan Tue Nov 12 20:01:48 2024 -0700 +++ b/src/index.html.luan Tue Nov 12 21:53:03 2024 -0700 @@ -112,8 +112,8 @@ <span pulldown> <img onclick="clickMenu(this)" src="/images/more_vert.svg"> <div> - <span onclick="editPost('<%=user_id%>')">Edit</span> - <span onclick="deletePost('<%=user_id%>')">Delete</span> + <span onclick="editPost(this)">Edit</span> + <span onclick="deletePost(this)">Delete</span> </div> </span> </div>