Mercurial Hosting > linkmystyle
view src/edit_icons.js.luan @ 2:e32e4120dc70
minor
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Fri, 11 Jul 2025 21:23:39 -0600 |
parents | 8f4df159f06b |
children |
line wrap: on
line source
local Luan = require "luan:Luan.luan" local error = Luan.error local pairs = Luan.pairs or error() local String = require "luan:String.luan" local starts_with = String.starts_with or error() local substring = String.sub or error() local Html = require "luan:Html.luan" local html_encode = Html.encode or error() local Parsers = require "luan:Parsers.luan" local json_string = Parsers.json_string or error() local Io = require "luan:Io.luan" local Http = require "luan:http/Http.luan" local Icon = require "site:/lib/Icon.luan" local icon_names = Icon.icon_names or error() local icon_from_doc = Icon.from_doc or error() local User = require "site:/lib/User.luan" local Db = require "site:/lib/Db.luan" return function() local user = User.current() or error() local user_id = user.id local html = `%> <form onsubmit="ajaxForm('/save_icons.js',this)" action="javascript:"> <% for name, info in pairs(icon_names) do local doc = Db.get_document("+icon_user_id:"..user_id.." +icon_name:"..name) local url = doc and icon_from_doc(doc).url or "" local type = info.type or "url" local label = type=="url" and "URL" or "" if type=="email" and starts_with(url,"mailto:") then url = substring(url,8) end %> <label><%=info.title%> <%=label%></label> <div field> <input type="<%=type%>" name="<%=name%>" value="<%=html_encode(url)%>" placeholder="<%= info.placeholder or "" %>"> </div> <% end %> <button small type=submit>Save</button> <button small type=button onclick="ajax('/cancel_edit_icons.js')">Cancel</button> </form> <%` Io.stdout = Http.response.text_writer() %> document.querySelector('div[icons]').innerHTML = <%= json_string(html) %>; <% end