diff options
author | Joris | 2017-03-24 09:21:06 +0000 |
---|---|---|
committer | Joris | 2017-03-24 09:21:06 +0000 |
commit | c0ac16a713c4e53cf6af8e72a6d5f6b8ac5d6456 (patch) | |
tree | 8a438430cee7411259fc395d8f3898488e85d750 /src/client/elm/Dialog/Update.elm | |
parent | 293eb8295162bf0a038f488237db9c9d1316c04d (diff) | |
parent | cfca18262c1ff48dcb683ddab7d03cf8e55573ff (diff) |
Merge branch 'features/categories' into 'master'
Features/categories
See merge request !1
Diffstat (limited to 'src/client/elm/Dialog/Update.elm')
-rw-r--r-- | src/client/elm/Dialog/Update.elm | 51 |
1 files changed, 47 insertions, 4 deletions
diff --git a/src/client/elm/Dialog/Update.elm b/src/client/elm/Dialog/Update.elm index d69082d..3915548 100644 --- a/src/client/elm/Dialog/Update.elm +++ b/src/client/elm/Dialog/Update.elm @@ -2,10 +2,19 @@ module Dialog.Update exposing ( update ) +import Dom exposing (Id) import Form exposing (Form) +import Form.Field as Field +import Task -import Dialog.Msg as Dialog +import Dialog.AddCategory.Model as AddCategory +import Dialog.AddIncome.Model as AddIncome +import Dialog.AddPayment.Model as AddPayment import Dialog.Model as Dialog +import Dialog.Msg as Dialog + +import Model.Category exposing (Categories) +import Model.PaymentCategory as PaymentCategory exposing (PaymentCategories) update : Dialog.Msg -> Dialog.Model -> (Dialog.Model, Cmd Dialog.Msg) update msg model = @@ -16,16 +25,50 @@ update msg model = , Cmd.none ) - Dialog.AddPaymentMsg formMsg -> + Dialog.Init inputId dialogMsg -> + update dialogMsg model + |> Tuple.mapSecond (\cmd -> Cmd.batch [cmd, inputFocus inputId]) + + Dialog.AddPaymentMsg categories paymentCategories formMsg -> ( { model - | addPayment = Form.update formMsg model.addPayment + | addPayment = + Form.update (AddPayment.validation categories) formMsg model.addPayment + |> updateCategory categories paymentCategories formMsg } , Cmd.none ) Dialog.AddIncomeMsg formMsg -> ( { model - | addIncome = Form.update formMsg model.addIncome + | addIncome = Form.update AddIncome.validation formMsg model.addIncome } , Cmd.none ) + + Dialog.AddCategoryMsg formMsg -> + ( { model + | addCategory = Form.update AddCategory.validation formMsg model.addCategory + } + , Cmd.none + ) + +inputFocus : Id -> Cmd Dialog.Msg +inputFocus id = + Dom.focus id + |> Task.map (always Dialog.NoOp) + |> Task.onError (\_ -> Task.succeed Dialog.NoOp) + |> Task.perform (always Dialog.NoOp) + +updateCategory : Categories -> PaymentCategories -> Form.Msg -> (Form String AddPayment.Model -> Form String AddPayment.Model) +updateCategory categories paymentCategories formMsg = + case formMsg of + Form.Input "name" Form.Text (Field.String paymentName) -> + case PaymentCategory.search paymentName paymentCategories of + Just category -> + Form.update + (AddPayment.validation categories) + (Form.Input "category" Form.Text (Field.String <| toString category)) + Nothing -> + identity + _ -> + identity |