0
|
1 local Luan = require "luan:Luan.luan"
|
|
2 local error = Luan.error
|
|
3 local pairs = Luan.pairs or error()
|
|
4 local String = require "luan:String.luan"
|
|
5 local starts_with = String.starts_with or error()
|
|
6 local substring = String.sub or error()
|
|
7 local Html = require "luan:Html.luan"
|
|
8 local html_encode = Html.encode or error()
|
|
9 local Parsers = require "luan:Parsers.luan"
|
|
10 local json_string = Parsers.json_string or error()
|
|
11 local Io = require "luan:Io.luan"
|
|
12 local Http = require "luan:http/Http.luan"
|
|
13 local Icon = require "site:/lib/Icon.luan"
|
|
14 local icon_names = Icon.icon_names or error()
|
|
15 local icon_from_doc = Icon.from_doc or error()
|
|
16 local User = require "site:/lib/User.luan"
|
|
17 local Db = require "site:/lib/Db.luan"
|
|
18
|
|
19
|
|
20 return function()
|
|
21 local user = User.current() or error()
|
|
22 local user_id = user.id
|
|
23 local html = `%>
|
|
24 <form onsubmit="ajaxForm('/save_icons.js',this)" action="javascript:">
|
|
25 <%
|
|
26 for name, info in pairs(icon_names) do
|
|
27 local doc = Db.get_document("+icon_user_id:"..user_id.." +icon_name:"..name)
|
|
28 local url = doc and icon_from_doc(doc).url or ""
|
|
29 local type = info.type or "url"
|
|
30 local label = type=="url" and "URL" or ""
|
|
31 if type=="email" and starts_with(url,"mailto:") then
|
|
32 url = substring(url,8)
|
|
33 end
|
|
34 %>
|
|
35 <label><%=info.title%> <%=label%></label>
|
|
36 <div field>
|
|
37 <input type="<%=type%>" name="<%=name%>" value="<%=html_encode(url)%>" placeholder="<%= info.placeholder or "" %>">
|
|
38 </div>
|
|
39 <%
|
|
40 end
|
|
41 %>
|
|
42 <button small type=submit>Save</button>
|
|
43 <button small type=button onclick="ajax('/cancel_edit_icons.js')">Cancel</button>
|
|
44 </form>
|
|
45 <%`
|
|
46 Io.stdout = Http.response.text_writer()
|
|
47 %>
|
|
48 document.querySelector('div[icons]').innerHTML = <%= json_string(html) %>;
|
|
49 <%
|
|
50 end
|