module Dialog.Model exposing ( Model , AddPayment , init , 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 } type alias AddPayment = { name : String , cost : Int , date : Date , frequency : Payment.Frequency } init : Model init = { addPayment = Form.initial [] addPaymentValidation } 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.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)