blob: d4d48030d545d762657b38b1926cc1973ec0430d (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
{-# LANGUAGE TupleSections, OverloadedStrings #-}
module Handler.Category where
import Import
import qualified Data.Text as T
getCategoryR :: TimeCategoryId -> Handler Html
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 Html
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
|