diff src/edit_icons.js.luan @ 0:8f4df159f06b

start public repo
author Franklin Schmidt <fschmidt@gmail.com>
date Fri, 11 Jul 2025 20:57:49 -0600
parents
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/edit_icons.js.luan	Fri Jul 11 20:57:49 2025 -0600
@@ -0,0 +1,50 @@
+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