{-# LANGUAGE TupleSections, OverloadedStrings #-} module Handler.Category where import Import import qualified Data.Text as T getCategoryR :: TimeCategoryId -> Handler RepHtml getCategoryR tcid = do cat <- runDB $ get404 tcid (formWidget, formEnctype) <- generateFormPost (timeCategoryForm cat) defaultLayout $ do aDomId <- newIdent (setTitle . toHtml) ("Time category " `T.append` timeCategoryName cat) $(widgetFile "categorypage") postCategoryR :: TimeCategoryId -> Handler RepHtml postCategoryR tcid = do cat <- runDB $ get404 tcid ((result, formWidget), formEnctype) <- runFormPost (timeCategoryForm cat) _ <- case result of FormSuccess res -> (runDB $ replace tcid res) >> return () _ -> return () defaultLayout $ do aDomId <- newIdent (setTitle . toHtml) ("Time category " `T.append` timeCategoryName cat) $(widgetFile "categorypage") timeCategoryAForm :: TimeCategory -> AForm Handler TimeCategory timeCategoryAForm tc = TimeCategory <$> pure (timeCategoryName tc) <*> areq checkBoxField "Disable" (Just (timeCategoryDisabled tc)) timeCategoryForm :: TimeCategory -> Html -> MForm Handler (FormResult TimeCategory, Widget) timeCategoryForm tc h = renderDivs (timeCategoryAForm tc) h