comparison src/edit_link.js.luan @ 0:8f4df159f06b

start public repo
author Franklin Schmidt <fschmidt@gmail.com>
date Fri, 11 Jul 2025 20:57:49 -0600
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:8f4df159f06b
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 Http = require "luan:http/Http.luan"
9 local Link = require "site:/lib/Link.luan"
10
11
12 return function()
13 local link_id = Http.request.parameters.link or error()
14 local link = Link.get_by_id(link_id)
15 Io.stdout = Http.response.text_writer()
16 if link == nil then
17 %>
18 let div = document.querySelector('div[link="<%=link_id%>"]');
19 if(div) div.outerHTML = '';
20 <%
21 return
22 end
23 local html = `%>
24 <form onsubmit="ajaxForm('/save_link.js',this)" action="javascript:">
25 <input type=hidden name=link value="<%=link_id%>">
26 <label>Title</label>
27 <input type=text required name=title value="<%=html_encode(link.title)%>">
28 <label>URL</label>
29 <input type=url required name=url value="<%=html_encode(link.url)%>">
30 <button small type=submit>Save</button>
31 <button small type=button onclick="cancel('<%=link.id%>')">Cancel</button>
32 </form>
33 <%`
34 %>
35 document.querySelector('div[link="<%=link_id%>"]').innerHTML = <%= json_string(html) %>;
36 <%
37 end