diff options
author | Clint Adams <clint@softwarefreedom.org> | 2012-10-24 17:16:15 -0400 |
---|---|---|
committer | Clint Adams <clint@softwarefreedom.org> | 2012-10-24 17:16:15 -0400 |
commit | 10f6e8f4cce3303f53df359e0f40fcb5d584e85d (patch) | |
tree | d5e7d5adb3dc81ac8f127e13f1d934d601597c5b | |
parent | 025eb70c992914fbdf018c189d358ae250d2eeb1 (diff) |
Category enablement self-service.
-rw-r--r-- | Handler/Category.hs | 36 | ||||
-rw-r--r-- | templates/categorypage.hamlet | 6 |
2 files changed, 42 insertions, 0 deletions
diff --git a/Handler/Category.hs b/Handler/Category.hs new file mode 100644 index 0000000..62928a2 --- /dev/null +++ b/Handler/Category.hs @@ -0,0 +1,36 @@ +{-# LANGUAGE TupleSections, OverloadedStrings #-} +module Handler.Category where + +import Import +import Data.Maybe (fromMaybe) +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 <- lift 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 <- lift newIdent + (setTitle . toHtml) ("Time category " `T.append` timeCategoryName cat) + $(widgetFile "categorypage") + +timeCategoryAForm :: TimeCategory -> AForm App App TimeCategory +timeCategoryAForm tc = TimeCategory + <$> pure (timeCategoryName tc) + <*> areq checkBoxField "Disable" (Just (timeCategoryDisabled tc)) + +timeCategoryForm :: TimeCategory -> Html -> MForm App App (FormResult TimeCategory, Widget) +timeCategoryForm tc h = renderDivs (timeCategoryAForm tc) h diff --git a/templates/categorypage.hamlet b/templates/categorypage.hamlet new file mode 100644 index 0000000..fb4a756 --- /dev/null +++ b/templates/categorypage.hamlet @@ -0,0 +1,6 @@ +<h1>#{timeCategoryName cat} + +<p> + <form method=post action=@{CategoryR tcid}#form enctype=#{formEnctype}> + ^{formWidget} + <input type="submit" value="Submit"> |