module Handler.ReferenceListing where import Import import Handler.Common getReferenceListingR, postReferenceListingR :: Handler TypedContent getReferenceListingR = postReferenceListingR postReferenceListingR = do ((insertResult, fsInsertForm), fsInsertEncoding) <- runFormPost $ referenceForm Nothing case insertResult of FormSuccess (Reference{..} `WithType` t) -> runDB $ do upsertBy (UniqueKind referenceNormKind) (Kind referenceNormKind t) [ KindType =. t ] insert Reference{..} return () FormFailure errors -> mapM_ (addMessage "formError" . toHtml) errors _ -> return () (referenceSort -> reference) <- runDB $ mapM withType =<< selectList [] [Asc ReferenceKind] selectRep $ do provideJson (reference :: [WithType (Entity Reference)]) provideRep . defaultLayout $ referenceListing ReferenceState { refFormState = Just InsertForm{..} , .. } putReferenceListingR :: Handler Value putReferenceListingR = do (Reference{..} `WithType` referenceType) <- requireCheckJsonBody returnJson <=< runDB $ do upsertBy (UniqueKind referenceNormKind) (Kind referenceNormKind referenceType) [ KindType =. referenceType ] withType =<< insertEntity Reference{..}