summaryrefslogtreecommitdiff
path: root/Handler/ReferenceListing.hs
diff options
context:
space:
mode:
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)