view src/private/admin/config.html.luan @ 13:24668255cede

preprocess urls
author Franklin Schmidt <fschmidt@gmail.com>
date Sun, 03 Jul 2022 23:59:41 -0600
parents a17e400ddaa1
children
line wrap: on
line source

local Luan = require "luan:Luan.luan"
local error = Luan.error
local Html = require "luan:Html.luan"
local html_encode = Html.encode or error()
local Parsers = require "luan:Parsers.luan"
local json_string = Parsers.json_string or error()
local Io = require "luan:Io.luan"
local Http = require "luan:http/Http.luan"
local reset_luan = Http.reset_luan or error()
local test_as_init = Http.test_as_init or error()
local Run = require "luan:http/tools/Run.luan"
local Config = require "site:/lib/Config.luan"
local Shared = require "site:/lib/Shared.luan"
local head = Shared.head or error()
local header = Shared.admin_header or error()
local Logging = require "luan:logging/Logging.luan"
local logger = Logging.logger "admin/config.html"


return function()
	Io.stdout = Http.response.text_writer()
	local updated = false
	if Http.request.method == "POST" then
		local config = Http.request.parameters.config or error()
		try
			test_as_init(config,"config")
		catch e
			Run.print_error(e,config)
			return
		end
		Config.set(config)
		reset_luan()
		updated = true
	end
%>
<!doctype html>
<html>
	<head>
<%		head() %>
		<title>FreedIt - Configure Forum</title>
		<style>
			textarea {
				width: 90%;
				height: 20em;
			}
		</style>
		<script>
			function restoreDefault() {
				document.querySelector('textarea').value = <%=json_string(Config.default_text,{compressed=true})%>;
			}
		</script>
	</head>
	<body>
<%		header() %>
		<div content>
			<h1>Configure Forum</h1>
<%	if updated then %>
			<p>Updated</p>
<%	else %>
			<form method=post>
				<p>
					Configuration in <a href="http://www.luan.software/">Luan</a>
					- <a href="javascript:restoreDefault()">restore default</a>
				</p>
				<p><textarea name=config autofocus><%= html_encode(Config.text) %></textarea></p>
				<p><input type=submit><p>
			</form>
<%	end %>
		</div>
	</body>
</html>
<%
end