diff options
author | Joris | 2016-06-26 12:31:24 +0200 |
---|---|---|
committer | Joris | 2016-06-26 12:31:24 +0200 |
commit | 9ec84e3a20c767f6525639f58cd22715e302b88d (patch) | |
tree | a080552859180707472c1a289080857c0a54fc06 /src/client/elm/Dialog | |
parent | 5cb36652ccf07c9e0995ebc421a837ad7d258469 (diff) |
Add an editable date field for punctual payment creation
Diffstat (limited to 'src/client/elm/Dialog')
-rw-r--r-- | src/client/elm/Dialog/AddPayment/View.elm | 10 | ||||
-rw-r--r-- | src/client/elm/Dialog/Model.elm | 16 |
2 files changed, 21 insertions, 5 deletions
diff --git a/src/client/elm/Dialog/AddPayment/View.elm b/src/client/elm/Dialog/AddPayment/View.elm index 79381dd..96686b8 100644 --- a/src/client/elm/Dialog/AddPayment/View.elm +++ b/src/client/elm/Dialog/AddPayment/View.elm @@ -7,8 +7,10 @@ import Html.Attributes exposing (..) import Html.Events exposing (..) import Html.App as Html import Task +import Date import Form exposing (Form) +import Utils.Form as Form import Dialog @@ -39,15 +41,16 @@ view loggedData frequency = , confirmMsg = \model -> ( case Form.getOutput model.addPayment of Just data -> - Ok (Msg.UpdateLoggedIn <| LoggedInMsg.AddPayment data.name data.cost data.frequency) + Ok (Msg.UpdateLoggedIn <| LoggedInMsg.AddPayment data.name data.cost data.date data.frequency) Nothing -> Err (Msg.Dialog <| Dialog.UpdateModel <| DialogMsg.AddPaymentMsg <| Form.Submit) ) , undo = getMessage "Undo" loggedData.translations } + currentDate = Date.fromTime loggedData.currentTime in button [ class "addPayment" - , onClick (Msg.Dialog <| Dialog.OpenWithUpdate dialogConfig (DialogMsg.AddPaymentMsg <| Form.Reset (DialogModel.addPaymentInitial frequency))) + , onClick (Msg.Dialog <| Dialog.OpenWithUpdate dialogConfig (DialogMsg.AddPaymentMsg <| Form.Reset (DialogModel.addPaymentInitial loggedData.translations currentDate frequency))) ] [ text (getMessage "AddPayment" loggedData.translations) ] @@ -60,5 +63,8 @@ addPaymentForm loggedData addPayment = ] [ Form.textInput loggedData.translations addPayment "payment" "name" , Form.textInput loggedData.translations addPayment "payment" "cost" + , if Form.frequency addPayment == Punctual + then Form.textInput loggedData.translations addPayment "payment" "date" + else text "" , Form.radioInputs loggedData.translations addPayment "payment" "frequency" [ toString Punctual, toString Monthly ] ] diff --git a/src/client/elm/Dialog/Model.elm b/src/client/elm/Dialog/Model.elm index 9bd6a09..2ac4591 100644 --- a/src/client/elm/Dialog/Model.elm +++ b/src/client/elm/Dialog/Model.elm @@ -5,11 +5,16 @@ module Dialog.Model exposing , addPaymentInitial ) +import Date exposing (Date) +import View.Date as Date + import Form exposing (Form) import Form.Field as Field exposing (Field) import Form.Validate as Validate exposing (Validation) +import Validation import Model.Payment as Payment +import Model.Translations exposing (Translations) type alias Model = { addPayment : Form String AddPayment @@ -18,6 +23,7 @@ type alias Model = type alias AddPayment = { name : String , cost : Int + , date : Date , frequency : Payment.Frequency } @@ -26,12 +32,16 @@ init = { addPayment = Form.initial [] addPaymentValidation } -addPaymentInitial : Payment.Frequency -> List (String, Field) -addPaymentInitial frequency = [ ("frequency", Field.Radio (toString frequency)) ] +addPaymentInitial : Translations -> Date -> Payment.Frequency -> List (String, Field) +addPaymentInitial translations date frequency = + [ ("date", Field.Text (Date.shortView date translations)) + , ("frequency", Field.Radio (toString frequency)) + ] addPaymentValidation : Validation String AddPayment addPaymentValidation = - Validate.form3 AddPayment + Validate.form4 AddPayment (Validate.get "name" (Validate.string `Validate.andThen` (Validate.nonEmpty))) (Validate.get "cost" (Validate.int `Validate.andThen` (Validate.minInt 1))) + (Validate.get "date" Validation.date) (Validate.get "frequency" Payment.validateFrequency) |