annotate src/new_thread.html.luan @ 42:0c1b820fff34

use push
author Franklin Schmidt <fschmidt@gmail.com>
date Tue, 08 Nov 2022 14:02:28 -0700
parents 9674275019bb
children 289718f121e4
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
8
be36282b556a add new_thread
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1 local Luan = require "luan:Luan.luan"
be36282b556a add new_thread
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2 local error = Luan.error
be36282b556a add new_thread
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3 local Io = require "luan:Io.luan"
be36282b556a add new_thread
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4 local Http = require "luan:http/Http.luan"
be36282b556a add new_thread
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
5 local Shared = require "site:/lib/Shared.luan"
be36282b556a add new_thread
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
6 local head = Shared.head or error()
be36282b556a add new_thread
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
7 local header = Shared.header or error()
be36282b556a add new_thread
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
8 local footer = Shared.footer or error()
be36282b556a add new_thread
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
9 local Forum = require "site:/lib/Forum.luan"
be36282b556a add new_thread
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
10 local forum_title = Forum.title or error()
be36282b556a add new_thread
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
11 local Post = require "site:/lib/Post.luan"
be36282b556a add new_thread
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
12 local User = require "site:/lib/User.luan"
be36282b556a add new_thread
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
13
be36282b556a add new_thread
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
14
be36282b556a add new_thread
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
15 return function()
be36282b556a add new_thread
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
16 local user = User.current_required()
be36282b556a add new_thread
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
17 if user==nil then return end
be36282b556a add new_thread
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
18 if Http.request.method == "POST" then
be36282b556a add new_thread
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
19 local subject = Http.request.parameters.subject or error()
be36282b556a add new_thread
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
20 local content = Http.request.parameters.content or error()
be36282b556a add new_thread
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
21 local post = Post.new_thread(user,subject,content)
be36282b556a add new_thread
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
22 Http.response.send_redirect("/thread.html?root="..post.id)
be36282b556a add new_thread
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
23 return
be36282b556a add new_thread
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
24 end
be36282b556a add new_thread
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
25 Io.stdout = Http.response.text_writer()
be36282b556a add new_thread
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
26 %>
be36282b556a add new_thread
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
27 <!doctype html>
be36282b556a add new_thread
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
28 <html>
be36282b556a add new_thread
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
29 <head>
be36282b556a add new_thread
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
30 <% head() %>
9
9674275019bb reply and edit
Franklin Schmidt <fschmidt@gmail.com>
parents: 8
diff changeset
31 <title><%=forum_title%>: new thread</title>
42
0c1b820fff34 use push
Franklin Schmidt <fschmidt@gmail.com>
parents: 9
diff changeset
32 <style>
0c1b820fff34 use push
Franklin Schmidt <fschmidt@gmail.com>
parents: 9
diff changeset
33 textarea {
0c1b820fff34 use push
Franklin Schmidt <fschmidt@gmail.com>
parents: 9
diff changeset
34 width: 100%;
0c1b820fff34 use push
Franklin Schmidt <fschmidt@gmail.com>
parents: 9
diff changeset
35 }
0c1b820fff34 use push
Franklin Schmidt <fschmidt@gmail.com>
parents: 9
diff changeset
36 </style>
0c1b820fff34 use push
Franklin Schmidt <fschmidt@gmail.com>
parents: 9
diff changeset
37 <script>
0c1b820fff34 use push
Franklin Schmidt <fschmidt@gmail.com>
parents: 9
diff changeset
38 function uploaded(input,url,filename) {
0c1b820fff34 use push
Franklin Schmidt <fschmidt@gmail.com>
parents: 9
diff changeset
39 let textarea = document.querySelector('textarea');
0c1b820fff34 use push
Franklin Schmidt <fschmidt@gmail.com>
parents: 9
diff changeset
40 textarea.focus();
0c1b820fff34 use push
Franklin Schmidt <fschmidt@gmail.com>
parents: 9
diff changeset
41 textarea.setRangeText(url,textarea.selectionStart,textarea.selectionEnd,'select');
0c1b820fff34 use push
Franklin Schmidt <fschmidt@gmail.com>
parents: 9
diff changeset
42 }
0c1b820fff34 use push
Franklin Schmidt <fschmidt@gmail.com>
parents: 9
diff changeset
43 </script>
8
be36282b556a add new_thread
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
44 </head>
be36282b556a add new_thread
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
45 <body>
be36282b556a add new_thread
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
46 <% header() %>
be36282b556a add new_thread
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
47 <div content>
be36282b556a add new_thread
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
48 <h1>New Thread</h1>
be36282b556a add new_thread
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
49 <form method=post>
be36282b556a add new_thread
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
50 <p>
be36282b556a add new_thread
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
51 <label>Subject</label>
be36282b556a add new_thread
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
52 <input name=subject required>
be36282b556a add new_thread
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
53 </p>
42
0c1b820fff34 use push
Franklin Schmidt <fschmidt@gmail.com>
parents: 9
diff changeset
54 <p><textarea name=content oninput="fixTextarea(this)"></textarea></p>
0c1b820fff34 use push
Franklin Schmidt <fschmidt@gmail.com>
parents: 9
diff changeset
55 <p>
0c1b820fff34 use push
Franklin Schmidt <fschmidt@gmail.com>
parents: 9
diff changeset
56 <input type=file onchange="upload(this,uploaded)">
0c1b820fff34 use push
Franklin Schmidt <fschmidt@gmail.com>
parents: 9
diff changeset
57 <button type=button onclick="fileButtonClick(this)">Upload File</button>
0c1b820fff34 use push
Franklin Schmidt <fschmidt@gmail.com>
parents: 9
diff changeset
58 </p>
8
be36282b556a add new_thread
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
59 <p><input type=submit></p>
be36282b556a add new_thread
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
60 </form>
be36282b556a add new_thread
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
61 </div>
be36282b556a add new_thread
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
62 <% footer() %>
be36282b556a add new_thread
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
63 </body>
be36282b556a add new_thread
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
64 </html>
be36282b556a add new_thread
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
65 <%
be36282b556a add new_thread
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
66 end