1
0
Fork 0
mirror of https://code.sup39.dev/repos/Wqawg synced 2025-03-20 04:46:22 +09:00

Multiplex ticket PUT and DELETE over POST

HTML forms support only GET and POST methods. One way to bypass that is
to send the form using JS. But I don't want that. Another is to send a
POST with a hidden form field which specifies the read method. This is
what 'postTicketR' does.
This commit is contained in:
fr33domlover 2016-05-02 11:34:11 +00:00
parent 9f917a7306
commit e8befc41ee
4 changed files with 15 additions and 4 deletions
src/Vervis/Handler

View file

@ -20,6 +20,7 @@ module Vervis.Handler.Ticket
, getTicketR
, putTicketR
, deleteTicketR
, postTicketR
, getTicketEditR
)
where
@ -34,7 +35,7 @@ import Database.Persist
import Text.Blaze.Html (Html, toHtml)
import Yesod.Auth (requireAuthId)
import Yesod.Core (defaultLayout)
import Yesod.Core.Handler (setMessage, redirect)
import Yesod.Core.Handler (setMessage, redirect, lookupPostParam, notFound)
import Yesod.Core.Widget (setTitle)
import Yesod.Form.Functions (runFormPost)
import Yesod.Form.Types (FormResult (..))
@ -146,6 +147,14 @@ deleteTicketR shar proj num =
--delete tickets?
error "Not implemented"
postTicketR :: Text -> Text -> Int -> Handler Html
postTicketR shar proj num = do
mmethod <- lookupPostParam "_method"
case mmethod of
Just "PUT" -> putTicketR shar proj num
Just "DELETE" -> deleteTicketR shar proj num
_ -> notFound
getTicketEditR :: Text -> Text -> Int -> Handler Html
getTicketEditR shar proj num = do
Entity _tid ticket <- runDB $ do