summaryrefslogtreecommitdiff
path: root/Handler/Category.hs
blob: 6a2c6df30e8800f61b14fb492817ef24669f088b (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 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