2019-10-23 09:48:08 +00:00
|
|
|
import tables, macros, strutils, os
|
2019-08-13 17:44:29 +00:00
|
|
|
import karax/[karaxdsl, vdom, vstyles]
|
|
|
|
|
2019-09-05 20:53:23 +00:00
|
|
|
import renderutils
|
2019-08-17 19:49:41 +00:00
|
|
|
import ../types, ../prefs_impl
|
2019-08-13 17:44:29 +00: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 12:38:14 +00: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 17:44:29 +00:00
|
|
|
case pref.kind
|
2019-08-15 12:38:14 +00:00
|
|
|
of checkbox: discard
|
|
|
|
of input: stmt[0].add newLit(pref.placeholder)
|
2019-10-23 09:48:08 +00:00
|
|
|
of select:
|
|
|
|
if pref.name == "theme":
|
|
|
|
stmt[0].add ident("themes")
|
|
|
|
else:
|
|
|
|
stmt[0].add newLit(pref.options)
|
2019-08-15 12:38:14 +00:00
|
|
|
|
|
|
|
result[2].add stmt
|
2019-08-13 17:44:29 +00:00
|
|
|
|
2019-10-23 09:48:08 +00:00
|
|
|
proc renderPreferences*(prefs: Prefs; path: string; themes: seq[string]): VNode =
|
2019-09-13 08:44:21 +00:00
|
|
|
buildHtml(tdiv(class="overlay-panel")):
|
2019-08-15 17:13:54 +00:00
|
|
|
fieldset(class="preferences"):
|
2019-08-22 21:44:22 +00:00
|
|
|
form(`method`="post", action="/saveprefs"):
|
2019-09-05 20:53:23 +00:00
|
|
|
refererField path
|
2019-08-19 02:37:28 +00:00
|
|
|
|
2019-08-13 17:44:29 +00:00
|
|
|
renderPrefs()
|
|
|
|
|
2019-08-15 23:57:36 +00:00
|
|
|
button(`type`="submit", class="pref-submit"):
|
2019-08-13 17:44:29 +00:00
|
|
|
text "Save preferences"
|
2019-08-15 17:13:54 +00:00
|
|
|
|
2019-09-05 20:53:23 +00:00
|
|
|
buttonReferer "/resetprefs", "Reset Preferences", path, class="pref-reset"
|