From 7bc954b779a9bc4e1c5e60f2648101c62ed22e72 Mon Sep 17 00:00:00 2001 From: Gregor Kleen Date: Tue, 14 Mar 2017 18:33:42 +0100 Subject: Reference & list --- Handler/ReferenceListing.hs | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 Handler/ReferenceListing.hs (limited to 'Handler/ReferenceListing.hs') diff --git a/Handler/ReferenceListing.hs b/Handler/ReferenceListing.hs new file mode 100644 index 0000000..0f777ee --- /dev/null +++ b/Handler/ReferenceListing.hs @@ -0,0 +1,27 @@ +module Handler.ReferenceListing where + +import Import + +import Handler.Common + +getReferenceListingR, postReferenceListingR :: Handler TypedContent +getReferenceListingR = postReferenceListingR +postReferenceListingR = do + ((insertResult, fsInsertForm), fsInsertEncoding) <- runFormPost $ referenceForm Nothing + + mapM_ (addMessage "formError" . toHtml) =<< case insertResult of + FormSuccess newReference -> [] <$ runDB (insert newReference) + FormFailure errors -> return errors + _ -> return [] + + reference <- runDB $ selectList [] [Asc ReferenceKind] + + selectRep $ do + provideJson (reference :: [Entity Reference]) + provideRep . defaultLayout $ referenceListing ReferenceState + { refFormState = Just InsertForm{..} + , .. + } + +putReferenceListingR :: Handler Value +putReferenceListingR = returnJson =<< runDB . insertEntity =<< (requireCheckJsonBody :: Handler Reference) -- cgit v1.2.3