aboutsummaryrefslogtreecommitdiff
path: root/src/client/elm/Dialog.elm
diff options
context:
space:
mode:
authorJoris2016-06-26 15:01:14 +0200
committerJoris2016-06-26 15:01:14 +0200
commit7ec5b5601fd655643ad0fe1120d56bc9b71674f6 (patch)
tree48dfdb9139cb2d0befdb69595dffdf8462c86b6f /src/client/elm/Dialog.elm
parent27bf42c165e5a9fa242e0679fca621f2a6dc4adb (diff)
downloadbudget-7ec5b5601fd655643ad0fe1120d56bc9b71674f6.tar.gz
budget-7ec5b5601fd655643ad0fe1120d56bc9b71674f6.tar.bz2
budget-7ec5b5601fd655643ad0fe1120d56bc9b71674f6.zip
Set up enter form submi behaviour on dialog
Diffstat (limited to 'src/client/elm/Dialog.elm')
-rw-r--r--src/client/elm/Dialog.elm31
1 files changed, 13 insertions, 18 deletions
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")
]