diff options
author | Yorhel <git@yorhel.nl> | 2020-11-13 11:37:35 +0100 |
---|---|---|
committer | Yorhel <git@yorhel.nl> | 2020-11-13 11:37:37 +0100 |
commit | 20011cf2f110d1d89d243ce77b122675463d93b5 (patch) | |
tree | 0e7fa402c0a70bfdc0fc9dd34900574b85acf431 | |
parent | 6d228704f2e13bccc3c418da5b8ddf537b206ce1 (diff) |
Elm/forms: Fix reporting of validation errors for fields on hidden tabs
https://vndb.org/t950.830
-rw-r--r-- | elm/CharEdit.elm | 43 | ||||
-rw-r--r-- | elm/Discussions/Edit.elm | 2 | ||||
-rw-r--r-- | elm/Discussions/Poll.elm | 2 | ||||
-rw-r--r-- | elm/Discussions/PostEdit.elm | 2 | ||||
-rw-r--r-- | elm/Discussions/Reply.elm | 2 | ||||
-rw-r--r-- | elm/DocEdit.elm | 2 | ||||
-rw-r--r-- | elm/Lib/Html.elm | 14 | ||||
-rw-r--r-- | elm/Lib/Image.elm | 7 | ||||
-rw-r--r-- | elm/ProducerEdit.elm | 6 | ||||
-rw-r--r-- | elm/ReleaseEdit.elm | 2 | ||||
-rw-r--r-- | elm/Report.elm | 2 | ||||
-rw-r--r-- | elm/Reviews/Comment.elm | 2 | ||||
-rw-r--r-- | elm/Reviews/Edit.elm | 2 | ||||
-rw-r--r-- | elm/StaffEdit.elm | 4 | ||||
-rw-r--r-- | elm/TagEdit.elm | 2 | ||||
-rw-r--r-- | elm/Tagmod.elm | 2 | ||||
-rw-r--r-- | elm/TraitEdit.elm | 2 | ||||
-rw-r--r-- | elm/UList/SaveDefault.elm | 2 | ||||
-rw-r--r-- | elm/User/Edit.elm | 2 | ||||
-rw-r--r-- | elm/User/Login.elm | 2 | ||||
-rw-r--r-- | elm/User/PassReset.elm | 2 | ||||
-rw-r--r-- | elm/User/PassSet.elm | 2 | ||||
-rw-r--r-- | elm/User/Register.elm | 2 | ||||
-rw-r--r-- | elm/VNEdit.elm | 38 |
24 files changed, 86 insertions, 62 deletions
diff --git a/elm/CharEdit.elm b/elm/CharEdit.elm index 837fbb4b..20fd97fb 100644 --- a/elm/CharEdit.elm +++ b/elm/CharEdit.elm @@ -8,8 +8,11 @@ import Browser import Browser.Navigation exposing (load) import Dict import Set +import Task +import Process import File exposing (File) import File.Select as FSel +import Lib.Ffi as Ffi import Lib.Util exposing (..) import Lib.Html exposing (..) import Lib.TextPreview as TP @@ -43,6 +46,7 @@ type Tab type alias Model = { state : Api.State , tab : Tab + , invalidDis : Bool , editsum : Editsum.Model , name : String , original : String @@ -82,6 +86,7 @@ init : GCE.Recv -> Model init d = { state = Api.Normal , tab = General + , invalidDis = False , editsum = { authmod = d.authmod, editsum = TP.bbcode d.editsum, locked = d.locked, hidden = d.hidden } , name = d.name , original = d.original @@ -158,6 +163,8 @@ vnConfig = { wrap = VnSearch, id = "vnadd", source = A.vnSource } type Msg = Editsum Editsum.Msg | Tab Tab + | Invalid Tab + | InvalidEnable | Submit | Submitted GApi.Response | Name String @@ -201,6 +208,9 @@ update msg model = case msg of Editsum m -> let (nm,nc) = Editsum.update m model.editsum in ({ model | editsum = nm }, Cmd.map Editsum nc) Tab t -> ({ model | tab = t }, Cmd.none) + Invalid t -> if model.invalidDis || model.tab == All || model.tab == t then (model, Cmd.none) else + ({ model | tab = t, invalidDis = True }, Task.attempt (always InvalidEnable) (Ffi.elemCall "reportValidity" "mainform" |> Task.andThen (\_ -> Process.sleep 100))) + InvalidEnable -> ({ model | invalidDis = False }, Cmd.none) Name s -> ({ model | name = s }, Cmd.none) Original s -> ({ model | original = s }, Cmd.none) Alias s -> ({ model | alias = s }, Cmd.none) @@ -289,19 +299,20 @@ view : Model -> Html Msg view model = let geninfo = - [ formField "name::Name (romaji)" [ inputText "name" model.name Name GCE.valName ] + [ formField "name::Name (romaji)" [ inputText "name" model.name Name (onInvalid (Invalid General) :: GCE.valName) ] , formField "original::Original name" - [ inputText "original" model.original Original GCE.valOriginal + [ inputText "original" model.original Original (onInvalid (Invalid General) :: GCE.valOriginal) , if model.name /= "" && model.name == model.original then b [ class "standout" ] [ br [] [], text "Should not be the same as the Name (romaji). Leave blank is the original name is already in the latin alphabet" ] else text "" ] , formField "alias::Aliases" - [ inputTextArea "alias" model.alias Alias (rows 3 :: GCE.valAlias) + [ inputTextArea "alias" model.alias Alias (rows 3 :: onInvalid (Invalid General) :: GCE.valAlias) , br [] [] , text "(Un)official aliases, separated by a newline. Must not include spoilers!" ] - , formField "desc::Description" [ TP.view "desc" model.desc Desc 600 (style "height" "150px" :: GCE.valDesc) [ b [ class "standout" ] [ text "English please!" ] ] ] + , formField "desc::Description" [ TP.view "desc" model.desc Desc 600 (style "height" "150px" :: onInvalid (Invalid General) :: GCE.valDesc) + [ b [ class "standout" ] [ text "English please!" ] ] ] , formField "bmonth::Birthday" [ inputSelect "bmonth" model.bMonth BMonth [style "width" "128px"] [ ( 0, "Unknown") @@ -321,7 +332,7 @@ view model = , if model.bMonth == 0 then text "" else inputSelect "" model.bDay BDay [style "width" "70px"] <| List.map (\i -> (i, String.fromInt i)) <| List.range 1 31 ] - , formField "age::Age" [ inputNumber "age" model.age Age GCE.valAge, text " years" ] + , formField "age::Age" [ inputNumber "age" model.age Age (onInvalid (Invalid General) :: GCE.valAge), text " years" ] , tr [ class "newpart" ] [ td [ colspan 2 ] [ text "Body" ] ] , formField "gender::Sex" @@ -338,13 +349,13 @@ view model = , inputSelect "" gen (\s -> SpoilGender (Just s)) [] GT.genders ] ] - , formField "sbust::Bust" [ inputNumber "sbust" (if model.sBust == 0 then Nothing else Just model.sBust ) SBust GCE.valS_Bust, text " cm" ] - , formField "swaist::Waist" [ inputNumber "swiast" (if model.sWaist == 0 then Nothing else Just model.sWaist) SWaist GCE.valS_Waist,text " cm" ] - , formField "ship::Hips" [ inputNumber "ship" (if model.sHip == 0 then Nothing else Just model.sHip ) SHip GCE.valS_Hip, text " cm" ] - , formField "height::Height" [ inputNumber "height" (if model.height == 0 then Nothing else Just model.height) Height GCE.valHeight, text " cm" ] - , formField "weight::Weight" [ inputNumber "weight" model.weight Weight GCE.valWeight, text " kg" ] - , formField "bloodt::Blood type" [ inputSelect "bloodt" model.bloodt BloodT [] GT.bloodTypes ] - , formField "cupsize::Cup size" [ inputSelect "cupsize" model.cupSize CupSize [] GT.cupSizes ] + , formField "sbust::Bust" [ inputNumber "sbust" (if model.sBust == 0 then Nothing else Just model.sBust ) SBust (onInvalid (Invalid General) :: GCE.valS_Bust), text " cm" ] + , formField "swaist::Waist" [ inputNumber "swiast" (if model.sWaist == 0 then Nothing else Just model.sWaist) SWaist (onInvalid (Invalid General) :: GCE.valS_Waist),text " cm" ] + , formField "ship::Hips" [ inputNumber "ship" (if model.sHip == 0 then Nothing else Just model.sHip ) SHip (onInvalid (Invalid General) :: GCE.valS_Hip), text " cm" ] + , formField "height::Height" [ inputNumber "height" (if model.height == 0 then Nothing else Just model.height) Height (onInvalid (Invalid General) :: GCE.valHeight), text " cm" ] + , formField "weight::Weight" [ inputNumber "weight" model.weight Weight (onInvalid (Invalid General) :: GCE.valWeight), text " kg" ] + , formField "bloodt::Blood type" [ inputSelect "bloodt" model.bloodt BloodT [onInvalid (Invalid General)] GT.bloodTypes ] + , formField "cupsize::Cup size" [ inputSelect "cupsize" model.cupSize CupSize [onInvalid (Invalid General)] GT.cupSizes ] , tr [ class "newpart" ] [ td [ colspan 2 ] [ text "Instance" ] ] ] ++ if model.mainRef @@ -370,7 +381,7 @@ view model = [ td [] [ Img.viewImg model.image ] , td [] [ h2 [] [ text "Image ID" ] - , input ([ type_ "text", class "text", tabindex 10, value (Maybe.withDefault "" model.image.id), onInputValidation ImageSet ] ++ GCE.valImage) [] + , input ([ type_ "text", class "text", tabindex 10, value (Maybe.withDefault "" model.image.id), onInvalid (Invalid Image), onInputValidation ImageSet ] ++ GCE.valImage) [] , br [] [] , text "Use an image that already exists on the server or empty to remove the current image." , br_ 2 @@ -378,13 +389,13 @@ view model = , inputButton "Browse image" ImageSelect [] , br [] [] , text "Image must be in JPEG or PNG format and at most 10 MiB. Images larger than 256x300 will automatically be resized." - , case Img.viewVote model.image of + , case Img.viewVote model.image ImageMsg (Invalid Image) of Nothing -> text "" Just v -> div [] [ br [] [] , text "Please flag this image: (see the ", a [ href "/d19" ] [ text "image flagging guidelines" ], text " for guidance)" - , Html.map ImageMsg v + , v ] ] ] ] @@ -483,7 +494,7 @@ view model = [ ("add", tr [] [ td [ colspan 4 ] [ br_ 1, A.view vnConfig model.vnSearch [placeholder "Add visual novel..."] ] ]) ] in - form_ Submit (model.state == Api.Loading) + form_ "mainform" Submit (model.state == Api.Loading) [ div [ class "maintabs left" ] [ ul [] [ li [ classList [("tabselected", model.tab == General)] ] [ a [ href "#", onClickD (Tab General) ] [ text "General info" ] ] diff --git a/elm/Discussions/Edit.elm b/elm/Discussions/Edit.elm index 6008cdef..082b4634 100644 --- a/elm/Discussions/Edit.elm +++ b/elm/Discussions/Edit.elm @@ -204,7 +204,7 @@ view model = in - form_ Submit (model.state == Api.Loading) + form_ "" Submit (model.state == Api.Loading) [ div [ class "mainbox" ] [ h1 [] [ text <| if model.tid == Nothing then "Create new thread" else "Edit thread" ] , table [ class "formtable" ] <| diff --git a/elm/Discussions/Poll.elm b/elm/Discussions/Poll.elm index 04761530..ec30fb06 100644 --- a/elm/Discussions/Poll.elm +++ b/elm/Discussions/Poll.elm @@ -109,7 +109,7 @@ view model = else text "" ] in - form_ Submit (model.state == Api.Loading) + form_ "" Submit (model.state == Api.Loading) [ div [ class "mainbox" ] [ h1 [] [ text model.data.question ] , table [ class "votebooth" ] diff --git a/elm/Discussions/PostEdit.elm b/elm/Discussions/PostEdit.elm index 0eb787d2..a46638a4 100644 --- a/elm/Discussions/PostEdit.elm +++ b/elm/Discussions/PostEdit.elm @@ -79,7 +79,7 @@ update msg model = view : Model -> Html Msg view model = - form_ Submit (model.state == Api.Loading) + form_ "" Submit (model.state == Api.Loading) [ div [ class "mainbox" ] [ h1 [] [ text "Edit post" ] , table [ class "formtable" ] <| diff --git a/elm/Discussions/Reply.elm b/elm/Discussions/Reply.elm index 3581c91f..1769b06c 100644 --- a/elm/Discussions/Reply.elm +++ b/elm/Discussions/Reply.elm @@ -58,7 +58,7 @@ update msg model = view : Model -> Html Msg view model = - form_ Submit (model.state == Api.Loading) + form_ "" Submit (model.state == Api.Loading) [ div [ class "mainbox" ] <| [ if model.old then diff --git a/elm/DocEdit.elm b/elm/DocEdit.elm index 9fbea631..df2b333e 100644 --- a/elm/DocEdit.elm +++ b/elm/DocEdit.elm @@ -75,7 +75,7 @@ update msg model = view : Model -> Html Msg view model = - form_ Submit (model.state == Api.Loading) + form_ "" Submit (model.state == Api.Loading) [ div [ class "mainbox" ] [ h1 [] [ text <| "Edit d" ++ String.fromInt model.id ] , table [ class "formtable" ] diff --git a/elm/Lib/Html.elm b/elm/Lib/Html.elm index 440abd00..01f5d844 100644 --- a/elm/Lib/Html.elm +++ b/elm/Lib/Html.elm @@ -25,6 +25,8 @@ onInputValidation msg = custom "input" <| targetValue (JD.at ["target", "validity", "valid"] JD.bool) +onInvalid : msg -> Attribute msg +onInvalid msg = on "invalid" (JD.succeed msg) -- Multi-<br> (ugly but oh, so, convenient) br_ : Int -> Html m @@ -33,9 +35,9 @@ br_ n = if n == 1 then br [] [] else span [] <| List.repeat n <| br [] [] -- Quick short-hand way of creating a form that can be disabled. -- Usage: --- form_ Submit_msg (state == Disabled) [contents] -form_ : msg -> Bool -> List (Html msg) -> Html msg -form_ sub dis cont = Html.form [ onSubmit sub ] +-- form_ id Submit_msg (state == Disabled) [contents] +form_ : String -> msg -> Bool -> List (Html msg) -> Html msg +form_ s sub dis cont = Html.form [ id s, onSubmit sub ] [ fieldset [disabled dis] cont ] @@ -155,14 +157,14 @@ inputRadio nam val onch = input ( -- Same as an inputText, but formats/parses an integer as Q### -inputWikidata : String -> Maybe Int -> (Maybe Int -> m) -> Html m -inputWikidata nam val onch = +inputWikidata : String -> Maybe Int -> (Maybe Int -> m) -> List (Attribute m) -> Html m +inputWikidata nam val onch attr = inputText nam (case val of Nothing -> "" Just v -> "Q" ++ String.fromInt v) (\v -> onch <| if v == "" then Nothing else String.toInt <| if String.startsWith "Q" v then String.dropLeft 1 v else v) - [ pattern "^Q?[1-9][0-9]{0,8}$" ] + (pattern "^Q?[1-9][0-9]{0,8}$" :: attr) -- Similar to inputCheck and inputRadio with a label, except this is just a link. diff --git a/elm/Lib/Image.elm b/elm/Lib/Image.elm index 31bab0b3..37cc26b4 100644 --- a/elm/Lib/Image.elm +++ b/elm/Lib/Image.elm @@ -143,14 +143,15 @@ viewImg image = ] -viewVote : Image -> Maybe (Html Msg) -viewVote model = +viewVote : Image -> (Msg -> a) -> a -> Maybe (Html a) +viewVote model wrap msg = let rad i sex val = input [ type_ "radio" , tabindex 10 , required True - , onCheck <| (if sex then MySex else MyVio) val + , onInvalid msg + , onCheck <| \b -> wrap <| (if sex then MySex else MyVio) val b , checked <| (if sex then i.my_sexual else i.my_violence) == Just val , name <| "imgvote-" ++ (if sex then "sex" else "vio") ++ "-" ++ Maybe.withDefault "" model.id ] [] diff --git a/elm/ProducerEdit.elm b/elm/ProducerEdit.elm index 0fd78375..213f8516 100644 --- a/elm/ProducerEdit.elm +++ b/elm/ProducerEdit.elm @@ -177,7 +177,7 @@ view model = ++ titles ++ [ formField "lang::Primary language" [ inputSelect "lang" model.lang Lang [] GT.languages ] , formField "website::Website" [ inputText "website" model.website Website GPE.valWebsite ] - , formField "l_wikidata::Wikidata ID" [ inputWikidata "l_wikidata" model.lWikidata LWikidata ] + , formField "l_wikidata::Wikidata ID" [ inputWikidata "l_wikidata" model.lWikidata LWikidata [] ] , formField "desc::Description" [ TP.view "desc" model.desc Desc 600 (style "height" "180px" :: GPE.valDesc) [ b [ class "standout" ] [ text "English please!" ] ] ] @@ -200,7 +200,7 @@ view model = ] newform () = - form_ DupSubmit (model.state == Api.Loading) + form_ "" DupSubmit (model.state == Api.Loading) [ div [ class "mainbox" ] [ h1 [] [ text "Add a new producer" ], table [ class "formtable" ] titles ] , div [ class "mainbox" ] [ if List.isEmpty model.dupProds then text "" else @@ -220,7 +220,7 @@ view model = ] fullform () = - form_ Submit (model.state == Api.Loading) + form_ "" Submit (model.state == Api.Loading) [ div [ class "mainbox" ] [ h1 [] [ text "Edit producer" ], table [ class "formtable" ] geninfo ] , div [ class "mainbox" ] [ fieldset [ class "submit" ] [ Html.map Editsum (Editsum.view model.editsum) diff --git a/elm/ReleaseEdit.elm b/elm/ReleaseEdit.elm index 1bcf91c5..b62678c9 100644 --- a/elm/ReleaseEdit.elm +++ b/elm/ReleaseEdit.elm @@ -436,7 +436,7 @@ viewGen model = view : Model -> Html Msg view model = - form_ Submit (model.state == Api.Loading) + form_ "" Submit (model.state == Api.Loading) [ div [ class "mainbox" ] [ h1 [] [ text "General info" ] , viewGen model diff --git a/elm/Report.elm b/elm/Report.elm index 342b37da..f9fb1cd3 100644 --- a/elm/Report.elm +++ b/elm/Report.elm @@ -163,7 +163,7 @@ view (state,model) = lst = List.filter (\l -> l.vis model.object) reasons cur = List.filter (\l -> l.label == model.reason) lst |> List.head |> Maybe.withDefault initial in - form_ Submit (state == Api.Loading) + form_ "" Submit (state == Api.Loading) [ div [ class "mainbox" ] [ h1 [] [ text "Submit report" ] , if state == Api.Error GApi.Success diff --git a/elm/Reviews/Comment.elm b/elm/Reviews/Comment.elm index fba37168..8b2399dd 100644 --- a/elm/Reviews/Comment.elm +++ b/elm/Reviews/Comment.elm @@ -38,7 +38,7 @@ update msg (state,id,content) = view : Model -> Html Msg view (state,_,content) = - form_ Submit (state == Api.Loading) + form_ "" Submit (state == Api.Loading) [ div [ class "mainbox" ] [ fieldset [ class "submit" ] [ TP.view "msg" content Content 600 ([rows 4, cols 50] ++ GRC.valMsg) diff --git a/elm/Reviews/Edit.elm b/elm/Reviews/Edit.elm index 925de964..c5314e27 100644 --- a/elm/Reviews/Edit.elm +++ b/elm/Reviews/Edit.elm @@ -110,7 +110,7 @@ view model = maxChars = if model.isfull then 100000 else 800 len = String.length model.text.data in - form_ Submit (model.state == Api.Loading) + form_ "" Submit (model.state == Api.Loading) [ div [ class "mainbox" ] [ h1 [] [ text <| if model.id == Nothing then "Submit a review" else "Edit review" ] , p [] [ b [] [ text "Rules" ] ] diff --git a/elm/StaffEdit.elm b/elm/StaffEdit.elm index 134a409b..a2e4f5df 100644 --- a/elm/StaffEdit.elm +++ b/elm/StaffEdit.elm @@ -178,7 +178,7 @@ view model = ] in - form_ Submit (model.state == Api.Loading) + form_ "" Submit (model.state == Api.Loading) [ div [ class "mainbox staffedit" ] [ h1 [] [ text "General info" ] , table [ class "formtable" ] @@ -191,7 +191,7 @@ view model = ] ] , formField "lang::Primary Language" [ inputSelect "lang" model.lang Lang [] GT.languages ] , formField "l_site::Official page" [ inputText "l_site" model.l_site Website (style "width" "400px" :: GSE.valL_Site) ] - , formField "l_wikidata::Wikidata ID" [ inputWikidata "l_wikidata" model.l_wikidata LWikidata ] + , formField "l_wikidata::Wikidata ID" [ inputWikidata "l_wikidata" model.l_wikidata LWikidata [] ] , formField "l_twitter::Twitter username" [ inputText "l_twitter" model.l_twitter LTwitter GSE.valL_Twitter ] , formField "l_anidb::AniDB Creator ID" [ inputText "l_anidb" (Maybe.withDefault "" (Maybe.map String.fromInt model.l_anidb)) LAnidb GSE.valL_Anidb ] , formField "l_pixiv::Pixiv ID" [ inputText "l_pixiv" (if model.l_pixiv == 0 then "" else String.fromInt model.l_pixiv) LPixiv GSE.valL_Pixiv ] diff --git a/elm/TagEdit.elm b/elm/TagEdit.elm index e8abedaa..2501f7b1 100644 --- a/elm/TagEdit.elm +++ b/elm/TagEdit.elm @@ -158,7 +158,7 @@ update msg model = view : Model -> Html Msg view model = - form_ Submit (model.formstate == Api.Loading) + form_ "" Submit (model.formstate == Api.Loading) [ div [ class "mainbox" ] [ h1 [] [ text <| if model.id == Nothing then "Submit new tag" else "Edit tag" ] , table [ class "formtable" ] <| diff --git a/elm/Tagmod.elm b/elm/Tagmod.elm index 82b6fd13..97ce93b0 100644 --- a/elm/Tagmod.elm +++ b/elm/Tagmod.elm @@ -248,7 +248,7 @@ viewFoot state changed add addMsg = -- The table has a lot of interactivity, the use of Html.Lazy is absolutely necessary for good responsiveness. view : Model -> Html Msg view model = - form_ Submit (model.state == Api.Loading) + form_ "" Submit (model.state == Api.Loading) [ div [ class "mainbox" ] [ h1 [] [ text <| "Edit tags for " ++ model.title ] , p [] diff --git a/elm/TraitEdit.elm b/elm/TraitEdit.elm index f7090af1..6b257ce1 100644 --- a/elm/TraitEdit.elm +++ b/elm/TraitEdit.elm @@ -140,7 +140,7 @@ update msg model = view : Model -> Html Msg view model = - form_ Submit (model.formstate == Api.Loading) + form_ "" Submit (model.formstate == Api.Loading) [ div [ class "mainbox" ] [ h1 [] [ text <| if model.id == Nothing then "Submit new trait" else "Edit trait" ] , table [ class "formtable" ] diff --git a/elm/UList/SaveDefault.elm b/elm/UList/SaveDefault.elm index a0945c4b..0ab2cef9 100644 --- a/elm/UList/SaveDefault.elm +++ b/elm/UList/SaveDefault.elm @@ -56,7 +56,7 @@ update msg model = view : Model -> Html Msg view model = - form_ Submit (model.state == Api.Loading) + form_ "" Submit (model.state == Api.Loading) [ div [ classList [("savedefault", True), ("hidden", model.hid)] ] [ b [] [ text "Save as default" ] , br [] [] diff --git a/elm/User/Edit.elm b/elm/User/Edit.elm index d09c77ae..43ec1212 100644 --- a/elm/User/Edit.elm +++ b/elm/User/Edit.elm @@ -266,7 +266,7 @@ view model = , formField "css::Custom CSS" [ inputTextArea "css" m.customcss (Prefs << Css) ([ rows 5, cols 60 ] ++ GUE.valPrefsCustomcss) ] ] - in form_ Submit (model.state == Api.Loading) + in form_ "" Submit (model.state == Api.Loading) [ div [ class "mainbox" ] [ h1 [] [ text model.title ] , table [ class "formtable" ] <| diff --git a/elm/User/Login.elm b/elm/User/Login.elm index 8b9c15c3..c1c55dfe 100644 --- a/elm/User/Login.elm +++ b/elm/User/Login.elm @@ -134,7 +134,7 @@ view model = ] ] - in form_ Submit (model.state == Api.Loading) + in form_ "" Submit (model.state == Api.Loading) [ if model.insecure then changeBox else loginBox , div [ class "mainbox" ] [ fieldset [ class "submit" ] diff --git a/elm/User/PassReset.elm b/elm/User/PassReset.elm index 641767d4..dbcb1d57 100644 --- a/elm/User/PassReset.elm +++ b/elm/User/PassReset.elm @@ -59,7 +59,7 @@ view model = [ p [] [ text "Your password has been reset and instructions to set a new one should reach your mailbox in a few minutes." ] ] ] else - form_ Submit (model.state == Api.Loading) + form_ "" Submit (model.state == Api.Loading) [ div [ class "mainbox" ] [ h1 [] [ text "Forgot Password" ] , p [] diff --git a/elm/User/PassSet.elm b/elm/User/PassSet.elm index 618b4ba1..9ad10748 100644 --- a/elm/User/PassSet.elm +++ b/elm/User/PassSet.elm @@ -66,7 +66,7 @@ update msg model = view : Model -> Html Msg view model = - form_ Submit (model.state == Api.Loading) + form_ "" Submit (model.state == Api.Loading) [ div [ class "mainbox" ] [ h1 [] [ text "Set your password" ] , p [] [ text "Now you can set a password for your account. You will be logged in automatically after your password has been saved." ] diff --git a/elm/User/Register.elm b/elm/User/Register.elm index 9afdded4..de8e36ce 100644 --- a/elm/User/Register.elm +++ b/elm/User/Register.elm @@ -70,7 +70,7 @@ view model = [ p [] [ text "Your account has been created! In a few minutes, you should receive an email with instructions to set your password." ] ] ] else - form_ Submit (model.state == Api.Loading) + form_ "" Submit (model.state == Api.Loading) [ div [ class "mainbox" ] [ h1 [] [ text "Create an account" ] , table [ class "formtable" ] diff --git a/elm/VNEdit.elm b/elm/VNEdit.elm index 711089de..9051a85a 100644 --- a/elm/VNEdit.elm +++ b/elm/VNEdit.elm @@ -8,8 +8,11 @@ import Browser import Browser.Navigation exposing (load) import Dict import Set +import Task +import Process import File exposing (File) import File.Select as FSel +import Lib.Ffi as Ffi import Lib.Util exposing (..) import Lib.Html exposing (..) import Lib.TextPreview as TP @@ -46,6 +49,7 @@ type Tab type alias Model = { state : Api.State , tab : Tab + , invalidDis : Bool , editsum : Editsum.Model , title : String , original : String @@ -81,6 +85,7 @@ init : GVE.Recv -> Model init d = { state = Api.Normal , tab = General + , invalidDis = False , editsum = { authmod = d.authmod, editsum = TP.bbcode d.editsum, locked = d.locked, hidden = d.hidden } , title = d.title , original = d.original @@ -148,6 +153,8 @@ seiyuuConfig = { wrap = SeiyuuSearch, id = "seiyuuadd", source = A.staffSource } type Msg = Editsum Editsum.Msg | Tab Tab + | Invalid Tab + | InvalidEnable | Submit | Submitted GApi.Response | Title String @@ -204,6 +211,9 @@ update msg model = case msg of Editsum m -> let (nm,nc) = Editsum.update m model.editsum in ({ model | editsum = nm }, Cmd.map Editsum nc) Tab t -> ({ model | tab = t }, Cmd.none) + Invalid t -> if model.invalidDis || model.tab == All || model.tab == t then (model, Cmd.none) else + ({ model | tab = t, invalidDis = True }, Task.attempt (always InvalidEnable) (Ffi.elemCall "reportValidity" "mainform" |> Task.andThen (\_ -> Process.sleep 100))) + InvalidEnable -> ({ model | invalidDis = False }, Cmd.none) Title s -> ({ model | title = s, dupVNs = [] }, Cmd.none) Original s -> ({ model | original = s, dupVNs = [] }, Cmd.none) Alias s -> ({ model | alias = s, dupVNs = [] }, Cmd.none) @@ -312,13 +322,13 @@ view model = let titles = [ formField "title::Title (romaji)" - [ inputText "title" model.title Title (style "width" "500px" :: GVE.valTitle) + [ inputText "title" model.title Title (style "width" "500px" :: onInvalid (Invalid General) :: GVE.valTitle) , if containsNonLatin model.title then b [ class "standout" ] [ br [] [], text "This title field should only contain latin-alphabet characters, please put the \"actual\" title in the field below and the romanization above." ] else text "" ] , formField "original::Original title" - [ inputText "original" model.original Original (style "width" "500px" :: GVE.valOriginal) + [ inputText "original" model.original Original (style "width" "500px" :: onInvalid (Invalid General) :: GVE.valOriginal) , if model.title /= "" && model.title == model.original then b [ class "standout" ] [ br [] [], text "Should not be the same as the Title (romaji). Leave blank is the original title is already in the latin alphabet" ] else if model.original /= "" && String.toLower model.title /= String.toLower model.original && not (containsNonLatin model.original) @@ -326,7 +336,7 @@ view model = else text "" ] , formField "alias::Aliases" - [ inputTextArea "alias" model.alias Alias (rows 3 :: GVE.valAlias) + [ inputTextArea "alias" model.alias Alias (rows 3 :: onInvalid (Invalid General) :: GVE.valAlias) , br [] [] , if hasDuplicates <| String.lines <| String.toLower model.alias then b [ class "standout" ] [ text "List contains duplicate aliases.", br [] [] ] @@ -348,12 +358,12 @@ view model = geninfo = titles ++ [ formField "desc::Description" - [ TP.view "desc" model.desc Desc 600 (style "height" "180px" :: GVE.valDesc) [ b [ class "standout" ] [ text "English please!" ] ] + [ TP.view "desc" model.desc Desc 600 (style "height" "180px" :: onInvalid (Invalid General) :: GVE.valDesc) [ b [ class "standout" ] [ text "English please!" ] ] , text "Short description of the main story. Please do not include spoilers, and don't forget to list the source in case you didn't write the description yourself." ] , formField "length::Length" [ inputSelect "length" model.length Length [] GT.vnLengths ] - , formField "l_wikidata::Wikidata ID" [ inputWikidata "l_wikidata" model.lWikidata LWikidata ] - , formField "l_renai::Renai.us link" [ text "http://renai.us/game/", inputText "l_renai" model.lRenai LRenai [], text ".shtml" ] + , formField "l_wikidata::Wikidata ID" [ inputWikidata "l_wikidata" model.lWikidata LWikidata [onInvalid (Invalid General)] ] + , formField "l_renai::Renai.us link" [ text "http://renai.us/game/", inputText "l_renai" model.lRenai LRenai (onInvalid (Invalid General) :: GVE.valL_Renai), text ".shtml" ] , tr [ class "newpart" ] [ td [ colspan 2 ] [ text "Database relations" ] ] , formField "Related VNs" @@ -390,7 +400,7 @@ view model = [ td [] [ Img.viewImg model.image ] , td [] [ h2 [] [ text "Image ID" ] - , input ([ type_ "text", class "text", tabindex 10, value (Maybe.withDefault "" model.image.id), onInputValidation ImageSet ] ++ GVE.valImage) [] + , input ([ type_ "text", class "text", tabindex 10, value (Maybe.withDefault "" model.image.id), onInputValidation ImageSet, onInvalid (Invalid Image) ] ++ GVE.valImage) [] , br [] [] , text "Use an image that already exists on the server or empty to remove the current image." , br_ 2 @@ -398,13 +408,13 @@ view model = , inputButton "Browse image" ImageSelect [] , br [] [] , text "Preferably the cover of the CD/DVD/package. Image must be in JPEG or PNG format and at most 10 MiB. Images larger than 256x400 will automatically be resized." - , case Img.viewVote model.image of + , case Img.viewVote model.image ImageMsg (Invalid Image) of Nothing -> text "" Just v -> div [] [ br [] [] , text "Please flag this image: (see the ", a [ href "/d19" ] [ text "image flagging guidelines" ], text " for guidance)" - , Html.map ImageMsg v + , v ] ] ] ] @@ -442,7 +452,7 @@ view model = [ td [ style "text-align" "right" ] [ b [ class "grayedout" ] [ text <| "s" ++ String.fromInt s.id ++ ":" ] ] , td [] [ a [ href <| "/s" ++ String.fromInt s.id ] [ text s.name ] ] , td [] [ inputSelect "" s.role (StaffRole n) [style "width" "150px" ] GT.creditTypes ] - , td [] [ inputText "" s.note (StaffNote n) (style "width" "300px" :: GVE.valStaffNote) ] + , td [] [ inputText "" s.note (StaffNote n) (style "width" "300px" :: onInvalid (Invalid Staff) :: GVE.valStaffNote) ] , td [] [ inputButton "remove" (StaffDel n) [] ] ] in table [] <| head ++ [ foot ] ++ List.indexedMap item model.staff @@ -481,7 +491,7 @@ view model = , td [] [ b [ class "grayedout" ] [ text <| "s" ++ String.fromInt s.id ++ ":" ] , a [ href <| "/s" ++ String.fromInt s.id ] [ text s.name ] ] - , td [] [ inputText "" s.note (SeiyuuNote n) (style "width" "300px" :: GVE.valSeiyuuNote) ] + , td [] [ inputText "" s.note (SeiyuuNote n) (style "width" "300px" :: onInvalid (Invalid Cast) :: GVE.valSeiyuuNote) ] , td [] [ inputButton "remove" (SeiyuuDel n) [] ] ] in @@ -508,7 +518,7 @@ view model = dimstr (x,y) = String.fromInt x ++ "x" ++ String.fromInt y in [ td [] [ Img.viewImg i ] - , td [] [ Img.viewVote i |> Maybe.map (Html.map (ScrMsg id)) |> Maybe.withDefault (text "") ] + , td [] [ Img.viewVote i (ScrMsg id) (Invalid Screenshots) |> Maybe.withDefault (text "") ] , td [] [ b [] [ text <| "Screenshot #" ++ String.fromInt (n+1) ] , text " (", a [ href "#", onClickD (ScrDel id) ] [ text "remove" ], text ")" @@ -591,7 +601,7 @@ view model = ] newform () = - form_ DupSubmit (model.state == Api.Loading) + form_ "" DupSubmit (model.state == Api.Loading) [ div [ class "mainbox" ] [ h1 [] [ text "Add a new visual novel" ], table [ class "formtable" ] titles ] , div [ class "mainbox" ] [ if List.isEmpty model.dupVNs then text "" else @@ -611,7 +621,7 @@ view model = ] fullform () = - form_ Submit (model.state == Api.Loading) + form_ "mainform" Submit (model.state == Api.Loading) [ div [ class "maintabs left" ] [ ul [] [ li [ classList [("tabselected", model.tab == General )] ] [ a [ href "#", onClickD (Tab General ) ] [ text "General info" ] ] |