diff options
Diffstat (limited to 'src/client/elm/Dialog/AddPaymentButton')
-rw-r--r-- | src/client/elm/Dialog/AddPaymentButton/View.elm | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/src/client/elm/Dialog/AddPaymentButton/View.elm b/src/client/elm/Dialog/AddPaymentButton/View.elm index 8014571..5da380c 100644 --- a/src/client/elm/Dialog/AddPaymentButton/View.elm +++ b/src/client/elm/Dialog/AddPaymentButton/View.elm @@ -31,11 +31,11 @@ import Dialog.Msg as DialogMsg import LoggedData exposing (LoggedData) import LoggedIn.Home.Model as HomeModel -view : LoggedData -> List (String, Field) -> Html Msg -> Html Msg -view loggedData initialForm content = +view : LoggedData -> List (String, Field) -> String -> Html Msg -> Html Msg +view loggedData initialForm title buttonContent = let dialogConfig = { className = "paymentDialog" - , title = getMessage "AddPayment" loggedData.translations + , title = getMessage title loggedData.translations , body = \model -> addPaymentForm loggedData model.addPayment , confirm = getMessage "Confirm" loggedData.translations , confirmMsg = submitForm << .addPayment @@ -45,7 +45,7 @@ view loggedData initialForm content = [ class "addPayment" , onClick (Msg.Dialog <| Dialog.OpenWithUpdate dialogConfig (DialogMsg.AddPaymentMsg <| Form.Reset initialForm)) ] - [ content ] + [ buttonContent ] addPaymentForm : LoggedData -> Form String DialogModel.AddPayment -> Html Msg addPaymentForm loggedData addPayment = @@ -56,7 +56,7 @@ addPaymentForm loggedData addPayment = ] [ htmlMap <| Form.textInput loggedData.translations addPayment "payment" "name" , htmlMap <| Form.textInput loggedData.translations addPayment "payment" "cost" - , if Form.frequency addPayment == Punctual + , if (Maybe.map .frequency <| Form.getOutput addPayment) == Just Punctual then htmlMap <| Form.textInput loggedData.translations addPayment "payment" "date" else text "" , htmlMap <| Form.radioInputs loggedData.translations addPayment "payment" "frequency" [ toString Punctual, toString Monthly ] @@ -67,6 +67,10 @@ submitForm : Form String DialogModel.AddPayment -> Msg submitForm addPayment = case Form.getOutput addPayment of Just data -> - Msg.Dialog <| Dialog.UpdateAndClose <| Msg.UpdateLoggedIn <| LoggedInMsg.AddPayment data.name data.cost data.date data.frequency + case data.id of + Just paymentId -> + Msg.Dialog <| Dialog.UpdateAndClose <| Msg.UpdateLoggedIn <| LoggedInMsg.EditPayment paymentId data.name data.cost data.date data.frequency + Nothing -> + Msg.Dialog <| Dialog.UpdateAndClose <| Msg.UpdateLoggedIn <| LoggedInMsg.CreatePayment data.name data.cost data.date data.frequency Nothing -> Msg.Dialog <| Dialog.Update <| DialogMsg.AddPaymentMsg <| Form.Submit |