8
|
1 local Luan = require "luan:Luan.luan"
|
|
2 local error = Luan.error
|
|
3 local Io = require "luan:Io.luan"
|
|
4 local Http = require "luan:http/Http.luan"
|
|
5 local Shared = require "site:/lib/Shared.luan"
|
|
6 local head = Shared.head or error()
|
|
7 local header = Shared.header or error()
|
|
8 local footer = Shared.footer or error()
|
|
9 local Forum = require "site:/lib/Forum.luan"
|
|
10 local forum_title = Forum.title or error()
|
|
11 local Post = require "site:/lib/Post.luan"
|
|
12 local User = require "site:/lib/User.luan"
|
|
13
|
|
14
|
|
15 return function()
|
|
16 local user = User.current_required()
|
|
17 if user==nil then return end
|
|
18 if Http.request.method == "POST" then
|
|
19 local subject = Http.request.parameters.subject or error()
|
|
20 local content = Http.request.parameters.content or error()
|
|
21 local post = Post.new_thread(user,subject,content)
|
|
22 Http.response.send_redirect("/thread.html?root="..post.id)
|
|
23 return
|
|
24 end
|
|
25 Io.stdout = Http.response.text_writer()
|
|
26 %>
|
|
27 <!doctype html>
|
|
28 <html>
|
|
29 <head>
|
|
30 <% head() %>
|
9
|
31 <title><%=forum_title%>: new thread</title>
|
42
|
32 <style>
|
|
33 textarea {
|
|
34 width: 100%;
|
|
35 }
|
|
36 </style>
|
|
37 <script>
|
|
38 function uploaded(input,url,filename) {
|
|
39 let textarea = document.querySelector('textarea');
|
|
40 textarea.focus();
|
|
41 textarea.setRangeText(url,textarea.selectionStart,textarea.selectionEnd,'select');
|
|
42 }
|
|
43 </script>
|
8
|
44 </head>
|
|
45 <body>
|
|
46 <% header() %>
|
|
47 <div content>
|
|
48 <h1>New Thread</h1>
|
|
49 <form method=post>
|
|
50 <p>
|
|
51 <label>Subject</label>
|
|
52 <input name=subject required>
|
|
53 </p>
|
42
|
54 <p><textarea name=content oninput="fixTextarea(this)"></textarea></p>
|
|
55 <p>
|
|
56 <input type=file onchange="upload(this,uploaded)">
|
|
57 <button type=button onclick="fileButtonClick(this)">Upload File</button>
|
|
58 </p>
|
8
|
59 <p><input type=submit></p>
|
|
60 </form>
|
|
61 </div>
|
|
62 <% footer() %>
|
|
63 </body>
|
|
64 </html>
|
|
65 <%
|
|
66 end
|