From 7ec5b5601fd655643ad0fe1120d56bc9b71674f6 Mon Sep 17 00:00:00 2001 From: Joris Date: Sun, 26 Jun 2016 15:01:14 +0200 Subject: Set up enter form submi behaviour on dialog --- src/client/elm/Dialog.elm | 31 +++++++++++++------------------ 1 file changed, 13 insertions(+), 18 deletions(-) (limited to 'src/client/elm/Dialog.elm') diff --git a/src/client/elm/Dialog.elm b/src/client/elm/Dialog.elm index 21286eb..3b9e93b 100644 --- a/src/client/elm/Dialog.elm +++ b/src/client/elm/Dialog.elm @@ -27,7 +27,7 @@ type alias Config model msg = , title : String , body : model -> Html msg , confirm : String - , confirmMsg : model -> Result msg msg + , confirmMsg : model -> msg , undo : String } @@ -42,10 +42,10 @@ init model mapMsg = type Msg model modelMsg msg = NoOp - | UpdateModel modelMsg + | Update modelMsg + | UpdateAndClose msg | OpenWithUpdate (Config model msg) modelMsg | Open (Config model msg) - | ConfirmMsg (model -> Result msg msg) | Close update : (modelMsg -> model -> (model, Cmd modelMsg)) -> Msg model modelMsg msg -> model -> Model model modelMsg msg -> (Model model modelMsg msg, Cmd msg) @@ -56,13 +56,19 @@ update updateModel msg baseModel model = , Cmd.none ) - UpdateModel modelMsg -> + Update modelMsg -> case updateModel modelMsg baseModel of (newModel, effects) -> ( { model | model = newModel } - , Cmd.map (model.mapMsg << UpdateModel) effects + , Cmd.map (model.mapMsg << Update) effects ) + UpdateAndClose msg -> + ( { model | config = Nothing } + , Task.succeed () + |> Task.perform (always msg) (always msg) + ) + OpenWithUpdate config modelMsg -> case updateModel modelMsg baseModel of (newModel, effects) -> @@ -70,7 +76,7 @@ update updateModel msg baseModel model = | model = newModel , config = Just config } - , Cmd.map (model.mapMsg << UpdateModel) effects + , Cmd.map (model.mapMsg << Update) effects ) Open config -> @@ -78,17 +84,6 @@ update updateModel msg baseModel model = , Cmd.none ) - ConfirmMsg confirmMsg -> - case confirmMsg baseModel of - Ok msg -> - ( { model | config = Nothing } - , Task.perform (always msg) (always msg) (Task.succeed NoOp) - ) - Err msg -> - ( model - , Task.perform (always msg) (always msg) (Task.succeed NoOp) - ) - Close -> ( { model | config = Nothing } , Cmd.none @@ -156,7 +151,7 @@ dialog model mapMsg { className, title, body, confirm, confirmMsg, undo } = ] [ button [ class "confirm" - , onClick (mapMsg <| ConfirmMsg confirmMsg) + , onClick (confirmMsg model) , style [ ("margin-right", "15px") ] -- cgit v1.2.3