annotate src/private/admin/config.html.luan @ 2:fc2383eb48a9

set config
author Franklin Schmidt <fschmidt@gmail.com>
date Thu, 16 Jun 2022 20:52:24 -0600
parents
children a17e400ddaa1
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2
fc2383eb48a9 set config
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1 local Luan = require "luan:Luan.luan"
fc2383eb48a9 set config
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2 local error = Luan.error
fc2383eb48a9 set config
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3 local Html = require "luan:Html.luan"
fc2383eb48a9 set config
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4 local html_encode = Html.encode or error()
fc2383eb48a9 set config
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
5 local Parsers = require "luan:Parsers.luan"
fc2383eb48a9 set config
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
6 local json_string = Parsers.json_string or error()
fc2383eb48a9 set config
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
7 local Io = require "luan:Io.luan"
fc2383eb48a9 set config
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
8 local Http = require "luan:http/Http.luan"
fc2383eb48a9 set config
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
9 local reset_luan = Http.reset_luan or error()
fc2383eb48a9 set config
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
10 local test_as_init = Http.test_as_init or error()
fc2383eb48a9 set config
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
11 local Run = require "luan:http/tools/Run.luan"
fc2383eb48a9 set config
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
12 local Config = require "site:/lib/Config.luan"
fc2383eb48a9 set config
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
13 local Logging = require "luan:logging/Logging.luan"
fc2383eb48a9 set config
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
14 local logger = Logging.logger "admin/Config.html"
fc2383eb48a9 set config
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
15
fc2383eb48a9 set config
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
16
fc2383eb48a9 set config
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
17 return function()
fc2383eb48a9 set config
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
18 Io.stdout = Http.response.text_writer()
fc2383eb48a9 set config
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
19 if Http.request.method == "POST" then
fc2383eb48a9 set config
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
20 local config = Http.request.parameters.config or error()
fc2383eb48a9 set config
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
21 try
fc2383eb48a9 set config
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
22 test_as_init(config,"config")
fc2383eb48a9 set config
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
23 catch e
fc2383eb48a9 set config
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
24 Run.print_error(e,config)
fc2383eb48a9 set config
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
25 return
fc2383eb48a9 set config
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
26 end
fc2383eb48a9 set config
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
27 Config.set(config)
fc2383eb48a9 set config
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
28 reset_luan()
fc2383eb48a9 set config
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
29 %>Updated<%
fc2383eb48a9 set config
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
30 return
fc2383eb48a9 set config
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
31 end
fc2383eb48a9 set config
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
32 %>
fc2383eb48a9 set config
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
33 <!doctype html>
fc2383eb48a9 set config
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
34 <html>
fc2383eb48a9 set config
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
35 <head>
fc2383eb48a9 set config
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
36 <title>FreedIt - Configure Forum</title>
fc2383eb48a9 set config
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
37 <style>
fc2383eb48a9 set config
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
38 @import "/site.css";
fc2383eb48a9 set config
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
39
fc2383eb48a9 set config
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
40 textarea {
fc2383eb48a9 set config
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
41 width: 90%;
fc2383eb48a9 set config
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
42 height: 20em;
fc2383eb48a9 set config
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
43 }
fc2383eb48a9 set config
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
44 </style>
fc2383eb48a9 set config
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
45 <script>
fc2383eb48a9 set config
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
46 function restoreDefault() {
fc2383eb48a9 set config
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
47 document.querySelector('textarea').value = <%=json_string(Config.default_text,{compressed=true})%>;
fc2383eb48a9 set config
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
48 }
fc2383eb48a9 set config
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
49 </script>
fc2383eb48a9 set config
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
50 </head>
fc2383eb48a9 set config
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
51 <body>
fc2383eb48a9 set config
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
52 <h1>Configure Forum</h1>
fc2383eb48a9 set config
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
53
fc2383eb48a9 set config
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
54 <form method=post>
fc2383eb48a9 set config
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
55 <p>
fc2383eb48a9 set config
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
56 Configuration in <a href="http://www.luan.software/">Luan</a>
fc2383eb48a9 set config
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
57 - <a href="javascript:restoreDefault()">restore default</a>
fc2383eb48a9 set config
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
58 </p>
fc2383eb48a9 set config
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
59 <p><textarea name=config autofocus><%= html_encode(Config.text) %></textarea></p>
fc2383eb48a9 set config
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
60 <p><input type=submit><p>
fc2383eb48a9 set config
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
61 </form>
fc2383eb48a9 set config
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
62 </body>
fc2383eb48a9 set config
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
63 </html>
fc2383eb48a9 set config
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
64 <%
fc2383eb48a9 set config
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
65 end