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