summaryrefslogtreecommitdiff
path: root/Handler/ReferenceListing.hs
diff options
context:
space:
mode:
authorGregor Kleen <gkleen@yggdrasil.li>2017-03-14 18:33:42 +0100
committerGregor Kleen <gkleen@yggdrasil.li>2017-03-14 18:33:42 +0100
commit7bc954b779a9bc4e1c5e60f2648101c62ed22e72 (patch)
treeb30851324772c14550c0444b7e79e36256f67900 /Handler/ReferenceListing.hs
parent53fcf55c02f9335518c28d26429913258fc28f87 (diff)
downloadbar-7bc954b779a9bc4e1c5e60f2648101c62ed22e72.tar
bar-7bc954b779a9bc4e1c5e60f2648101c62ed22e72.tar.gz
bar-7bc954b779a9bc4e1c5e60f2648101c62ed22e72.tar.bz2
bar-7bc954b779a9bc4e1c5e60f2648101c62ed22e72.tar.xz
bar-7bc954b779a9bc4e1c5e60f2648101c62ed22e72.zip
Reference & list
Diffstat (limited to 'Handler/ReferenceListing.hs')
-rw-r--r--Handler/ReferenceListing.hs27
1 files changed, 27 insertions, 0 deletions
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 @@
1module Handler.ReferenceListing where
2
3import Import
4
5import Handler.Common
6
7getReferenceListingR, postReferenceListingR :: Handler TypedContent
8getReferenceListingR = postReferenceListingR
9postReferenceListingR = do
10 ((insertResult, fsInsertForm), fsInsertEncoding) <- runFormPost $ referenceForm Nothing
11
12 mapM_ (addMessage "formError" . toHtml) =<< case insertResult of
13 FormSuccess newReference -> [] <$ runDB (insert newReference)
14 FormFailure errors -> return errors
15 _ -> return []
16
17 reference <- runDB $ selectList [] [Asc ReferenceKind]
18
19 selectRep $ do
20 provideJson (reference :: [Entity Reference])
21 provideRep . defaultLayout $ referenceListing ReferenceState
22 { refFormState = Just InsertForm{..}
23 , ..
24 }
25
26putReferenceListingR :: Handler Value
27putReferenceListingR = returnJson =<< runDB . insertEntity =<< (requireCheckJsonBody :: Handler Reference)