annotate src/edit.js.luan @ 18:94e26bffd4fb

UI work
author Franklin Schmidt <fschmidt@gmail.com>
date Mon, 11 Jul 2022 12:14:05 -0600
parents 0edde02b908c
children da006d1c1eba
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
15
0edde02b908c edit in place
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1 local Luan = require "luan:Luan.luan"
0edde02b908c edit in place
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2 local error = Luan.error
0edde02b908c edit in place
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3 local Html = require "luan:Html.luan"
0edde02b908c edit in place
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4 local html_encode = Html.encode or error()
0edde02b908c edit in place
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
5 local Parsers = require "luan:Parsers.luan"
0edde02b908c edit in place
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
6 local json_string = Parsers.json_string or error()
0edde02b908c edit in place
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
7 local Io = require "luan:Io.luan"
0edde02b908c edit in place
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
8 local output_of = Io.output_of or error()
0edde02b908c edit in place
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
9 local Http = require "luan:http/Http.luan"
0edde02b908c edit in place
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
10 local Post = require "site:/lib/Post.luan"
0edde02b908c edit in place
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
11
0edde02b908c edit in place
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
12
0edde02b908c edit in place
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
13 local function form(post)
0edde02b908c edit in place
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
14 %>
0edde02b908c edit in place
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
15 <p><textarea name=content><%=html_encode(post.content)%></textarea></p>
0edde02b908c edit in place
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
16 <p>
0edde02b908c edit in place
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
17 <a href="javascript:saveEdit('<%= post.id %>')">save</a>
0edde02b908c edit in place
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
18 <a href="javascript:cancelEdit('<%= post.id %>')">cancel</a>
0edde02b908c edit in place
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
19 </p>
0edde02b908c edit in place
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
20 <%
0edde02b908c edit in place
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
21 end
0edde02b908c edit in place
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
22
0edde02b908c edit in place
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
23 return function()
0edde02b908c edit in place
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
24 local post = Http.request.parameters.post or error()
0edde02b908c edit in place
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
25 post = Post.get_by_id(post) or error()
0edde02b908c edit in place
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
26 local html = output_of(function() form(post) end)
0edde02b908c edit in place
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
27 Io.stdout = Http.response.text_writer()
0edde02b908c edit in place
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
28 %>
0edde02b908c edit in place
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
29 let postDiv = document.querySelector('[post="<%=post.id%>"]');
0edde02b908c edit in place
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
30 postDiv.querySelector('[output]').style.display = 'none';
0edde02b908c edit in place
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
31 postDiv.querySelector('[edit]').innerHTML = <%= json_string(html) %>;
18
94e26bffd4fb UI work
Franklin Schmidt <fschmidt@gmail.com>
parents: 15
diff changeset
32 postDiv.querySelector('textarea').focus();
15
0edde02b908c edit in place
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
33 <%
0edde02b908c edit in place
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
34 end