From f605541cbaaa3c339eef8f345547bcd653d3f721 Mon Sep 17 00:00:00 2001 From: Joris Date: Mon, 27 Jun 2016 14:36:03 +0200 Subject: Add the edit functionnality on payments --- src/client/elm/Utils/Form.elm | 8 -------- src/client/elm/Utils/Http.elm | 30 ++++++++++++++++-------------- 2 files changed, 16 insertions(+), 22 deletions(-) (limited to 'src/client/elm/Utils') diff --git a/src/client/elm/Utils/Form.elm b/src/client/elm/Utils/Form.elm index 482db5f..8d75a32 100644 --- a/src/client/elm/Utils/Form.elm +++ b/src/client/elm/Utils/Form.elm @@ -1,6 +1,5 @@ module Utils.Form exposing ( fieldAsText - , frequency ) import Form exposing (Form) @@ -12,10 +11,3 @@ fieldAsText form field = Form.getFieldAsString field form |> .value |> Maybe.withDefault "" - -frequency : Form a b -> Frequency -frequency form = - let field = Form.getFieldAsString "frequency" form - in if field.value == Just (toString Monthly) - then Monthly - else Punctual diff --git a/src/client/elm/Utils/Http.elm b/src/client/elm/Utils/Http.elm index 9bcfad7..4edc233 100644 --- a/src/client/elm/Utils/Http.elm +++ b/src/client/elm/Utils/Http.elm @@ -1,26 +1,28 @@ module Utils.Http exposing - ( post - , postWithBody - , delete + ( jsonRequest + , request + , requestWithBody , decodeHttpValue , errorKey ) import Http exposing (..) import Task exposing (..) -import Json.Decode as Json exposing (Decoder) +import Json.Decode as JsonDecode exposing (Decoder) +import Json.Encode as JsonEncode -post : String -> Task Error Value -post url = postWithBody url empty +jsonRequest : String -> String -> JsonEncode.Value -> Task Error Value +jsonRequest method url json = + json + |> JsonEncode.encode 0 + |> Http.string + |> requestWithBody method url -postWithBody : String -> Body -> Task Error Value -postWithBody = request "POST" +request : String -> String -> Task Error Value +request method url = requestWithBody method url empty -delete : String -> Task Error Value -delete url = request "DELETE" url empty - -request : String -> String -> Body -> Task Error Value -request method url body = +requestWithBody : String -> String -> Body -> Task Error Value +requestWithBody method url body = { verb = method , headers = [] , url = url @@ -52,7 +54,7 @@ decodeHttpValue : Decoder a -> Value -> Task Error a decodeHttpValue decoder value = case value of Text str -> - case Json.decodeString decoder str of + case JsonDecode.decodeString decoder str of Ok v -> succeed v Err msg -> fail (UnexpectedPayload msg) _ -> -- cgit v1.2.3