From 8cd63a64abafe21378c35c2489d49f24c9ece3c9 Mon Sep 17 00:00:00 2001 From: Joris Date: Mon, 4 Apr 2016 01:27:36 +0200 Subject: Add income list CRUD in user page --- src/client/elm/LoggedIn/User/Model.elm | 46 ++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 src/client/elm/LoggedIn/User/Model.elm (limited to 'src/client/elm/LoggedIn/User/Model.elm') diff --git a/src/client/elm/LoggedIn/User/Model.elm b/src/client/elm/LoggedIn/User/Model.elm new file mode 100644 index 0000000..4f96a80 --- /dev/null +++ b/src/client/elm/LoggedIn/User/Model.elm @@ -0,0 +1,46 @@ +module LoggedIn.User.Model + ( Model + , AddIncome + , init + ) where + +import String exposing (toInt, split) +import Date exposing (Date) +import Date.Utils exposing (dateFromFields) +import Utils.Date exposing (numToMonth) + +import Form exposing (Form) +import Form.Validate as Validate exposing (..) +import Form.Error exposing (Error(InvalidString)) + +type alias Model = + { addIncome : Form () AddIncome + } + +type alias AddIncome = + { creation : Date + , amount : Int + } + +init : Model +init = + { addIncome = Form.initial [] validate + } + +validate : Validation () AddIncome +validate = + form2 AddIncome + (get "creation" dateValidation) + (get "amount" (int `andThen` (minInt 1))) + +dateValidation : Validation () Date +dateValidation = + customValidation string (\str -> + case split "/" str of + [day, month, year] -> + case (toInt day, toInt month, toInt year) of + (Ok dayNum, Ok monthNum, Ok yearNum) -> + Ok (dateFromFields yearNum (numToMonth monthNum) dayNum 0 0 0 0) + _ -> Err InvalidString + _ -> Err InvalidString + ) -- cgit v1.2.3