diff options
author | Joris | 2016-06-26 17:30:03 +0200 |
---|---|---|
committer | Joris | 2016-06-26 17:30:03 +0200 |
commit | 885dfd7708e338a3220c85b7f22a3ac267aad3f7 (patch) | |
tree | ff259354eb9fd97fc0bab2775296830dcced5693 /src/client/elm/Dialog/AddPaymentButton | |
parent | cfade71c343eb29c8873011f5878a39aed8257b2 (diff) |
Add the clone functionality on payments
Diffstat (limited to 'src/client/elm/Dialog/AddPaymentButton')
-rw-r--r-- | src/client/elm/Dialog/AddPaymentButton/View.elm | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/src/client/elm/Dialog/AddPaymentButton/View.elm b/src/client/elm/Dialog/AddPaymentButton/View.elm new file mode 100644 index 0000000..8014571 --- /dev/null +++ b/src/client/elm/Dialog/AddPaymentButton/View.elm @@ -0,0 +1,72 @@ +module Dialog.AddPaymentButton.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 Form.Field as Field exposing (Field) +import Utils.Form as 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 -> List (String, Field) -> Html Msg -> Html Msg +view loggedData initialForm content = + let dialogConfig = + { className = "paymentDialog" + , title = getMessage "AddPayment" loggedData.translations + , body = \model -> addPaymentForm loggedData model.addPayment + , confirm = getMessage "Confirm" loggedData.translations + , confirmMsg = submitForm << .addPayment + , undo = getMessage "Undo" loggedData.translations + } + in button + [ class "addPayment" + , onClick (Msg.Dialog <| Dialog.OpenWithUpdate dialogConfig (DialogMsg.AddPaymentMsg <| Form.Reset initialForm)) + ] + [ content ] + +addPaymentForm : LoggedData -> Form String DialogModel.AddPayment -> Html Msg +addPaymentForm loggedData addPayment = + let htmlMap = Html.map (Msg.Dialog << Dialog.Update << DialogMsg.AddPaymentMsg) + in Html.form + [ class "addPayment" + , onSubmitPrevDefault Msg.NoOp + ] + [ htmlMap <| Form.textInput loggedData.translations addPayment "payment" "name" + , htmlMap <| Form.textInput loggedData.translations addPayment "payment" "cost" + , if Form.frequency addPayment == Punctual + then htmlMap <| Form.textInput loggedData.translations addPayment "payment" "date" + else text "" + , htmlMap <| Form.radioInputs loggedData.translations addPayment "payment" "frequency" [ toString Punctual, toString Monthly ] + , Form.hiddenSubmit (submitForm addPayment) + ] + +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 + Nothing -> + Msg.Dialog <| Dialog.Update <| DialogMsg.AddPaymentMsg <| Form.Submit |