comparison src/save_edit.js.luan @ 42:0c1b820fff34

use push
author Franklin Schmidt <fschmidt@gmail.com>
date Tue, 08 Nov 2022 14:02:28 -0700
parents 66fd3784e60e
children 96f0c3d65698
comparison
equal deleted inserted replaced
41:acb730710328 42:0c1b820fff34
7 local Http = require "luan:http/Http.luan" 7 local Http = require "luan:http/Http.luan"
8 local Post = require "site:/lib/Post.luan" 8 local Post = require "site:/lib/Post.luan"
9 local Bbcode = require "site:/lib/Bbcode.luan" 9 local Bbcode = require "site:/lib/Bbcode.luan"
10 local bbcode_to_html = Bbcode.to_html or error() 10 local bbcode_to_html = Bbcode.to_html or error()
11 local Db = require "site:/lib/Db.luan" 11 local Db = require "site:/lib/Db.luan"
12 local Shared = require "site:/lib/Shared.luan"
13 local base_url = Shared.base_url or error()
14 local Logging = require "luan:logging/Logging.luan"
15 local logger = Logging.logger "save_edit.js"
12 16
13 17
14 return function() 18 return function()
15 local post = Http.request.parameters.post or error() 19 local post = Http.request.parameters.post or error()
16 local text = Http.request.parameters.text or error() 20 local text = Http.request.parameters.text or error()
19 post.author_is_current() or error() 23 post.author_is_current() or error()
20 post.content = text 24 post.content = text
21 post.save() 25 post.save()
22 end ) 26 end )
23 local html = output_of(function() bbcode_to_html(post.content) end) 27 local html = output_of(function() bbcode_to_html(post.content) end)
24 Io.stdout = Http.response.text_writer() 28 local js = output_of(function()
25 %> 29 %>
26 let postDiv = document.querySelector('[post="<%=post.id%>"]'); 30 updated( '<%=post.id%>', <%= json_string(html) %> );
27 cancelEdit(postDiv);
28 postDiv.querySelector('[message]').innerHTML = <%= json_string(html) %>;
29 <% 31 <%
32 end)
33 local url = base_url().."/thread.html?root="..post.root_id
34 Http.push(url,js)
30 end 35 end