add create-challenge form

This commit is contained in:
Filip Gralinski 2015-08-29 14:58:47 +02:00
parent 765dddc644
commit f00df0797f
8 changed files with 56 additions and 0 deletions

View File

@ -34,6 +34,7 @@ import Yesod.Fay (getFaySite)
import Handler.Common import Handler.Common
import Handler.Fay import Handler.Fay
import Handler.Home import Handler.Home
import Handler.CreateChallenge
-- This line actually creates our YesodDispatch instance. It is the second half -- This line actually creates our YesodDispatch instance. It is the second half
-- of the call to mkYesodData which occurs in Foundation.hs. Please see the -- of the call to mkYesodData which occurs in Foundation.hs. Please see the

View File

@ -0,0 +1,36 @@
module Handler.CreateChallenge where
import Import
import Yesod.Form.Bootstrap3 (BootstrapFormLayout (..), renderBootstrap3,
withSmallInput)
getCreateChallengeR :: Handler Html
getCreateChallengeR = do
(formWidget, formEnctype) <- generateFormPost sampleForm
let submission = Nothing :: Maybe (FileInfo, Text)
handlerName = "getCreateChallengeR" :: Text
defaultLayout $ do
aDomId <- newIdent
setTitle "Welcome To Yesod!"
$(widgetFile "create-challenge")
postCreateChallengeR :: Handler Html
postCreateChallengeR = do
((result, formWidget), formEnctype) <- runFormPost sampleForm
let handlerName = "postCreateChallengeR" :: Text
challengeData = case result of
FormSuccess res -> Just res
_ -> Nothing
defaultLayout $ do
aDomId <- newIdent
setTitle "Welcome To Yesod!"
$(widgetFile "creating-challenge")
sampleForm :: Form (Text, Text, Text, Text, Text)
sampleForm = renderBootstrap3 BootstrapBasicForm $ (,,,,)
<$> areq textField (fieldSettingsLabel MsgName) Nothing
<*> areq textField (fieldSettingsLabel MsgPublicUrl) Nothing
<*> areq textField (fieldSettingsLabel MsgBranch) Nothing
<*> areq textField (fieldSettingsLabel MsgPrivateUrl) Nothing
<*> areq textField (fieldSettingsLabel MsgBranch) Nothing

View File

@ -6,3 +6,5 @@
/robots.txt RobotsR GET /robots.txt RobotsR GET
/ HomeR GET POST / HomeR GET POST
/create-challenge CreateChallengeR GET POST

View File

@ -23,6 +23,7 @@ library
Settings.StaticFiles Settings.StaticFiles
SharedTypes SharedTypes
Handler.Common Handler.Common
Handler.CreateChallenge
Handler.Fay Handler.Fay
Handler.Home Handler.Home

View File

@ -1,3 +1,9 @@
LogIn: log in LogIn: log in
LogOut: log out LogOut: log out
LoggedAs: logged as LoggedAs: logged as
CreateChallenge: add a challenge
Name: name
PublicUrl: public repo (URL)
PrivateUrl: private repo (URL)
Branch: branch
Add: Add!

View File

@ -0,0 +1,7 @@
<h2>Add a challenge!
<p>
<form method=post action=@{CreateChallengeR}#form enctype=#{formEnctype}>
^{formWidget}
<button .btn .btn-primary type="submit">
_{MsgAdd} <span class="glyphicon glyphicon-upload"></span>

View File

@ -0,0 +1,2 @@
$maybe (name, publicUrl, publicBranch, privateUrl, privateUrl) <- challengeData
<p>Cloning #{publicUrl}

View File

@ -1,6 +1,7 @@
<div id="heading"> <div id="heading">
$maybe user <- maybeUser $maybe user <- maybeUser
_{MsgLoggedAs} #{userIdent $ entityVal user} _{MsgLoggedAs} #{userIdent $ entityVal user}
\ | <a href="@{CreateChallengeR}">_{MsgCreateChallenge}</a>
\ | <a href="@{AuthR LogoutR}">_{MsgLogOut}</a> \ | <a href="@{AuthR LogoutR}">_{MsgLogOut}</a>
$nothing $nothing
<a href="@{AuthR LoginR}">_{MsgLogIn}</a> <a href="@{AuthR LoginR}">_{MsgLogIn}</a>