aboutsummaryrefslogtreecommitdiff
path: root/src/client/Dialog/AddIncome/View.elm
diff options
context:
space:
mode:
authorJoris2017-03-26 21:10:42 +0200
committerJoris2017-03-26 21:10:42 +0200
commit1e47a7754ca38bd1a6c74765d8378caf68ce4619 (patch)
treed0d9238479dc2529a1b558bbbcde346e7e8c2935 /src/client/Dialog/AddIncome/View.elm
parentc0ac16a713c4e53cf6af8e72a6d5f6b8ac5d6456 (diff)
downloadbudget-1e47a7754ca38bd1a6c74765d8378caf68ce4619.tar.gz
budget-1e47a7754ca38bd1a6c74765d8378caf68ce4619.tar.bz2
budget-1e47a7754ca38bd1a6c74765d8378caf68ce4619.zip
Separate client and server watch
Diffstat (limited to 'src/client/Dialog/AddIncome/View.elm')
-rw-r--r--src/client/Dialog/AddIncome/View.elm72
1 files changed, 72 insertions, 0 deletions
diff --git a/src/client/Dialog/AddIncome/View.elm b/src/client/Dialog/AddIncome/View.elm
new file mode 100644
index 0000000..b413308
--- /dev/null
+++ b/src/client/Dialog/AddIncome/View.elm
@@ -0,0 +1,72 @@
+module Dialog.AddIncome.View exposing
+ ( button
+ )
+
+import Html exposing (..)
+import Html.Attributes exposing (..)
+import Html.Events exposing (..)
+import Task
+
+import Form exposing (Form)
+import Form.Field as Field exposing (Field)
+import Utils.Form as Form
+
+import Dialog
+import Dialog.AddIncome.Model as AddIncome
+import Dialog.Msg as DialogMsg
+
+import Tooltip
+
+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.View exposing (View(LoggedInView))
+
+import LoggedData exposing (LoggedData)
+import LoggedIn.Home.Model as HomeModel
+
+button : LoggedData -> List (String, Field) -> String -> Html Msg -> Maybe String -> Html Msg
+button loggedData initialForm title buttonContent tooltip =
+ let dialogConfig =
+ { className = "incomeDialog"
+ , title = getMessage loggedData.translations title
+ , body = \model -> addIncomeForm loggedData model.addIncome
+ , confirm = getMessage loggedData.translations "Confirm"
+ , confirmMsg = submitForm << .addIncome
+ , undo = getMessage loggedData.translations "Undo"
+ }
+ in Html.button
+ ( ( case tooltip of
+ Just message -> Tooltip.show Msg.Tooltip message
+ Nothing -> []
+ )
+ ++ [ onClick (Msg.Dialog <| Dialog.OpenWithUpdate dialogConfig (DialogMsg.Init "incomeamount" (DialogMsg.AddIncomeMsg <| Form.Reset initialForm))) ]
+ )
+ [ buttonContent ]
+
+addIncomeForm : LoggedData -> Form String AddIncome.Model -> Html Msg
+addIncomeForm loggedData addIncome =
+ let htmlMap = Html.map (Msg.Dialog << Dialog.Update << DialogMsg.AddIncomeMsg)
+ in Html.form
+ [ onSubmitPrevDefault Msg.NoOp ]
+ [ htmlMap <| Form.textInput loggedData.translations addIncome "income" "amount"
+ , htmlMap <| Form.textInput loggedData.translations addIncome "income" "date"
+ , Form.hiddenSubmit (submitForm addIncome)
+ ]
+
+submitForm : Form String AddIncome.Model -> Msg
+submitForm addIncome =
+ case Form.getOutput addIncome of
+ Just data ->
+ case data.id of
+ Just incomeId ->
+ Msg.Dialog <| Dialog.UpdateAndClose <| Msg.EditIncome incomeId data.amount data.date
+ Nothing ->
+ Msg.Dialog <| Dialog.UpdateAndClose <| Msg.CreateIncome data.amount data.date
+ Nothing ->
+ Msg.Dialog <| Dialog.Update <| DialogMsg.AddIncomeMsg <| Form.Submit