From 4ce4de89a5400b0d8b9cddaa2922901a081fdaaa Mon Sep 17 00:00:00 2001 From: Joris Date: Thu, 23 Jun 2016 23:43:23 +0200 Subject: Use a dialog to add a payment --- src/client/elm/Dialog.elm | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) (limited to 'src/client/elm/Dialog.elm') diff --git a/src/client/elm/Dialog.elm b/src/client/elm/Dialog.elm index 0fb43db..4b5b4cd 100644 --- a/src/client/elm/Dialog.elm +++ b/src/client/elm/Dialog.elm @@ -8,7 +8,7 @@ module Dialog exposing ) import Platform.Cmd exposing (Cmd) -import Task +import Task exposing (Task) import Html exposing (..) import Html.Attributes exposing (..) @@ -25,7 +25,7 @@ type alias Config model msg = { title : String , body : model -> Html msg , confirm : String - , confirmMsg : msg + , confirmMsg : model -> Result msg msg , undo : String } @@ -39,12 +39,12 @@ init mapMsg = type Msg model msg = NoOp - | ConfirmMsg msg + | ConfirmMsg (model -> Result msg msg) | Open (Config model msg) | Close -update : Msg model msg -> Model model msg -> (Model model msg, Cmd msg) -update msg model = +update : Msg model msg -> model -> Model model msg -> (Model model msg, Cmd msg) +update msg baseModel model = case msg of NoOp -> ( model @@ -52,10 +52,15 @@ update msg model = ) ConfirmMsg confirmMsg -> - ( { model | config = Nothing } - , Task.succeed msg - |> Task.perform (always confirmMsg) (always 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) + ) Open config -> ( { model | config = Just config } @@ -90,7 +95,7 @@ curtain mapMsg isVisible = div [ class "curtain" , style - [ ("position", "absolute") + [ ("position", "fixed") , ("top", "0") , ("left", "0") , ("width", "100%") @@ -109,11 +114,10 @@ dialog model mapMsg { title, body, confirm, confirmMsg, undo } = div [ class "content" , style - [ ("min-width", "300px") - , ("position", "absolute") + [ ("position", "fixed") , ("top", "25%") , ("left", "50%") - , ("transform", "translate(-50%, -50%)") + , ("transform", "translate(-50%, -25%)") , ("z-index", "1000") , ("background-color", "white") , ("padding", "20px") -- cgit v1.2.3