annotate src/thread.html.luan @ 15:0edde02b908c

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