summaryrefslogtreecommitdiff
path: root/Handler/Category.hs
diff options
context:
space:
mode:
authorClint Adams <clint@softwarefreedom.org>2012-10-24 17:16:15 -0400
committerClint Adams <clint@softwarefreedom.org>2012-10-24 17:16:15 -0400
commit10f6e8f4cce3303f53df359e0f40fcb5d584e85d (patch)
treed5e7d5adb3dc81ac8f127e13f1d934d601597c5b /Handler/Category.hs
parent025eb70c992914fbdf018c189d358ae250d2eeb1 (diff)
Category enablement self-service.
Diffstat (limited to 'Handler/Category.hs')
-rw-r--r--Handler/Category.hs36
1 files changed, 36 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