Created
August 21, 2011 15:39
-
-
Save bshepherdson/1160759 to your computer and use it in GitHub Desktop.
Broken jqueryDayTimeField in Yesod
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| {-# LANGUAGE TemplateHaskell, QuasiQuotes, OverloadedStrings #-} | |
| module Handler.Activities where | |
| import LoveBug | |
| import Utils | |
| import Data.Text (Text) | |
| import qualified Data.Text as T | |
| import Control.Applicative | |
| import Control.Monad | |
| import Control.Arrow (second) | |
| import Data.Maybe | |
| import Yesod.Form | |
| import Yesod.Form.Jquery | |
| import Data.Time | |
| import qualified Data.Map as M | |
| import Text.Printf | |
| getActivityR :: Handler RepHtml | |
| getActivityR = do | |
| (uid, u) <- requireAuth | |
| mc <- maybeCoupleByUser u | |
| (_, wformActivity, enctypeActivity, nonceActivity) <- runFormPost $ activityFormlet Nothing | |
| case mc of | |
| Nothing -> defaultLayout $ do | |
| setTitle "Time Together - Activities" | |
| addHamlet $[hamlet|<p>You are not connected with anyone, so there are no Activities to view.|] | |
| Just (cid, c) -> do | |
| activityTitles <- runDB $ do | |
| raw <- selectList [ActivityOwnerEq cid] [ActivityTitleAsc] 0 0 | |
| return $ map (second activityTitle) raw | |
| (_, wformRecord, enctypeRecord, nonceRecord) <- runFormPost $ activityRecordFormlet activityTitles Nothing | |
| (acts, recs) <- runDB $ do | |
| acts <- selectList [ActivityOwnerEq cid] [ActivityTitleAsc] 0 0 | |
| recs <- selectList [ActivityRecordOwnerEq cid] [ActivityRecordStartedDesc] 10 0 | |
| return (acts, recs) | |
| let activityNames = M.fromList activityTitles | |
| defaultLayout $ do | |
| setTitle "Time Together - Activities" | |
| addWidget $(widgetFile "activities") | |
| data ActivityRecordForm = ActivityRecordForm { | |
| rActivity :: ActivityId, | |
| rStarted :: UTCTime, | |
| rDuration :: Double, | |
| rComment :: Maybe Textarea | |
| } deriving (Show) | |
| activityRecordFormlet :: [(ActivityId, Text)] -> Formlet LoveBug LoveBug ActivityRecordForm | |
| activityRecordFormlet acts r = fieldsToTable $ ActivityRecordForm | |
| <$> selectField acts "Activity" (fmap rActivity r) | |
| <*> jqueryDayTimeField "Start time" (fmap rStarted r) | |
| <*> doubleField "Duration (hours)" (fmap rDuration r) | |
| <*> maybeTextareaField "Comment" (fmap rComment r) | |
| {- | |
| and the resulting HTML: | |
| <table class="newActivityRecordTable"> | |
| <tbody> | |
| <tr class="required"> | |
| <td><label for="f2">Activity</label><div class="tooltip"></div></td> | |
| <td><select id="f2" name="f3"><option value="none"></option><option value="1">Horseback riding</option><option value="2">Watching a movie</option></select></td> | |
| </tr> | |
| <tr class="required"> | |
| <td><label for="f5">Start time</label><div class="tooltip"></div></td> | |
| <td><input id="f5" name="f4" required="" value=""></td> | |
| </tr> | |
| <tr class="required"> | |
| <td><label for="f7">Duration (hours)</label><div class="tooltip"></div></td> | |
| <td><input id="f7" name="f6" type="text" required="" value=""></td> | |
| </tr> | |
| <tr class="optional"> | |
| <td><label for="f9">Comment</label><div class="tooltip"></div></td> | |
| <td><textarea id="f9" name="f8"></textarea></td> | |
| </tr> | |
| <tr><td colspan="2"><input type="submit" value="Create"></td> | |
| </tr></tbody></table> | |
| -} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment