2021-12-27 10:37:38 +09:00
|
|
|
# SPDX-License-Identifier: AGPL-3.0-only
|
2020-06-22 10:50:16 +09:00
|
|
|
import tables, macros, strutils
|
|
|
|
import karax/[karaxdsl, vdom]
|
2019-08-14 02:44:29 +09:00
|
|
|
|
2019-09-06 05:53:23 +09:00
|
|
|
import renderutils
|
2019-08-18 04:49:41 +09:00
|
|
|
import ../types, ../prefs_impl
|
2019-08-14 02:44:29 +09: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 21:38:14 +09: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-14 02:44:29 +09:00
|
|
|
case pref.kind
|
2019-08-15 21:38:14 +09:00
|
|
|
of checkbox: discard
|
|
|
|
of input: stmt[0].add newLit(pref.placeholder)
|
2019-10-23 18:48:08 +09:00
|
|
|
of select:
|
|
|
|
if pref.name == "theme":
|
|
|
|
stmt[0].add ident("themes")
|
|
|
|
else:
|
|
|
|
stmt[0].add newLit(pref.options)
|
2019-08-15 21:38:14 +09:00
|
|
|
|
|
|
|
result[2].add stmt
|
2019-08-14 02:44:29 +09:00
|
|
|
|
2019-10-23 18:48:08 +09:00
|
|
|
proc renderPreferences*(prefs: Prefs; path: string; themes: seq[string]): VNode =
|
2019-09-13 17:44:21 +09:00
|
|
|
buildHtml(tdiv(class="overlay-panel")):
|
2019-08-16 02:13:54 +09:00
|
|
|
fieldset(class="preferences"):
|
2022-01-31 01:17:59 +09:00
|
|
|
form(`method`="post", action="/saveprefs", autocomplete="off"):
|
2019-09-06 05:53:23 +09:00
|
|
|
refererField path
|
2019-08-19 11:37:28 +09:00
|
|
|
|
2019-08-14 02:44:29 +09:00
|
|
|
renderPrefs()
|
|
|
|
|
2021-12-28 02:05:09 +09:00
|
|
|
h4(class="note"):
|
2023-05-26 16:02:25 +09:00
|
|
|
text "設定は個人情報無しのクッキーとしてクライエントサイドで保存されます。"
|
2020-06-10 00:01:30 +09:00
|
|
|
|
2019-08-16 08:57:36 +09:00
|
|
|
button(`type`="submit", class="pref-submit"):
|
2021-12-28 10:55:07 +09:00
|
|
|
text "保存"
|
2019-08-16 02:13:54 +09:00
|
|
|
|
2021-12-28 10:55:07 +09:00
|
|
|
buttonReferer "/resetprefs", "やり直す", path, class="pref-reset"
|