comparison src/edit.js.luan @ 15:0edde02b908c

edit in place
author Franklin Schmidt <fschmidt@gmail.com>
date Tue, 05 Jul 2022 23:27:54 -0600
parents
children 94e26bffd4fb
comparison
equal deleted inserted replaced
14:7d0c96408abf 15:0edde02b908c
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 output_of = Io.output_of or error()
9 local Http = require "luan:http/Http.luan"
10 local Post = require "site:/lib/Post.luan"
11
12
13 local function form(post)
14 %>
15 <p><textarea name=content><%=html_encode(post.content)%></textarea></p>
16 <p>
17 <a href="javascript:saveEdit('<%= post.id %>')">save</a>
18 <a href="javascript:cancelEdit('<%= post.id %>')">cancel</a>
19 </p>
20 <%
21 end
22
23 return function()
24 local post = Http.request.parameters.post or error()
25 post = Post.get_by_id(post) or error()
26 local html = output_of(function() form(post) end)
27 Io.stdout = Http.response.text_writer()
28 %>
29 let postDiv = document.querySelector('[post="<%=post.id%>"]');
30 postDiv.querySelector('[output]').style.display = 'none';
31 postDiv.querySelector('[edit]').innerHTML = <%= json_string(html) %>;
32 <%
33 end