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()
|
9
|
16
|
11
|
17
|
9
|
18 return function()
|
|
19 local root_id = Http.request.parameters.root or error()
|
|
20 local docs, total_hits = Db.search("post_root_id:"..root_id,1,1000,{sort="id"})
|
|
21 local posts = Post.from_docs(docs)
|
|
22 local subject_html = posts[1].subject_html
|
|
23 Io.stdout = Http.response.text_writer()
|
|
24 %>
|
|
25 <!doctype html>
|
|
26 <html>
|
|
27 <head>
|
|
28 <% head() %>
|
|
29 <title><%=forum_title%>: <%=subject_html%></title>
|
|
30 <style>
|
15
|
31 [message] {
|
9
|
32 white-space: pre-wrap;
|
|
33 }
|
|
34 </style>
|
15
|
35 <script>
|
|
36 function cancelEdit(post) {
|
|
37 let postDiv = document.querySelector('[post="'+post+'"]');
|
|
38 postDiv.querySelector('[output]').style.display = 'block';
|
|
39 postDiv.querySelector('[edit]').innerHTML = '';
|
|
40 }
|
|
41
|
|
42 function saveEdit(post) {
|
|
43 let postDiv = document.querySelector('[post="'+post+'"]');
|
|
44 let text = postDiv.querySelector('textarea').value;
|
|
45 let postData = 'post=' + post + '&text=' + encodeURIComponent(text);
|
|
46 ajax("save_edit.js",postData);
|
|
47 }
|
|
48 </script>
|
9
|
49 </head>
|
|
50 <body>
|
|
51 <% header() %>
|
|
52 <div content>
|
|
53 <h1><%=subject_html%></h1>
|
|
54 <% for _, post in ipairs(posts) do %>
|
|
55 <hr>
|
15
|
56 <div post="<%=post.id%>">
|
|
57 <div output>
|
|
58 <% bbcode_to_html(post.content) %>
|
|
59 <p>
|
|
60 <a href="/reply.html?parent=<%=post.id%>">reply</a>
|
|
61 - <a href="javascript:ajax('/edit.js?post=<%=post.id%>')">edit</a>
|
|
62 </p>
|
|
63 </div>
|
|
64 <div edit></div>
|
|
65 </div>
|
9
|
66 <% end %>
|
|
67 </div>
|
|
68 <% footer() %>
|
|
69 </body>
|
|
70 </html>
|
|
71 <%
|
|
72 end
|