annotate src/thread.html.luan @ 16:bff178656073

delete function
author Franklin Schmidt <fschmidt@gmail.com>
date Wed, 06 Jul 2022 22:42:42 -0600
parents 0edde02b908c
children 94e26bffd4fb
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
9
9674275019bb reply and edit
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1 local Luan = require "luan:Luan.luan"
9674275019bb reply and edit
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2 local error = Luan.error
9674275019bb reply and edit
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3 local ipairs = Luan.ipairs or error()
9674275019bb reply and edit
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4 local Io = require "luan:Io.luan"
9674275019bb reply and edit
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
5 local Http = require "luan:http/Http.luan"
9674275019bb reply and edit
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
6 local Shared = require "site:/lib/Shared.luan"
9674275019bb reply and edit
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
7 local head = Shared.head or error()
9674275019bb reply and edit
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
8 local header = Shared.header or error()
9674275019bb reply and edit
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
9 local footer = Shared.footer or error()
9674275019bb reply and edit
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
10 local Forum = require "site:/lib/Forum.luan"
9674275019bb reply and edit
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
11 local forum_title = Forum.title or error()
9674275019bb reply and edit
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
12 local Db = require "site:/lib/Db.luan"
9674275019bb reply and edit
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
13 local Post = require "site:/lib/Post.luan"
12
ad1604c72156 fix bbcode
Franklin Schmidt <fschmidt@gmail.com>
parents: 11
diff changeset
14 local Bbcode = require "site:/lib/Bbcode.luan"
ad1604c72156 fix bbcode
Franklin Schmidt <fschmidt@gmail.com>
parents: 11
diff changeset
15 local bbcode_to_html = Bbcode.to_html or error()
16
bff178656073 delete function
Franklin Schmidt <fschmidt@gmail.com>
parents: 15
diff changeset
16 local User = require "site:/lib/User.luan"
9
9674275019bb reply and edit
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
17
11
3ed1e3f3a53a use bbcode_to_html
Franklin Schmidt <fschmidt@gmail.com>
parents: 9
diff changeset
18
16
bff178656073 delete function
Franklin Schmidt <fschmidt@gmail.com>
parents: 15
diff changeset
19 local function deletePost()
bff178656073 delete function
Franklin Schmidt <fschmidt@gmail.com>
parents: 15
diff changeset
20 %><a href="javascript:" onclick="deletePost(parentNode)">delete</a><%
bff178656073 delete function
Franklin Schmidt <fschmidt@gmail.com>
parents: 15
diff changeset
21 end
bff178656073 delete function
Franklin Schmidt <fschmidt@gmail.com>
parents: 15
diff changeset
22
9
9674275019bb reply and edit
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
23 return function()
9674275019bb reply and edit
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
24 local root_id = Http.request.parameters.root or error()
9674275019bb reply and edit
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
25 local docs, total_hits = Db.search("post_root_id:"..root_id,1,1000,{sort="id"})
9674275019bb reply and edit
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
26 local posts = Post.from_docs(docs)
9674275019bb reply and edit
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
27 local subject_html = posts[1].subject_html
16
bff178656073 delete function
Franklin Schmidt <fschmidt@gmail.com>
parents: 15
diff changeset
28 local user = User.current()
bff178656073 delete function
Franklin Schmidt <fschmidt@gmail.com>
parents: 15
diff changeset
29 local user_name = user and user.name
9
9674275019bb reply and edit
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
30 Io.stdout = Http.response.text_writer()
9674275019bb reply and edit
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
31 %>
9674275019bb reply and edit
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
32 <!doctype html>
9674275019bb reply and edit
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
33 <html>
9674275019bb reply and edit
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
34 <head>
9674275019bb reply and edit
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
35 <% head() %>
9674275019bb reply and edit
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
36 <title><%=forum_title%>: <%=subject_html%></title>
9674275019bb reply and edit
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
37 <style>
15
0edde02b908c edit in place
Franklin Schmidt <fschmidt@gmail.com>
parents: 12
diff changeset
38 [message] {
9
9674275019bb reply and edit
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
39 white-space: pre-wrap;
9674275019bb reply and edit
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
40 }
9674275019bb reply and edit
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
41 </style>
15
0edde02b908c edit in place
Franklin Schmidt <fschmidt@gmail.com>
parents: 12
diff changeset
42 <script>
0edde02b908c edit in place
Franklin Schmidt <fschmidt@gmail.com>
parents: 12
diff changeset
43 function cancelEdit(post) {
0edde02b908c edit in place
Franklin Schmidt <fschmidt@gmail.com>
parents: 12
diff changeset
44 let postDiv = document.querySelector('[post="'+post+'"]');
0edde02b908c edit in place
Franklin Schmidt <fschmidt@gmail.com>
parents: 12
diff changeset
45 postDiv.querySelector('[output]').style.display = 'block';
0edde02b908c edit in place
Franklin Schmidt <fschmidt@gmail.com>
parents: 12
diff changeset
46 postDiv.querySelector('[edit]').innerHTML = '';
0edde02b908c edit in place
Franklin Schmidt <fschmidt@gmail.com>
parents: 12
diff changeset
47 }
0edde02b908c edit in place
Franklin Schmidt <fschmidt@gmail.com>
parents: 12
diff changeset
48 function saveEdit(post) {
0edde02b908c edit in place
Franklin Schmidt <fschmidt@gmail.com>
parents: 12
diff changeset
49 let postDiv = document.querySelector('[post="'+post+'"]');
0edde02b908c edit in place
Franklin Schmidt <fschmidt@gmail.com>
parents: 12
diff changeset
50 let text = postDiv.querySelector('textarea').value;
0edde02b908c edit in place
Franklin Schmidt <fschmidt@gmail.com>
parents: 12
diff changeset
51 let postData = 'post=' + post + '&text=' + encodeURIComponent(text);
0edde02b908c edit in place
Franklin Schmidt <fschmidt@gmail.com>
parents: 12
diff changeset
52 ajax("save_edit.js",postData);
0edde02b908c edit in place
Franklin Schmidt <fschmidt@gmail.com>
parents: 12
diff changeset
53 }
16
bff178656073 delete function
Franklin Schmidt <fschmidt@gmail.com>
parents: 15
diff changeset
54
bff178656073 delete function
Franklin Schmidt <fschmidt@gmail.com>
parents: 15
diff changeset
55 function deletePost(span) {
bff178656073 delete function
Franklin Schmidt <fschmidt@gmail.com>
parents: 15
diff changeset
56 span.innerHTML = document.querySelector('[hidden][delete]').innerHTML;
bff178656073 delete function
Franklin Schmidt <fschmidt@gmail.com>
parents: 15
diff changeset
57 }
bff178656073 delete function
Franklin Schmidt <fschmidt@gmail.com>
parents: 15
diff changeset
58 function deleteNo(span) {
bff178656073 delete function
Franklin Schmidt <fschmidt@gmail.com>
parents: 15
diff changeset
59 span.innerHTML = document.querySelector('[hidden][undelete]').innerHTML;
bff178656073 delete function
Franklin Schmidt <fschmidt@gmail.com>
parents: 15
diff changeset
60 }
bff178656073 delete function
Franklin Schmidt <fschmidt@gmail.com>
parents: 15
diff changeset
61 function deleteYes(span) {
bff178656073 delete function
Franklin Schmidt <fschmidt@gmail.com>
parents: 15
diff changeset
62 let post = span.getAttribute('delete');
bff178656073 delete function
Franklin Schmidt <fschmidt@gmail.com>
parents: 15
diff changeset
63 ajax( '/delete.js?post=' + post );
bff178656073 delete function
Franklin Schmidt <fschmidt@gmail.com>
parents: 15
diff changeset
64 }
15
0edde02b908c edit in place
Franklin Schmidt <fschmidt@gmail.com>
parents: 12
diff changeset
65 </script>
9
9674275019bb reply and edit
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
66 </head>
9674275019bb reply and edit
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
67 <body>
9674275019bb reply and edit
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
68 <% header() %>
9674275019bb reply and edit
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
69 <div content>
9674275019bb reply and edit
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
70 <h1><%=subject_html%></h1>
16
bff178656073 delete function
Franklin Schmidt <fschmidt@gmail.com>
parents: 15
diff changeset
71 <% for _, post in ipairs(posts) do
bff178656073 delete function
Franklin Schmidt <fschmidt@gmail.com>
parents: 15
diff changeset
72 if post.is_deleted then
bff178656073 delete function
Franklin Schmidt <fschmidt@gmail.com>
parents: 15
diff changeset
73 continue
bff178656073 delete function
Franklin Schmidt <fschmidt@gmail.com>
parents: 15
diff changeset
74 end
bff178656073 delete function
Franklin Schmidt <fschmidt@gmail.com>
parents: 15
diff changeset
75 %>
9
9674275019bb reply and edit
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
76 <hr>
15
0edde02b908c edit in place
Franklin Schmidt <fschmidt@gmail.com>
parents: 12
diff changeset
77 <div post="<%=post.id%>">
0edde02b908c edit in place
Franklin Schmidt <fschmidt@gmail.com>
parents: 12
diff changeset
78 <div output>
0edde02b908c edit in place
Franklin Schmidt <fschmidt@gmail.com>
parents: 12
diff changeset
79 <% bbcode_to_html(post.content) %>
0edde02b908c edit in place
Franklin Schmidt <fschmidt@gmail.com>
parents: 12
diff changeset
80 <p>
0edde02b908c edit in place
Franklin Schmidt <fschmidt@gmail.com>
parents: 12
diff changeset
81 <a href="/reply.html?parent=<%=post.id%>">reply</a>
16
bff178656073 delete function
Franklin Schmidt <fschmidt@gmail.com>
parents: 15
diff changeset
82 <% if post.author_name == user_name then %>
15
0edde02b908c edit in place
Franklin Schmidt <fschmidt@gmail.com>
parents: 12
diff changeset
83 - <a href="javascript:ajax('/edit.js?post=<%=post.id%>')">edit</a>
16
bff178656073 delete function
Franklin Schmidt <fschmidt@gmail.com>
parents: 15
diff changeset
84 - <span delete="<%=post.id%>"><%deletePost()%></span>
bff178656073 delete function
Franklin Schmidt <fschmidt@gmail.com>
parents: 15
diff changeset
85 <% end %>
15
0edde02b908c edit in place
Franklin Schmidt <fschmidt@gmail.com>
parents: 12
diff changeset
86 </p>
0edde02b908c edit in place
Franklin Schmidt <fschmidt@gmail.com>
parents: 12
diff changeset
87 </div>
0edde02b908c edit in place
Franklin Schmidt <fschmidt@gmail.com>
parents: 12
diff changeset
88 <div edit></div>
0edde02b908c edit in place
Franklin Schmidt <fschmidt@gmail.com>
parents: 12
diff changeset
89 </div>
9
9674275019bb reply and edit
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
90 <% end %>
9674275019bb reply and edit
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
91 </div>
9674275019bb reply and edit
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
92 <% footer() %>
16
bff178656073 delete function
Franklin Schmidt <fschmidt@gmail.com>
parents: 15
diff changeset
93 <span hidden delete>Delete? <a href="javascript:" onclick="deleteYes(parentNode)">yes</a> / <a href="javascript:" onclick="deleteNo(parentNode)">no</a></span>
bff178656073 delete function
Franklin Schmidt <fschmidt@gmail.com>
parents: 15
diff changeset
94 <span hidden undelete><%deletePost()%></span>
9
9674275019bb reply and edit
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
95 </body>
9674275019bb reply and edit
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
96 </html>
9674275019bb reply and edit
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
97 <%
9674275019bb reply and edit
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
98 end