summaryrefslogtreecommitdiff
path: root/elm/Lib/Html.elm
diff options
context:
space:
mode:
authorYorhel <git@yorhel.nl>2019-10-16 10:31:24 +0200
committerYorhel <git@yorhel.nl>2019-10-16 15:29:38 +0200
commit678f511619708ba893cb2414eead90cdae685708 (patch)
tree2c79c111805f38454e07d96645f3fdc31fe75860 /elm/Lib/Html.elm
parent1fb8a234cf5a455af6d78c893320b21de8347bc4 (diff)
v2rw: Convert staff adding/editing form
This is the first major editing form to be converted, so I'm expecting a little breakage. A good chunk of this code has been copied from v3. In terms of the UI there has been a small change: aliases that are still referenced do not have the 'remove' link and instead have a flag that shows that they are still referenced. This ought to be a bit friendlier than throwing an error message after the user has submitted the form. Some other things I'd like to improve in this form: - BBCode preview - Pasting in external links and letting the form figure out the Pixiv ID, etc. - Or perhaps even: Integrate AniDB/Wikidata search/autocompletion.
Diffstat (limited to 'elm/Lib/Html.elm')
-rw-r--r--elm/Lib/Html.elm44
1 files changed, 35 insertions, 9 deletions
diff --git a/elm/Lib/Html.elm b/elm/Lib/Html.elm
index d2588799..fe67da32 100644
--- a/elm/Lib/Html.elm
+++ b/elm/Lib/Html.elm
@@ -82,6 +82,8 @@ inputTextArea : String -> String -> (String -> m) -> List (Attribute m) -> Html
inputTextArea nam val onch attrs = textarea (
[ tabindex 10
, onInput onch
+ , rows 4
+ , cols 50
]
++ attrs
++ (if nam == "" then [] else [ id nam, name nam ])
@@ -99,12 +101,33 @@ inputCheck nam val onch = input (
) []
+inputRadio : String -> Bool -> (Bool -> m) -> Html m
+inputRadio nam val onch = input (
+ [ type_ "radio"
+ , tabindex 10
+ , onCheck onch
+ , checked val
+ ]
+ ++ (if nam == "" then [] else [ name nam ])
+ ) []
+
+
+-- Same as an inputText, but formats/parses an integer as Q###
+inputWikidata : String -> Int -> (Int -> m) -> Html m
+inputWikidata nam val onch =
+ inputText nam
+ (if val == 0 then "" else "Q" ++ String.fromInt val)
+ (\v -> onch <| if v == "" then 0 else Maybe.withDefault val <| String.toInt <| if String.startsWith "Q" v then String.dropLeft 1 v else v)
+ [ pattern "^Q?[1-9][0-9]{0,8}$" ]
+
+
-- 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
+-- "none" -> To generate a full-width field (colspan=2)
+-- "" -> Empty label
+-- "Some string" -> Text label
+-- "Some string#eng" -> Text label with (English please!) message
+-- "input::String" -> Label that refers to the named input (also supports #eng)
--
-- (Yeah, stringly typed arguments; I wish Elm had typeclasses)
formField : String -> List (Html m) -> Html m
@@ -113,10 +136,13 @@ formField lbl cont =
[ 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
- ]
+ let
+ (nlbl, eng) = if String.endsWith "#eng" lbl then (String.dropRight 4 lbl, True) else (lbl, False)
+ genlbl str = text str :: if eng then [ br [] [], b [ class "standout" ] [ text "English please!" ] ] else []
+ in
+ td [ class "label" ] <|
+ case String.split "::" nlbl of
+ [name, txt] -> [ label [ for name ] (genlbl txt) ]
+ txt -> genlbl (String.concat txt)
, td (class "field" :: if lbl == "none" then [ colspan 2 ] else []) cont
]