annotate src/reply.html.luan @ 9:9674275019bb

reply and edit
author Franklin Schmidt <fschmidt@gmail.com>
date Thu, 30 Jun 2022 00:02:28 -0600
parents
children 24668255cede
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 Io = require "luan:Io.luan"
9674275019bb reply and edit
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4 local Http = require "luan:http/Http.luan"
9674275019bb reply and edit
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
5 local Shared = require "site:/lib/Shared.luan"
9674275019bb reply and edit
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
6 local head = Shared.head or error()
9674275019bb reply and edit
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
7 local header = Shared.header or error()
9674275019bb reply and edit
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
8 local footer = Shared.footer or error()
9674275019bb reply and edit
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
9 local Forum = require "site:/lib/Forum.luan"
9674275019bb reply and edit
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
10 local forum_title = Forum.title or error()
9674275019bb reply and edit
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
11 local Post = require "site:/lib/Post.luan"
9674275019bb reply and edit
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
12 local User = require "site:/lib/User.luan"
9674275019bb reply and edit
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
13
9674275019bb reply and edit
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
14
9674275019bb reply and edit
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
15 return function()
9674275019bb reply and edit
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
16 local user = User.current_required()
9674275019bb reply and edit
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
17 if user==nil then return end
9674275019bb reply and edit
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
18 local parent_id = Http.request.parameters.parent or error()
9674275019bb reply and edit
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
19 local parent = Post.get_by_id(parent_id) or error()
9674275019bb reply and edit
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
20 if Http.request.method == "POST" then
9674275019bb reply and edit
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
21 local content = Http.request.parameters.content or error()
9674275019bb reply and edit
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
22 local post = parent.reply(user,content)
9674275019bb reply and edit
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
23 Http.response.send_redirect("/thread.html?root="..post.root_id)
9674275019bb reply and edit
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
24 return
9674275019bb reply and edit
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
25 end
9674275019bb reply and edit
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
26 Io.stdout = Http.response.text_writer()
9674275019bb reply and edit
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
27 %>
9674275019bb reply and edit
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
28 <!doctype html>
9674275019bb reply and edit
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
29 <html>
9674275019bb reply and edit
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
30 <head>
9674275019bb reply and edit
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
31 <% head() %>
9674275019bb reply and edit
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
32 <title><%=forum_title%>: reply</title>
9674275019bb reply and edit
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
33 </head>
9674275019bb reply and edit
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
34 <body>
9674275019bb reply and edit
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
35 <% header() %>
9674275019bb reply and edit
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
36 <div content>
9674275019bb reply and edit
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
37 <h1>reply to: <%=parent.root.subject_html%></h1>
9674275019bb reply and edit
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
38 <p>This page will almost certainly be replaced by ajax, but whatever. Hack for now.</p>
9674275019bb reply and edit
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
39 <form method=post>
9674275019bb reply and edit
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
40 <p><textarea name=content></textarea></p>
9674275019bb reply and edit
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
41 <p><input type=submit></p>
9674275019bb reply and edit
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
42 </form>
9674275019bb reply and edit
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
43 </div>
9674275019bb reply and edit
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
44 <% footer() %>
9674275019bb reply and edit
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
45 </body>
9674275019bb reply and edit
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
46 </html>
9674275019bb reply and edit
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
47 <%
9674275019bb reply and edit
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
48 end