9
|
1 local Luan = require "luan:Luan.luan"
|
|
2 local error = Luan.error
|
|
3 local ipairs = Luan.ipairs or error()
|
18
|
4 local Time = require "luan:Time.luan"
|
|
5 local time_now = Time.now or error()
|
9
|
6 local Io = require "luan:Io.luan"
|
|
7 local Http = require "luan:http/Http.luan"
|
|
8 local Shared = require "site:/lib/Shared.luan"
|
|
9 local head = Shared.head or error()
|
|
10 local header = Shared.header or error()
|
|
11 local footer = Shared.footer or error()
|
|
12 local Forum = require "site:/lib/Forum.luan"
|
|
13 local forum_title = Forum.title or error()
|
|
14 local Db = require "site:/lib/Db.luan"
|
|
15 local Post = require "site:/lib/Post.luan"
|
12
|
16 local Bbcode = require "site:/lib/Bbcode.luan"
|
|
17 local bbcode_to_html = Bbcode.to_html or error()
|
16
|
18 local User = require "site:/lib/User.luan"
|
9
|
19
|
11
|
20
|
16
|
21 local function deletePost()
|
|
22 %><a href="javascript:" onclick="deletePost(parentNode)">delete</a><%
|
|
23 end
|
|
24
|
9
|
25 return function()
|
|
26 local root_id = Http.request.parameters.root or error()
|
|
27 local docs, total_hits = Db.search("post_root_id:"..root_id,1,1000,{sort="id"})
|
|
28 local posts = Post.from_docs(docs)
|
|
29 local subject_html = posts[1].subject_html
|
16
|
30 local user = User.current()
|
|
31 local user_name = user and user.name
|
18
|
32 local now = time_now()
|
9
|
33 Io.stdout = Http.response.text_writer()
|
|
34 %>
|
|
35 <!doctype html>
|
|
36 <html>
|
|
37 <head>
|
|
38 <% head() %>
|
|
39 <title><%=forum_title%>: <%=subject_html%></title>
|
|
40 <style>
|
18
|
41 div[author] {
|
|
42 margin-bottom: 6px;
|
|
43 font-size: 10px;
|
|
44 }
|
|
45 div[author] img {
|
|
46 width: 28px;
|
|
47 vertical-align: middle;
|
|
48 border-radius: 50%;
|
|
49 }
|
|
50 div[author] a {
|
|
51 font-weight: bold;
|
|
52 }
|
|
53 span[ago] {
|
|
54 color: #888;
|
|
55 }
|
15
|
56 [message] {
|
9
|
57 white-space: pre-wrap;
|
|
58 }
|
18
|
59 textarea {
|
|
60 width: 100%;
|
|
61 max-width: 450px;
|
|
62 height: 100px;
|
|
63 }
|
9
|
64 </style>
|
15
|
65 <script>
|
|
66 function cancelEdit(post) {
|
|
67 let postDiv = document.querySelector('[post="'+post+'"]');
|
|
68 postDiv.querySelector('[output]').style.display = 'block';
|
|
69 postDiv.querySelector('[edit]').innerHTML = '';
|
|
70 }
|
|
71 function saveEdit(post) {
|
|
72 let postDiv = document.querySelector('[post="'+post+'"]');
|
|
73 let text = postDiv.querySelector('textarea').value;
|
|
74 let postData = 'post=' + post + '&text=' + encodeURIComponent(text);
|
|
75 ajax("save_edit.js",postData);
|
|
76 }
|
16
|
77
|
|
78 function deletePost(span) {
|
|
79 span.innerHTML = document.querySelector('[hidden][delete]').innerHTML;
|
|
80 }
|
|
81 function deleteNo(span) {
|
|
82 span.innerHTML = document.querySelector('[hidden][undelete]').innerHTML;
|
|
83 }
|
|
84 function deleteYes(span) {
|
|
85 let post = span.getAttribute('delete');
|
|
86 ajax( '/delete.js?post=' + post );
|
|
87 }
|
18
|
88
|
|
89 function init() {
|
|
90 let spans = document.querySelectorAll('span[ago]');
|
|
91 for( let i=0; i<spans.length; i++ ) {
|
|
92 let span = spans[i];
|
|
93 let date = span.getAttribute('date');
|
|
94 date = parseInt(date);
|
|
95 span.title = new Date(date).toLocaleString();
|
|
96 }
|
|
97 }
|
15
|
98 </script>
|
9
|
99 </head>
|
18
|
100 <body onload="init()">
|
9
|
101 <% header() %>
|
|
102 <div content>
|
|
103 <h1><%=subject_html%></h1>
|
16
|
104 <% for _, post in ipairs(posts) do
|
|
105 if post.is_deleted then
|
|
106 continue
|
|
107 end
|
|
108 %>
|
9
|
109 <hr>
|
15
|
110 <div post="<%=post.id%>">
|
18
|
111 <div author>
|
|
112 <img src="/images/profile.png">
|
|
113 <a href="/whatever"><%= post.author_name %></a>
|
|
114 <span ago date="<%=post.date%>"><% post.ago(now) %> ago</span>
|
|
115 </div>
|
15
|
116 <div output>
|
|
117 <% bbcode_to_html(post.content) %>
|
|
118 <p>
|
|
119 <a href="/reply.html?parent=<%=post.id%>">reply</a>
|
16
|
120 <% if post.author_name == user_name then %>
|
15
|
121 - <a href="javascript:ajax('/edit.js?post=<%=post.id%>')">edit</a>
|
16
|
122 - <span delete="<%=post.id%>"><%deletePost()%></span>
|
|
123 <% end %>
|
15
|
124 </p>
|
|
125 </div>
|
|
126 <div edit></div>
|
|
127 </div>
|
9
|
128 <% end %>
|
|
129 </div>
|
|
130 <% footer() %>
|
16
|
131 <span hidden delete>Delete? <a href="javascript:" onclick="deleteYes(parentNode)">yes</a> / <a href="javascript:" onclick="deleteNo(parentNode)">no</a></span>
|
|
132 <span hidden undelete><%deletePost()%></span>
|
9
|
133 </body>
|
|
134 </html>
|
|
135 <%
|
|
136 end
|