blob: 96686b85a32cf5c3d0525670e009d1b6de4292ca (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
|
module Dialog.AddPayment.View exposing
( view
)
import Html exposing (..)
import Html.Attributes exposing (..)
import Html.Events exposing (..)
import Html.App as Html
import Task
import Date
import Form exposing (Form)
import Utils.Form as Form
import Dialog
import View.Form as Form
import View.Events exposing (onSubmitPrevDefault)
import Msg exposing (Msg)
import LoggedIn.Msg as LoggedInMsg
import LoggedIn.Home.Msg as HomeMsg
import Model.Translations exposing (getMessage)
import Model.Payment as Payment exposing (Frequency(..))
import Model.View exposing (View(LoggedInView))
import Dialog.Model as DialogModel
import Dialog.Msg as DialogMsg
import LoggedData exposing (LoggedData)
import LoggedIn.Home.Model as HomeModel
view : LoggedData -> Frequency -> Html Msg
view loggedData frequency =
let dialogConfig =
{ className = "paymentDialog"
, title = getMessage "AddPayment" loggedData.translations
, body = \model -> addPaymentForm loggedData model.addPayment
, confirm = getMessage "Confirm" loggedData.translations
, confirmMsg = \model -> (
case Form.getOutput model.addPayment of
Just data ->
Ok (Msg.UpdateLoggedIn <| LoggedInMsg.AddPayment data.name data.cost data.date data.frequency)
Nothing ->
Err (Msg.Dialog <| Dialog.UpdateModel <| DialogMsg.AddPaymentMsg <| Form.Submit)
)
, undo = getMessage "Undo" loggedData.translations
}
currentDate = Date.fromTime loggedData.currentTime
in button
[ class "addPayment"
, onClick (Msg.Dialog <| Dialog.OpenWithUpdate dialogConfig (DialogMsg.AddPaymentMsg <| Form.Reset (DialogModel.addPaymentInitial loggedData.translations currentDate frequency)))
]
[ text (getMessage "AddPayment" loggedData.translations) ]
addPaymentForm : LoggedData -> Form String DialogModel.AddPayment -> Html Msg
addPaymentForm loggedData addPayment =
Html.map (Msg.Dialog << Dialog.UpdateModel << DialogMsg.AddPaymentMsg) <|
Html.form
[ class "addPayment"
, onSubmitPrevDefault Form.NoOp
]
[ Form.textInput loggedData.translations addPayment "payment" "name"
, Form.textInput loggedData.translations addPayment "payment" "cost"
, if Form.frequency addPayment == Punctual
then Form.textInput loggedData.translations addPayment "payment" "date"
else text ""
, Form.radioInputs loggedData.translations addPayment "payment" "frequency" [ toString Punctual, toString Monthly ]
]
|