aboutsummaryrefslogtreecommitdiff
path: root/src/client
diff options
context:
space:
mode:
authorJoris2015-08-27 20:36:18 +0200
committerJoris2015-08-27 20:36:18 +0200
commitfd86f021e88a00348ac0e03f03d81cb15bf3042b (patch)
treebaf7cbb5cc01fccebc235e0e400cad94eb90de6b /src/client
parenta2527c34e6b0e719a948cfd36bfee5ffad095a30 (diff)
Server payament delete
Diffstat (limited to 'src/client')
-rw-r--r--src/client/ServerCommunication.elm35
-rw-r--r--src/client/View/Payments/Table.elm16
2 files changed, 28 insertions, 23 deletions
diff --git a/src/client/ServerCommunication.elm b/src/client/ServerCommunication.elm
index b4b547d..010b3df 100644
--- a/src/client/ServerCommunication.elm
+++ b/src/client/ServerCommunication.elm
@@ -11,6 +11,7 @@ import Json.Decode exposing (..)
import Date
import Model.Message exposing (messageDecoder)
+import Model.Payment exposing (PaymentId)
import Update as U
import Update.SignIn exposing (..)
@@ -20,6 +21,7 @@ type Communication =
NoCommunication
| SignIn String
| AddPayment String Int
+ | DeletePayment PaymentId
| SignOut
serverCommunications : Signal.Mailbox Communication
@@ -40,26 +42,21 @@ getRequest communication =
NoCommunication ->
Nothing
SignIn login ->
- Just
- { verb = "post"
- , headers = []
- , url = "/signIn?login=" ++ login
- , body = Http.empty
- }
+ Just (simplePost ("/signIn?login=" ++ login))
AddPayment name cost ->
- Just
- { verb = "post"
- , headers = []
- , url = "/payment/add?name=" ++ name ++ "&cost=" ++ (toString cost)
- , body = Http.empty
- }
+ Just (simplePost ("/payment/add?name=" ++ name ++ "&cost=" ++ (toString cost)))
+ DeletePayment paymentId ->
+ Just (simplePost ("payment/delete?id=" ++ paymentId))
SignOut ->
- Just
- { verb = "post"
- , headers = []
- , url = "/signOut"
- , body = Http.empty
- }
+ Just (simplePost "/signout")
+
+simplePost : String -> Http.Request
+simplePost url =
+ { verb = "post"
+ , headers = []
+ , url = url
+ , body = Http.empty
+ }
communicationToAction : Communication -> Http.Response -> U.Action
communicationToAction communication response =
@@ -74,6 +71,8 @@ communicationToAction communication response =
decodeResponse
response
(\id -> U.UpdatePayment (UP.AddPayment id name cost))
+ DeletePayment id ->
+ U.UpdatePayment (UP.Remove id)
SignOut ->
U.GoSignInView
else
diff --git a/src/client/View/Payments/Table.elm b/src/client/View/Payments/Table.elm
index 9033db8..50dd151 100644
--- a/src/client/View/Payments/Table.elm
+++ b/src/client/View/Payments/Table.elm
@@ -16,6 +16,8 @@ import Model exposing (Model)
import Model.Payment exposing (..)
import Model.View.PaymentView exposing (PaymentView)
+import ServerCommunication as SC exposing (serverCommunications)
+
import Update exposing (..)
import Update.Payment exposing (..)
@@ -54,9 +56,13 @@ paymentLine model paymentView (id, payment) =
, div [ class "cell" ] [ text ((toString payment.cost) ++ " €") ]
, div [ class "cell" ] [ text payment.userName ]
, div [ class "cell" ] [ text (renderDate payment.creation model.translations) ]
- , div
- [ class "cell remove"
- , onClick actions.address (UpdatePayment (Remove id))
- ]
- [ renderIcon "times" ]
+ , if paymentView.userName == payment.userName
+ then
+ div
+ [ class "cell remove"
+ , onClick serverCommunications.address (SC.DeletePayment id)
+ ]
+ [ renderIcon "times" ]
+ else
+ div [ class "cell" ] []
]