diff options
author | Joris | 2016-08-08 20:58:17 +0200 |
---|---|---|
committer | Joris | 2016-08-08 20:58:17 +0200 |
commit | 8816cf758119a6a2073e561c8df297a833630986 (patch) | |
tree | 20e63f3c0de15945b818a6d7a78359f9134b5e82 /src/client/elm/Dialog/AddIncome/Model.elm | |
parent | b54d8e45fc8784d8fa6eaa03f58536b7a19cf70b (diff) |
Show incomes in a table and update like payments are updated
Diffstat (limited to 'src/client/elm/Dialog/AddIncome/Model.elm')
-rw-r--r-- | src/client/elm/Dialog/AddIncome/Model.elm | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/src/client/elm/Dialog/AddIncome/Model.elm b/src/client/elm/Dialog/AddIncome/Model.elm new file mode 100644 index 0000000..664557e --- /dev/null +++ b/src/client/elm/Dialog/AddIncome/Model.elm @@ -0,0 +1,52 @@ +module Dialog.AddIncome.Model exposing + ( Model + , init + , initialAdd + , initialClone + , initialEdit + ) + +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.Translations exposing (Translations) +import Model.Income exposing (Income, IncomeId) + +type alias Model = + { id : Maybe IncomeId + , amount : Int + , date : Date + } + +init : Form String Model +init = Form.initial [] validate + +initialAdd : Translations -> Date -> List (String, Field) +initialAdd translations date = + [ ("date", Field.Text (Date.shortView date translations)) + ] + +initialClone : Translations -> Date -> Income -> List (String, Field) +initialClone translations date income = + [ ("amount", Field.Text (toString income.amount)) + , ("date", Field.Text (Date.shortView (Date.fromTime income.time) translations)) + ] + +initialEdit : Translations -> IncomeId -> Income -> List (String, Field) +initialEdit translations incomeId income = + [ ("id", Field.Text (toString incomeId)) + , ("amount", Field.Text (toString income.amount)) + , ("date", Field.Text (Date.shortView (Date.fromTime income.time) translations)) + ] + +validate : Validation String Model +validate = + Validate.form3 Model + (Validate.get "id" (Validate.maybe Validate.int)) + (Validate.get "amount" (Validate.int `Validate.andThen` (Validate.minInt 1))) + (Validate.get "date" Validation.date) |