annotate src/edit.html.luan @ 10:de0cbf515ef5

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