From 70720548c9af024dbb6080638ac8e5470c2213eb Mon Sep 17 00:00:00 2001 From: Joris Date: Sat, 25 Jun 2016 15:10:03 +0200 Subject: Use the search to view either punctual or monthly payments --- src/client/elm/Dialog.elm | 62 ++++++++++++++++++++++++++++++++--------------- 1 file changed, 42 insertions(+), 20 deletions(-) (limited to 'src/client/elm/Dialog.elm') diff --git a/src/client/elm/Dialog.elm b/src/client/elm/Dialog.elm index 4b5b4cd..21286eb 100644 --- a/src/client/elm/Dialog.elm +++ b/src/client/elm/Dialog.elm @@ -16,41 +16,68 @@ import Html.Events exposing (..) -- Model -type alias Model model msg = +type alias Model model modelMsg msg = { config : Maybe (Config model msg) - , mapMsg : Msg model msg -> msg + , mapMsg : Msg model modelMsg msg -> msg + , model : model } type alias Config model msg = - { title : String + { className : String + , title : String , body : model -> Html msg , confirm : String , confirmMsg : model -> Result msg msg , undo : String } -init : (Msg model msg -> msg) -> Model model msg -init mapMsg = +init : model -> (Msg model modelMsg msg -> msg) -> Model model modelMsg msg +init model mapMsg = { config = Nothing , mapMsg = mapMsg + , model = model } -- Update -type Msg model msg = +type Msg model modelMsg msg = NoOp - | ConfirmMsg (model -> Result msg msg) + | UpdateModel modelMsg + | OpenWithUpdate (Config model msg) modelMsg | Open (Config model msg) + | ConfirmMsg (model -> Result msg msg) | Close -update : Msg model msg -> model -> Model model msg -> (Model model msg, Cmd msg) -update msg baseModel model = +update : (modelMsg -> model -> (model, Cmd modelMsg)) -> Msg model modelMsg msg -> model -> Model model modelMsg msg -> (Model model modelMsg msg, Cmd msg) +update updateModel msg baseModel model = case msg of NoOp -> ( model , Cmd.none ) + UpdateModel modelMsg -> + case updateModel modelMsg baseModel of + (newModel, effects) -> + ( { model | model = newModel } + , Cmd.map (model.mapMsg << UpdateModel) effects + ) + + OpenWithUpdate config modelMsg -> + case updateModel modelMsg baseModel of + (newModel, effects) -> + ( { model + | model = newModel + , config = Just config + } + , Cmd.map (model.mapMsg << UpdateModel) effects + ) + + Open config -> + ( { model | config = Just config } + , Cmd.none + ) + ConfirmMsg confirmMsg -> case confirmMsg baseModel of Ok msg -> @@ -62,11 +89,6 @@ update msg baseModel model = , Task.perform (always msg) (always msg) (Task.succeed NoOp) ) - Open config -> - ( { model | config = Just config } - , Cmd.none - ) - Close -> ( { model | config = Nothing } , Cmd.none @@ -74,8 +96,8 @@ update msg baseModel model = -- View -view : model -> Model model msg -> Html msg -view model { mapMsg, config } = +view : Model model modelMsg msg -> Html msg +view { mapMsg, config, model } = let isVisible = case config of Just _ -> True @@ -90,7 +112,7 @@ view model { mapMsg, config } = dialog model mapMsg c ] -curtain : (Msg model msg -> msg) -> Bool -> Html msg +curtain : (Msg model modelMsg msg -> msg) -> Bool -> Html msg curtain mapMsg isVisible = div [ class "curtain" @@ -109,10 +131,10 @@ curtain mapMsg isVisible = ] [] -dialog : model -> (Msg model msg -> msg) -> Config model msg -> Html msg -dialog model mapMsg { title, body, confirm, confirmMsg, undo } = +dialog : model -> (Msg model modelMsg msg -> msg) -> Config model msg -> Html msg +dialog model mapMsg { className, title, body, confirm, confirmMsg, undo } = div - [ class "content" + [ class ("content " ++ className) , style [ ("position", "fixed") , ("top", "25%") -- cgit v1.2.3