aboutsummaryrefslogtreecommitdiff
path: root/src/client/elm/Dialog/AddPayment
diff options
context:
space:
mode:
authorJoris2017-03-26 21:10:42 +0200
committerJoris2017-03-26 21:10:42 +0200
commit1e47a7754ca38bd1a6c74765d8378caf68ce4619 (patch)
treed0d9238479dc2529a1b558bbbcde346e7e8c2935 /src/client/elm/Dialog/AddPayment
parentc0ac16a713c4e53cf6af8e72a6d5f6b8ac5d6456 (diff)
downloadbudget-1e47a7754ca38bd1a6c74765d8378caf68ce4619.tar.gz
budget-1e47a7754ca38bd1a6c74765d8378caf68ce4619.tar.bz2
budget-1e47a7754ca38bd1a6c74765d8378caf68ce4619.zip
Separate client and server watch
Diffstat (limited to 'src/client/elm/Dialog/AddPayment')
-rw-r--r--src/client/elm/Dialog/AddPayment/Model.elm70
-rw-r--r--src/client/elm/Dialog/AddPayment/View.elm95
2 files changed, 0 insertions, 165 deletions
diff --git a/src/client/elm/Dialog/AddPayment/Model.elm b/src/client/elm/Dialog/AddPayment/Model.elm
deleted file mode 100644
index a287d37..0000000
--- a/src/client/elm/Dialog/AddPayment/Model.elm
+++ /dev/null
@@ -1,70 +0,0 @@
-module Dialog.AddPayment.Model exposing
- ( Model
- , init
- , initialAdd
- , initialClone
- , initialEdit
- , validation
- )
-
-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 exposing (Payment, Frequency, PaymentId)
-import Model.Translations exposing (Translations)
-import Model.Category as Category exposing (Categories, CategoryId)
-
-import Utils.Maybe as Maybe
-
-type alias Model =
- { id : Maybe PaymentId
- , name : String
- , cost : Int
- , date : Date
- , category : CategoryId
- , frequency : Frequency
- }
-
-init : Form String Model
-init = Form.initial [] (validation Category.empty)
-
-initialAdd : Translations -> Date -> Frequency -> List (String, Field)
-initialAdd translations date frequency =
- [ ("date", Field.string (Date.shortView date translations))
- , ("frequency", Field.string (toString frequency))
- , ("category", Field.string "")
- ]
-
-initialClone : Translations -> Date -> Maybe CategoryId -> Payment -> List (String, Field)
-initialClone translations date category payment =
- [ ("name", Field.string payment.name)
- , ("cost", Field.string (toString payment.cost))
- , ("date", Field.string (Date.shortView date translations))
- , ("frequency", Field.string (toString payment.frequency))
- , ("category", Field.string (Maybe.map toString category |> Maybe.withDefault ""))
- ]
-
-initialEdit : Translations -> Maybe CategoryId -> Payment -> List (String, Field)
-initialEdit translations category payment =
- [ ("id", Field.string (toString payment.id))
- , ("name", Field.string payment.name)
- , ("cost", Field.string (toString payment.cost))
- , ("date", Field.string (Date.shortView payment.date translations))
- , ("frequency", Field.string (toString payment.frequency))
- , ("category", Field.string (Maybe.map toString category |> Maybe.withDefault ""))
- ]
-
-validation : Categories -> Validation String Model
-validation categories =
- Validate.map6 Model
- (Validate.field "id" (Validate.maybe Validate.int))
- (Validate.field "name" (Validate.string |> Validate.andThen Validate.nonEmpty))
- (Validate.field "cost" (Validate.int |> Validate.andThen (Validate.minInt 1)))
- (Validate.field "date" Validation.date)
- (Validate.field "category" (Validation.category categories))
- (Validate.field "frequency" Payment.validateFrequency)
diff --git a/src/client/elm/Dialog/AddPayment/View.elm b/src/client/elm/Dialog/AddPayment/View.elm
deleted file mode 100644
index 078d5b7..0000000
--- a/src/client/elm/Dialog/AddPayment/View.elm
+++ /dev/null
@@ -1,95 +0,0 @@
-module Dialog.AddPayment.View exposing
- ( button
- )
-
-import Dict
-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.AddPayment.Model as AddPayment
-import Dialog.Msg as DialogMsg
-
-import Tooltip
-
-import View.Events exposing (onSubmitPrevDefault)
-import View.Form as Form
-
-import LoggedIn.Home.Msg as HomeMsg
-import LoggedIn.Msg as LoggedInMsg
-import Msg exposing (Msg)
-
-import Model.Category exposing (Categories)
-import Model.Payment as Payment exposing (Frequency(..))
-import Model.PaymentCategory exposing (PaymentCategories)
-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 = "paymentDialog"
- , title = getMessage loggedData.translations title
- , body = \model -> addPaymentForm loggedData model.addPayment
- , confirm = getMessage loggedData.translations "Confirm"
- , confirmMsg = submitForm loggedData.categories loggedData.paymentCategories << .addPayment
- , undo = getMessage loggedData.translations "Undo"
- }
- in Html.button
- ( ( case tooltip of
- Just message -> Tooltip.show Msg.Tooltip message
- Nothing -> []
- )
- ++ [ class "addPayment"
- , onClick (Msg.Dialog <| Dialog.OpenWithUpdate dialogConfig (DialogMsg.Init "paymentname" (DialogMsg.AddPaymentMsg loggedData.categories loggedData.paymentCategories <| Form.Reset initialForm)))
- ]
- )
- [ buttonContent ]
-
-addPaymentForm : LoggedData -> Form String AddPayment.Model -> Html Msg
-addPaymentForm loggedData addPayment =
- let htmlMap = Html.map (Msg.Dialog << Dialog.Update << DialogMsg.AddPaymentMsg loggedData.categories loggedData.paymentCategories)
- categoryOptions =
- loggedData.categories
- |> Dict.toList
- |> List.sortBy (.name << Tuple.second)
- |> List.map (\(id, category) -> (toString id, category.name))
- in Html.form
- [ class "addPayment"
- , onSubmitPrevDefault Msg.NoOp
- ]
- [ htmlMap <| Form.textInput loggedData.translations addPayment "payment" "name"
- , htmlMap <| Form.textInput loggedData.translations addPayment "payment" "cost"
- , if (Form.getFieldAsString "frequency" addPayment).value == Just (toString Punctual)
- then htmlMap <| Form.textInput loggedData.translations addPayment "payment" "date"
- else text ""
- , htmlMap <| Form.selectInput loggedData.translations addPayment "payment" "category" categoryOptions
-
- , htmlMap <| Form.radioInputs loggedData.translations addPayment "payment" "frequency" [ toString Punctual, toString Monthly ]
- , Form.hiddenSubmit (submitForm loggedData.categories loggedData.paymentCategories addPayment)
- ]
-
-submitForm : Categories -> PaymentCategories -> Form String AddPayment.Model -> Msg
-submitForm categories paymentCategories addPayment =
- case Form.getOutput addPayment of
- Just data ->
- case data.id of
- Just paymentId ->
- Msg.Dialog
- <| Dialog.UpdateAndClose
- <| Msg.EditPayment paymentId data.name data.cost data.date data.category data.frequency
- Nothing ->
- Msg.Dialog
- <| Dialog.UpdateAndClose
- <| Msg.CreatePayment data.name data.cost data.date data.category data.frequency
- Nothing ->
- Msg.Dialog <| Dialog.Update <| DialogMsg.AddPaymentMsg categories paymentCategories <| Form.Submit