aboutsummaryrefslogtreecommitdiff
path: root/src/client/elm/Dialog/AddPayment
diff options
context:
space:
mode:
Diffstat (limited to 'src/client/elm/Dialog/AddPayment')
-rw-r--r--src/client/elm/Dialog/AddPayment/View.elm64
1 files changed, 64 insertions, 0 deletions
diff --git a/src/client/elm/Dialog/AddPayment/View.elm b/src/client/elm/Dialog/AddPayment/View.elm
new file mode 100644
index 0000000..8915b1d
--- /dev/null
+++ b/src/client/elm/Dialog/AddPayment/View.elm
@@ -0,0 +1,64 @@
+module Dialog.AddPayment.View exposing
+ ( view
+ )
+
+import Html exposing (..)
+import Html.Attributes exposing (..)
+import Html.Events exposing (..)
+import Html.App as Html
+import Task
+
+import Form exposing (Form)
+
+import Dialog
+
+import View.Form as Form
+import View.Events exposing (onSubmitPrevDefault)
+
+import Msg exposing (Msg)
+import LoggedIn.Msg as LoggedInMsg
+import LoggedIn.Home.Msg as HomeMsg
+
+import Model.Translations exposing (getMessage)
+import Model.Payment as Payment exposing (Frequency(..))
+import Model.View exposing (View(LoggedInView))
+
+import Dialog.Model as DialogModel
+import Dialog.Msg as DialogMsg
+
+import LoggedData exposing (LoggedData)
+import LoggedIn.Home.Model as HomeModel
+
+view : LoggedData -> Frequency -> Html Msg
+view loggedData frequency =
+ let dialogConfig =
+ { className = "paymentDialog"
+ , title = getMessage "AddPayment" loggedData.translations
+ , body = \model -> addPaymentForm loggedData model.addPayment
+ , confirm = getMessage "Confirm" loggedData.translations
+ , confirmMsg = \model -> (
+ case Form.getOutput model.addPayment of
+ Just data ->
+ Ok (Msg.UpdateLoggedIn <| LoggedInMsg.AddPayment data.name data.cost data.frequency)
+ Nothing ->
+ Err (Msg.Dialog <| Dialog.UpdateModel <| DialogMsg.AddPaymentMsg <| Form.Submit)
+ )
+ , undo = getMessage "Undo" loggedData.translations
+ }
+ in button
+ [ class "addPayment"
+ , onClick (Msg.Dialog <| Dialog.OpenWithUpdate dialogConfig (DialogMsg.AddPaymentMsg <| Form.Reset (DialogModel.addPaymentInitial frequency)))
+ ]
+ [ text (getMessage "AddPayment" loggedData.translations) ]
+
+addPaymentForm : LoggedData -> Form String DialogModel.AddPayment -> Html Msg
+addPaymentForm loggedData addPayment =
+ let htmlMap = Html.map (Msg.Dialog << Dialog.UpdateModel << DialogMsg.AddPaymentMsg)
+ in Html.form
+ [ class "addPayment"
+ , onSubmitPrevDefault Msg.NoOp
+ ]
+ [ Form.textInput loggedData.translations addPayment htmlMap "payment" "name"
+ , Form.textInput loggedData.translations addPayment htmlMap "payment" "cost"
+ , Form.radioInputs loggedData.translations addPayment htmlMap "payment" "frequency" [ toString Punctual, toString Monthly ]
+ ]