From bb316286b0859b5648c61f44c88399f4c1aad9cd Mon Sep 17 00:00:00 2001 From: Joris Date: Sat, 2 Jan 2016 19:07:19 +0100 Subject: Use start-app for elm --- src/client/elm/View/LoggedIn/Account.elm | 65 ++++++++++++++++---------------- 1 file changed, 33 insertions(+), 32 deletions(-) (limited to 'src/client/elm/View/LoggedIn/Account.elm') diff --git a/src/client/elm/View/LoggedIn/Account.elm b/src/client/elm/View/LoggedIn/Account.elm index 706f7cc..9459740 100644 --- a/src/client/elm/View/LoggedIn/Account.elm +++ b/src/client/elm/View/LoggedIn/Account.elm @@ -2,23 +2,24 @@ module View.LoggedIn.Account ( account ) where +import List +import Signal exposing (Address) + import Html exposing (..) import Html as H exposing (..) import Html.Attributes exposing (..) import Html.Events exposing (..) -import List - -import ServerCommunication as SC exposing (serverCommunications) - -import Update exposing (..) -import Update.LoggedIn exposing (..) -import Update.LoggedIn.Account exposing (..) import Model exposing (Model) import Model.User exposing (getUserName) import Model.Payer exposing (..) -import Model.View.LoggedInView exposing (LoggedInView) import Model.Translations exposing (getParamMessage, getMessage) +import Model.Action exposing (..) +import Model.Action.LoggedInAction exposing (..) +import Model.Action.AccountAction exposing (..) +import Model.Communication as Communication + +import Model.View.LoggedInView exposing (LoggedInView) import Model.View.LoggedIn.Account exposing (..) import View.Expand exposing (..) @@ -27,8 +28,8 @@ import View.Events exposing (onSubmitPrevDefault) import Utils.Either exposing (toMaybeError) -account : Model -> LoggedInView -> Html -account model loggedInView = +account : Address Action -> Model -> LoggedInView -> Html +account address model loggedInView = let account = loggedInView.account in div [ classList @@ -36,17 +37,17 @@ account model loggedInView = , ("detail", account.visibleDetail) ] ] - [ exceedingPayers model loggedInView + [ exceedingPayers address model loggedInView , if account.visibleDetail - then income model account + then income address model account else text "" ] -exceedingPayers : Model -> LoggedInView -> Html -exceedingPayers model loggedInView = +exceedingPayers : Address Action -> Model -> LoggedInView -> Html +exceedingPayers address model loggedInView = button [ class "header" - , onClick actions.address (UpdateLoggedIn << UpdateAccount <| ToggleDetail) + , onClick address (UpdateLoggedIn << UpdateAccount <| ToggleDetail) ] ( (List.map (exceedingPayer model loggedInView) (getOrderedExceedingPayers model.currentTime loggedInView.account.payers)) ++ [ expand ExpandDown loggedInView.account.visibleDetail ] @@ -68,16 +69,16 @@ exceedingPayer model loggedInView payer = [ text ("+ " ++ (price model payer.amount)) ] ] -income : Model -> Account -> Html -income model account = +income : Address Action -> Model -> Account -> Html +income address model account = case account.incomeEdition of - Just edition -> - incomeEdition model account edition Nothing -> - incomeRead model account + incomeRead address model account + Just edition -> + incomeEdition address model account edition -incomeRead : Model -> Account -> Html -incomeRead model account = +incomeRead : Address Action -> Model -> Account -> Html +incomeRead address model account = div [ class "income" ] [ ( case getCurrentIncome account of @@ -86,17 +87,17 @@ incomeRead model account = Just income -> text (getParamMessage [price model income] "Income" model.translations) ) - , toggleIncomeEdition "editIncomeEdition" (getMessage "Edit" model.translations) + , toggleIncomeEdition address "editIncomeEdition" (getMessage "Edit" model.translations) ] -incomeEdition : Model -> Account -> IncomeEdition -> Html -incomeEdition model account edition = +incomeEdition : Address Action -> Model -> Account -> IncomeEdition -> Html +incomeEdition address model account edition = H.form [ case validateIncome edition.income model.translations of Ok validatedAmount -> - onSubmitPrevDefault serverCommunications.address (SC.SetIncome model.currentTime validatedAmount) + onSubmitPrevDefault address (ServerCommunication <| Communication.SetIncome model.currentTime validatedAmount) Err error -> - onSubmitPrevDefault actions.address (UpdateLoggedIn << UpdateAccount << UpdateEditionError <| error) + onSubmitPrevDefault address (UpdateLoggedIn << UpdateAccount << UpdateEditionError <| error) , class "income" ] [ label @@ -105,7 +106,7 @@ incomeEdition model account edition = , input [ id "incomeInput" , value edition.income - , on "input" targetValue (Signal.message actions.address << UpdateLoggedIn << UpdateAccount << UpdateIncomeEdition) + , on "input" targetValue (Signal.message address << UpdateLoggedIn << UpdateAccount << UpdateIncomeEdition) , maxlength 10 ] [] @@ -114,17 +115,17 @@ incomeEdition model account edition = , class "validateIncomeEdition" ] [ text (getMessage "Validate" model.translations) ] - , toggleIncomeEdition "undoIncomeEdition" (getMessage "Undo" model.translations) + , toggleIncomeEdition address "undoIncomeEdition" (getMessage "Undo" model.translations) , case edition.error of Just error -> div [ class "error" ] [ text error ] Nothing -> text "" ] -toggleIncomeEdition : String -> String -> Html -toggleIncomeEdition className name = +toggleIncomeEdition : Address Action -> String -> String -> Html +toggleIncomeEdition address className name = button [ type' "button" , class className - , onClick actions.address (UpdateLoggedIn << UpdateAccount <| ToggleIncomeEdition) + , onClick address (UpdateLoggedIn << UpdateAccount <| ToggleIncomeEdition) ] [ text name ] -- cgit v1.2.3