diff --git a/src/views/preferences.nim b/src/views/preferences.nim index 8a1fe5f..afe9092 100644 --- a/src/views/preferences.nim +++ b/src/views/preferences.nim @@ -1,6 +1,7 @@ import tables, macros, strformat, xmltree import karax/[karaxdsl, vdom, vstyles] +import renderutils import ../types, ../prefs_impl proc genCheckbox(pref, label: string; state: bool): VNode = @@ -55,14 +56,11 @@ proc renderPreferences*(prefs: Prefs; path: string): VNode = buildHtml(tdiv(class="preferences-container")): fieldset(class="preferences"): form(`method`="post", action="/saveprefs"): - verbatim "" % path + refererField path renderPrefs() button(`type`="submit", class="pref-submit"): text "Save preferences" - form(`method`="post", action="/resetprefs", class="pref-reset"): - verbatim "" % path - button(`type`="submit"): - text "Reset preferences" + buttonReferer "/resetprefs", "Reset Preferences", path, class="pref-reset" diff --git a/src/views/renderutils.nim b/src/views/renderutils.nim index 24a42a5..48978a0 100644 --- a/src/views/renderutils.nim +++ b/src/views/renderutils.nim @@ -39,8 +39,18 @@ proc linkText*(text: string; class=""): VNode = buildHtml(): a(href=url, class=class): text text +proc refererField*(path: string): VNode = + buildHtml(): + verbatim "" % path + proc iconReferer*(icon, action, path: string, title=""): VNode = buildHtml(form(`method`="get", action=action, class="icon-button")): - verbatim "" % path + refererField path button(`type`="submit"): icon icon, title=title + +proc buttonReferer*(action, text, path: string; class=""; `method`="post"): VNode = + buildHtml(form(`method`=`method`, action=action, class=class)): + refererField path + button(`type`="submit"): + text text diff --git a/src/views/tweet.nim b/src/views/tweet.nim index 47ee506..b3d5e1f 100644 --- a/src/views/tweet.nim +++ b/src/views/tweet.nim @@ -58,10 +58,7 @@ proc renderVideoDisabled(video: Video; path: string): VNode = of mp4: p: text "mp4 playback disabled in preferences" of m3u8, vmap: - form(`method`="post", action=("/enablehls")): - verbatim "" % path - button(`type`="submit"): - text "Enable hls playback" + buttonReferer "/enablehls", "Enable hls playback", path proc renderVideoUnavailable(video: Video): VNode = buildHtml(tdiv):