2021-12-27 02:37:38 +01:00
|
|
|
# SPDX-License-Identifier: AGPL-3.0-only
|
2020-06-22 03:50:16 +02:00
|
|
|
import tables, macros, strutils
|
|
|
|
import karax/[karaxdsl, vdom]
|
2019-08-13 19:44:29 +02:00
|
|
|
|
2019-09-05 22:53:23 +02:00
|
|
|
import renderutils
|
2019-08-17 21:49:41 +02:00
|
|
|
import ../types, ../prefs_impl
|
2019-08-13 19:44:29 +02:00
|
|
|
|
|
|
|
macro renderPrefs*(): untyped =
|
|
|
|
result = nnkCall.newTree(
|
|
|
|
ident("buildHtml"), ident("tdiv"), nnkStmtList.newTree())
|
|
|
|
|
|
|
|
for header, options in prefList:
|
|
|
|
result[2].add nnkCall.newTree(
|
|
|
|
ident("legend"),
|
|
|
|
nnkStmtList.newTree(
|
|
|
|
nnkCommand.newTree(ident("text"), newLit(header))))
|
|
|
|
|
|
|
|
for pref in options:
|
2019-08-15 14:38:14 +02:00
|
|
|
let procName = ident("gen" & capitalizeAscii($pref.kind))
|
|
|
|
let state = nnkDotExpr.newTree(ident("prefs"), ident(pref.name))
|
|
|
|
var stmt = nnkStmtList.newTree(
|
|
|
|
nnkCall.newTree(procName, newLit(pref.name), newLit(pref.label), state))
|
|
|
|
|
2019-08-13 19:44:29 +02:00
|
|
|
case pref.kind
|
2019-08-15 14:38:14 +02:00
|
|
|
of checkbox: discard
|
|
|
|
of input: stmt[0].add newLit(pref.placeholder)
|
2019-10-23 11:48:08 +02:00
|
|
|
of select:
|
|
|
|
if pref.name == "theme":
|
|
|
|
stmt[0].add ident("themes")
|
|
|
|
else:
|
|
|
|
stmt[0].add newLit(pref.options)
|
2019-08-15 14:38:14 +02:00
|
|
|
|
|
|
|
result[2].add stmt
|
2019-08-13 19:44:29 +02:00
|
|
|
|
2019-10-23 11:48:08 +02:00
|
|
|
proc renderPreferences*(prefs: Prefs; path: string; themes: seq[string]): VNode =
|
2019-09-13 10:44:21 +02:00
|
|
|
buildHtml(tdiv(class="overlay-panel")):
|
2019-08-15 19:13:54 +02:00
|
|
|
fieldset(class="preferences"):
|
2019-08-22 23:44:22 +02:00
|
|
|
form(`method`="post", action="/saveprefs"):
|
2019-09-05 22:53:23 +02:00
|
|
|
refererField path
|
2019-08-19 04:37:28 +02:00
|
|
|
|
2019-08-13 19:44:29 +02:00
|
|
|
renderPrefs()
|
|
|
|
|
2020-06-09 17:01:30 +02:00
|
|
|
h4(class="cookie-note"):
|
|
|
|
text "Preferences are stored client-side using cookies without any personal information."
|
|
|
|
|
2019-08-16 01:57:36 +02:00
|
|
|
button(`type`="submit", class="pref-submit"):
|
2019-08-13 19:44:29 +02:00
|
|
|
text "Save preferences"
|
2019-08-15 19:13:54 +02:00
|
|
|
|
2019-09-05 22:53:23 +02:00
|
|
|
buttonReferer "/resetprefs", "Reset Preferences", path, class="pref-reset"
|