diff options
Diffstat (limited to 'src/client/elm/Dialog')
-rw-r--r-- | src/client/elm/Dialog/AddPaymentButton/View.elm | 16 | ||||
-rw-r--r-- | src/client/elm/Dialog/Model.elm | 18 |
2 files changed, 25 insertions, 9 deletions
diff --git a/src/client/elm/Dialog/AddPaymentButton/View.elm b/src/client/elm/Dialog/AddPaymentButton/View.elm index 8014571..5da380c 100644 --- a/src/client/elm/Dialog/AddPaymentButton/View.elm +++ b/src/client/elm/Dialog/AddPaymentButton/View.elm @@ -31,11 +31,11 @@ import Dialog.Msg as DialogMsg import LoggedData exposing (LoggedData) import LoggedIn.Home.Model as HomeModel -view : LoggedData -> List (String, Field) -> Html Msg -> Html Msg -view loggedData initialForm content = +view : LoggedData -> List (String, Field) -> String -> Html Msg -> Html Msg +view loggedData initialForm title buttonContent = let dialogConfig = { className = "paymentDialog" - , title = getMessage "AddPayment" loggedData.translations + , title = getMessage title loggedData.translations , body = \model -> addPaymentForm loggedData model.addPayment , confirm = getMessage "Confirm" loggedData.translations , confirmMsg = submitForm << .addPayment @@ -45,7 +45,7 @@ view loggedData initialForm content = [ class "addPayment" , onClick (Msg.Dialog <| Dialog.OpenWithUpdate dialogConfig (DialogMsg.AddPaymentMsg <| Form.Reset initialForm)) ] - [ content ] + [ buttonContent ] addPaymentForm : LoggedData -> Form String DialogModel.AddPayment -> Html Msg addPaymentForm loggedData addPayment = @@ -56,7 +56,7 @@ addPaymentForm loggedData addPayment = ] [ htmlMap <| Form.textInput loggedData.translations addPayment "payment" "name" , htmlMap <| Form.textInput loggedData.translations addPayment "payment" "cost" - , if Form.frequency addPayment == Punctual + , if (Maybe.map .frequency <| Form.getOutput addPayment) == Just Punctual then htmlMap <| Form.textInput loggedData.translations addPayment "payment" "date" else text "" , htmlMap <| Form.radioInputs loggedData.translations addPayment "payment" "frequency" [ toString Punctual, toString Monthly ] @@ -67,6 +67,10 @@ submitForm : Form String DialogModel.AddPayment -> Msg submitForm addPayment = case Form.getOutput addPayment of Just data -> - Msg.Dialog <| Dialog.UpdateAndClose <| Msg.UpdateLoggedIn <| LoggedInMsg.AddPayment data.name data.cost data.date data.frequency + case data.id of + Just paymentId -> + Msg.Dialog <| Dialog.UpdateAndClose <| Msg.UpdateLoggedIn <| LoggedInMsg.EditPayment paymentId data.name data.cost data.date data.frequency + Nothing -> + Msg.Dialog <| Dialog.UpdateAndClose <| Msg.UpdateLoggedIn <| LoggedInMsg.CreatePayment data.name data.cost data.date data.frequency Nothing -> Msg.Dialog <| Dialog.Update <| DialogMsg.AddPaymentMsg <| Form.Submit diff --git a/src/client/elm/Dialog/Model.elm b/src/client/elm/Dialog/Model.elm index 6256fea..b49d8f1 100644 --- a/src/client/elm/Dialog/Model.elm +++ b/src/client/elm/Dialog/Model.elm @@ -4,6 +4,7 @@ module Dialog.Model exposing , init , addPaymentInitial , clonePaymentInitial + , editPaymentInitial ) import Date exposing (Date) @@ -14,7 +15,7 @@ import Form.Field as Field exposing (Field) import Form.Validate as Validate exposing (Validation) import Validation -import Model.Payment as Payment exposing (Payment, Frequency) +import Model.Payment as Payment exposing (Payment, Frequency, PaymentId) import Model.Translations exposing (Translations) type alias Model = @@ -22,7 +23,8 @@ type alias Model = } type alias AddPayment = - { name : String + { id : Maybe PaymentId + , name : String , cost : Int , date : Date , frequency : Frequency @@ -47,9 +49,19 @@ clonePaymentInitial translations date payment = , ("frequency", Field.Radio (toString payment.frequency)) ] +editPaymentInitial : Translations -> Payment -> List (String, Field) +editPaymentInitial translations payment = + [ ("id", Field.Text (toString payment.id)) + , ("name", Field.Text payment.name) + , ("cost", Field.Text (toString payment.cost)) + , ("date", Field.Text (Date.shortView payment.date translations)) + , ("frequency", Field.Radio (toString payment.frequency)) + ] + addPaymentValidation : Validation String AddPayment addPaymentValidation = - Validate.form4 AddPayment + Validate.form5 AddPayment + (Validate.get "id" (Validate.maybe Validate.int)) (Validate.get "name" (Validate.string `Validate.andThen` (Validate.nonEmpty))) (Validate.get "cost" (Validate.int `Validate.andThen` (Validate.minInt 1))) (Validate.get "date" Validation.date) |