blob: 55057a92f02b661ccdce6af8df5c76b09d34d732 (
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
36
37
38
39
40
41
42
|
{-# LANGUAGE TupleSections, OverloadedStrings #-}
module Handler.Employment where
import Import
import qualified Data.Text as T
import Yesod.Form.Jquery (jqueryDayField, def)
getEmploymentR :: EmploymentId -> Handler Html
getEmploymentR eid = do
emp <- runDB $ get404 eid
user <- runDB $ get404 (employmentUser emp)
let username = userIdent user
(formWidget, formEnctype) <- generateFormPost (employmentForm emp)
defaultLayout $ do
aDomId <- newIdent
(setTitle . toHtml) ("Employment span for " `T.append` username)
$(widgetFile "employmentpage")
postEmploymentR :: EmploymentId -> Handler Html
postEmploymentR eid = do
emp <- runDB $ get404 eid
user <- runDB $ get404 (employmentUser emp)
let username = userIdent user
((result, formWidget), formEnctype) <- runFormPost (employmentForm emp)
_ <- case result of
FormSuccess res -> (runDB $ replace eid res) >> return ()
_ -> return ()
defaultLayout $ do
aDomId <- newIdent
(setTitle . toHtml) ("Employment span for " `T.append` username)
$(widgetFile "employmentpage")
employmentAForm :: Employment -> AForm Handler Employment
employmentAForm tc = Employment
<$> pure (employmentUser tc)
<*> areq (jqueryDayField def) "Start date" (Just (employmentStartDate tc))
<*> aopt (jqueryDayField def) "End date" (Just (employmentEndDate tc))
<*> areq doubleField "Commitment" (Just (employmentCommitment tc))
employmentForm :: Employment -> Html -> MForm Handler (FormResult Employment, Widget)
employmentForm tc h = renderDivs (employmentAForm tc) h
|