annotate src/save_edit.js.luan @ 24:fccbe5554fcc

tinymce work
author Franklin Schmidt <fschmidt@gmail.com>
date Tue, 19 Jul 2022 22:07:02 -0600
parents 33731231093a
children 66fd3784e60e
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 Parsers = require "luan:Parsers.luan"
0edde02b908c edit in place
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4 local json_string = Parsers.json_string or error()
0edde02b908c edit in place
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
5 local Io = require "luan:Io.luan"
0edde02b908c edit in place
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
6 local output_of = Io.output_of or error()
0edde02b908c edit in place
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
7 local Http = require "luan:http/Http.luan"
0edde02b908c edit in place
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
8 local Post = require "site:/lib/Post.luan"
0edde02b908c edit in place
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
9 local Bbcode = require "site:/lib/Bbcode.luan"
21
33731231093a fix bbcode editing
Franklin Schmidt <fschmidt@gmail.com>
parents: 19
diff changeset
10 local remove_html = Bbcode.remove_html or error()
15
0edde02b908c edit in place
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
11 local bbcode_to_html = Bbcode.to_html or error()
0edde02b908c edit in place
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
12 local Db = require "site:/lib/Db.luan"
0edde02b908c edit in place
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
13
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 return function()
0edde02b908c edit in place
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
16 local post = Http.request.parameters.post or error()
0edde02b908c edit in place
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
17 local text = Http.request.parameters.text or error()
21
33731231093a fix bbcode editing
Franklin Schmidt <fschmidt@gmail.com>
parents: 19
diff changeset
18 text = remove_html(text)
15
0edde02b908c edit in place
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
19 Db.run_in_transaction( function()
0edde02b908c edit in place
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
20 post = Post.get_by_id(post) or error()
16
bff178656073 delete function
Franklin Schmidt <fschmidt@gmail.com>
parents: 15
diff changeset
21 post.author_is_current() or error()
15
0edde02b908c edit in place
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
22 post.content = text
0edde02b908c edit in place
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
23 post.save()
0edde02b908c edit in place
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
24 end )
0edde02b908c edit in place
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
25 local html = output_of(function() bbcode_to_html(post.content) end)
0edde02b908c edit in place
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
26 Io.stdout = Http.response.text_writer()
0edde02b908c edit in place
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
27 %>
0edde02b908c edit in place
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
28 let postDiv = document.querySelector('[post="<%=post.id%>"]');
19
da006d1c1eba use contentEditable
Franklin Schmidt <fschmidt@gmail.com>
parents: 16
diff changeset
29 cancelEdit(postDiv);
15
0edde02b908c edit in place
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
30 postDiv.querySelector('[message]').innerHTML = <%= json_string(html) %>;
0edde02b908c edit in place
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
31 <%
0edde02b908c edit in place
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
32 end