diff options
author | Joris | 2015-09-06 16:46:59 +0200 |
---|---|---|
committer | Joris | 2015-09-06 16:46:59 +0200 |
commit | 3853811450d4fe801da996eb48825049c3541030 (patch) | |
tree | b483c6152f55b6fe87d23108d2d0346a593e51ac /src/client/Model/View/LoggedIn/Add.elm | |
parent | 0b6f0fa29075178b45cb17d2932003ab4b342280 (diff) |
Renaming PaymentView to LoggedInView
Diffstat (limited to 'src/client/Model/View/LoggedIn/Add.elm')
-rw-r--r-- | src/client/Model/View/LoggedIn/Add.elm | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/src/client/Model/View/LoggedIn/Add.elm b/src/client/Model/View/LoggedIn/Add.elm new file mode 100644 index 0000000..abd8a4d --- /dev/null +++ b/src/client/Model/View/LoggedIn/Add.elm @@ -0,0 +1,43 @@ +module Model.View.LoggedIn.Add + ( AddPayment + , Frequency(..) + , initAddPayment + , validateName + , validateCost + ) where + +import Result as Result exposing (Result(..)) + +import Utils.Validation exposing (..) + +import Model.Translations exposing (..) + +type alias AddPayment = + { name : String + , nameError : Maybe String + , cost : String + , costError : Maybe String + , frequency : Frequency + } + +initAddPayment : Frequency -> AddPayment +initAddPayment frequency = + { name = "" + , nameError = Nothing + , cost = "" + , costError = Nothing + , frequency = frequency + } + +validateName : String -> Translations -> Result String String +validateName name translations = + name + |> validateNonEmpty (getMessage "CategoryRequired" translations) + +validateCost : String -> Translations -> Result String Int +validateCost cost translations = + cost + |> validateNonEmpty (getMessage "CostRequired" translations) + |> flip Result.andThen (validateNumber (getMessage "CostMustBeNumber" translations) (\number -> number >= 0)) + +type Frequency = Punctual | Monthly |