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