view src/edit.html.luan @ 10:de0cbf515ef5

remove author_id
author Franklin Schmidt <fschmidt@gmail.com>
date Thu, 30 Jun 2022 11:11:00 -0600
parents 9674275019bb
children 24668255cede
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 Io = require "luan:Io.luan"
local Http = require "luan:http/Http.luan"
local Shared = require "site:/lib/Shared.luan"
local head = Shared.head or error()
local header = Shared.header or error()
local footer = Shared.footer or error()
local Forum = require "site:/lib/Forum.luan"
local forum_title = Forum.title or error()
local Post = require "site:/lib/Post.luan"
local User = require "site:/lib/User.luan"


return function()
	local user = User.current_required()
	if user==nil then return end
	local post_id = Http.request.parameters.post or error()
	local post = Post.get_by_id(post_id) or error()
	if Http.request.method == "POST" then
		post.content = Http.request.parameters.content or error()
		post.save()
		Http.response.send_redirect("/thread.html?root="..post.root_id)
		return
	end
	Io.stdout = Http.response.text_writer()
%>
<!doctype html>
<html>
	<head>
<%		head() %>
		<title><%=forum_title%>: edit</title>
	</head>
	<body>
<%		header() %>
		<div content>
			<h1>edit: <%=post.root.subject_html%></h1>
			<p>This page will almost certainly be replaced by ajax, but whatever.  Hack for now.</p>
			<form method=post>
				<p><textarea name=content><%=html_encode(post.content)%></textarea></p>
				<p><input type=submit></p>
			</form>
		</div>
<%		footer() %>
	</body>
</html>
<%
end