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