summaryrefslogtreecommitdiff
path: root/elm/Lib
diff options
context:
space:
mode:
authorYorhel <git@yorhel.nl>2019-10-02 14:21:12 +0200
committerYorhel <git@yorhel.nl>2019-10-02 14:21:15 +0200
commit7d8274f0332b1c92825988c6393037bf7eb12af3 (patch)
treecdcc33c92f764b3199fffeef990d71e6085dff06 /elm/Lib
parent1a9a4b4bdb8f3b6d7d0ad12032c17c44a8287a09 (diff)
v2rw: Convert user preferences form
And add a small 'formField' function to shrink the Elm form generation code a bit.
Diffstat (limited to 'elm/Lib')
-rw-r--r--elm/Lib/Api.elm1
-rw-r--r--elm/Lib/Html.elm27
2 files changed, 28 insertions, 0 deletions
diff --git a/elm/Lib/Api.elm b/elm/Lib/Api.elm
index 06072599..4df99fde 100644
--- a/elm/Lib/Api.elm
+++ b/elm/Lib/Api.elm
@@ -40,6 +40,7 @@ showResponse res =
Taken -> "Username already taken, please choose a different name."
DoubleEmail -> "Email address already used for another account."
DoubleIP -> "You can only register one account from the same IP within 24 hours."
+ BadCurPass -> "Current password is invalid."
expectResponse : (Response -> msg) -> Http.Expect msg
diff --git a/elm/Lib/Html.elm b/elm/Lib/Html.elm
index 41f6e376..fd5ebf5d 100644
--- a/elm/Lib/Html.elm
+++ b/elm/Lib/Html.elm
@@ -13,6 +13,10 @@ onClickN : m -> Attribute m
onClickN action = custom "click" (JD.succeed { message = action, stopPropagation = True, preventDefault = True})
+-- Multi-<br> (ugly but oh, so, convenient)
+br_ : Int -> Html m
+br_ n = if n == 1 then br [] [] else span [] <| List.repeat n <| br [] []
+
-- Submit button with loading indicator and error message display
submitButton : String -> Api.State -> Bool -> Bool -> Html m
submitButton val state valid load = div []
@@ -85,3 +89,26 @@ inputCheck nam val onch = input (
]
++ (if nam == "" then [] else [ id nam, name nam ])
) []
+
+
+-- Generate a form field (table row) with a label. The `label` string can be:
+--
+-- "none" -> To generate a full-width field (colspan=2)
+-- "" -> Empty label
+-- "Some string" -> Text label
+-- "input::String" -> Label that refers to the named input
+--
+-- (Yeah, stringly typed arguments; I wish Elm had typeclasses)
+formField : String -> List (Html m) -> Html m
+formField lbl cont =
+ tr [ class "newfield" ]
+ [ if lbl == "none"
+ then text ""
+ else
+ td [ class "label" ]
+ [ case String.split "::" lbl of
+ [name, txt] -> label [ for name ] [ text txt ]
+ txt -> text <| String.concat txt
+ ]
+ , td (class "field" :: if lbl == "none" then [ colspan 2 ] else []) cont
+ ]