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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
|
module LoggedIn.Home.Account.View
( view
) where
import List
import Signal
import Html exposing (..)
import Html as H exposing (..)
import Html.Attributes exposing (..)
import Html.Events exposing (..)
import LoggedData exposing (LoggedData)
import LoggedIn.Action as LoggedInAction
import LoggedIn.Home.Action as HomeAction
import LoggedIn.Home.Model as HomeModel
import LoggedIn.Home.Model.Payer exposing (..)
import LoggedIn.Home.View.Price exposing (price)
import LoggedIn.Home.View.Expand exposing (..)
import LoggedIn.Home.Account.Action as AccountAction
import LoggedIn.Home.Account.Model as AccountModel
import Model exposing (Model)
import Model.User exposing (getUserName)
import Model.Translations exposing (getParamMessage, getMessage)
import Action
import Mailbox
import View.Events exposing (onSubmitPrevDefault)
import Utils.Either exposing (toMaybeError)
view : LoggedData -> HomeModel.Model -> Html
view loggedData homeModel =
let account = homeModel.account
in div
[ classList
[ ("account", True)
, ("detail", account.visibleDetail)
]
]
[ exceedingPayers loggedData homeModel
, if account.visibleDetail
then income loggedData account
else text ""
]
exceedingPayers : LoggedData -> HomeModel.Model -> Html
exceedingPayers loggedData homeModel =
button
[ class "header"
, onClick Mailbox.address (Action.UpdateLoggedIn << LoggedInAction.HomeAction << HomeAction.UpdateAccount <| AccountAction.ToggleDetail)
]
( (List.map (exceedingPayer loggedData homeModel) (getOrderedExceedingPayers loggedData.currentTime loggedData.users loggedData.incomes loggedData.payments))
++ [ expand ExpandDown homeModel.account.visibleDetail ]
)
exceedingPayer : LoggedData -> HomeModel.Model -> ExceedingPayer -> Html
exceedingPayer loggedData homeModel payer =
div
[ class "exceedingPayer" ]
[ span
[ class "userName" ]
[ payer.userId
|> getUserName loggedData.users
|> Maybe.withDefault "−"
|> text
]
, span
[ class "amount" ]
[ text ("+ " ++ (price loggedData.conf payer.amount)) ]
]
income : LoggedData -> AccountModel.Model -> Html
income loggedData account =
case account.incomeEdition of
Nothing ->
incomeRead loggedData account
Just edition ->
incomeEdition loggedData account edition
incomeRead : LoggedData -> AccountModel.Model -> Html
incomeRead loggedData account =
div
[ class "income" ]
[ ( case AccountModel.getCurrentIncome loggedData.incomes loggedData.me account of
Nothing ->
text (getMessage "NoIncome" loggedData.translations)
Just income ->
text (getParamMessage [price loggedData.conf income] "Income" loggedData.translations)
)
, toggleIncomeEdition loggedData "editIncomeEdition" (getMessage "Edit" loggedData.translations)
]
incomeEdition : LoggedData -> AccountModel.Model -> AccountModel.IncomeEdition -> Html
incomeEdition loggedData account edition =
H.form
[ case AccountModel.validateIncome edition.income loggedData.translations of
Ok validatedAmount ->
onSubmitPrevDefault Mailbox.address (Action.UpdateLoggedIn <| LoggedInAction.UpdateIncome validatedAmount)
Err error ->
onSubmitPrevDefault Mailbox.address (Action.UpdateLoggedIn << LoggedInAction.HomeAction << HomeAction.UpdateAccount << AccountAction.UpdateEditionError <| error)
, class "income"
]
[ label
[ for "incomeInput" ]
[ text (getMessage "NewIncome" loggedData.translations) ]
, input
[ id "incomeInput"
, value edition.income
, on "input" targetValue (Signal.message Mailbox.address << Action.UpdateLoggedIn << LoggedInAction.HomeAction << HomeAction.UpdateAccount << AccountAction.UpdateIncomeEdition)
, maxlength 10
]
[]
, button
[ type' "submit"
, class "validateIncomeEdition"
]
[ text (getMessage "Validate" loggedData.translations) ]
, toggleIncomeEdition loggedData "undoIncomeEdition" (getMessage "Undo" loggedData.translations)
, case edition.error of
Just error -> div [ class "error" ] [ text error ]
Nothing -> text ""
]
toggleIncomeEdition : LoggedData -> String -> String -> Html
toggleIncomeEdition loggedData className name =
button
[ type' "button"
, class className
, onClick Mailbox.address (Action.UpdateLoggedIn << LoggedInAction.HomeAction << HomeAction.UpdateAccount <| AccountAction.ToggleIncomeEdition)
]
[ text name ]
|