Commit b906b215 authored by Nicolas Lenz's avatar Nicolas Lenz
Browse files

Form misc

parent 43f55d7b
Pipeline #867 passed with stages
in 4 minutes and 7 seconds
......@@ -5,8 +5,10 @@ license: Apache-2.0
dependencies:
- base
- classy-prelude
- keys
- yesod-core
- yesod-form
- containers
default-extensions:
- NoImplicitPrelude
......
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE QuasiQuotes #-}
{-# LANGUAGE MultiParamTypeClasses #-}
module Form where
import ClassyPrelude hiding (Handler)
import Data.Key (traverseWithKey)
import qualified Data.Map
import Foundation
import Yesod.Core
import Yesod.Form
import Config
import Result
instance RenderMessage App FormMessage where
renderMessage _ _ = defaultFormMessage
getFormR :: Text -> Handler TypedContent
getFormR id = undefined
cf :: Map Text ConfigForm
cf = undefined
cf = Data.Map.fromList
[ ("lolsurvey", ConfigFormSurvey ConfigFormHandlerRedirect questions)
]
questions :: Map Text ConfigFormSurveyQuestion
questions = Data.Map.fromList
[ ("q1", ConfigFormSurveyQuestionString)
, ("q2", ConfigFormSurveyQuestionInt )
]
postFormR :: Text -> Handler Html
postFormR id = case lookup id cf of
Just ConfigFormSurvey{..} -> do
result <- mapM (\question -> undefined) configFormSurveyQuestions
result <- runInputPost $ traverseWithKey surveyQuestion configFormSurveyQuestions
--let result = "Test"
defaultLayout [whamlet|<p>${show result}|]
Just ConfigFormQuiz{..} -> do
undefined
result <- runInputPost $ traverseWithKey quizQuestion configFormQuizQuestions
defaultLayout [whamlet|<p>${show result}|]
Nothing -> defaultLayout [whamlet|<p>Oops.|]
surveyQuestion :: Text -> ConfigFormSurveyQuestion -> FormInput Handler Answer
surveyQuestion id ConfigFormSurveyQuestionString = AnswerString <$> ireq textField id
surveyQuestion id ConfigFormSurveyQuestionInt = AnswerInt <$> ireq intField id
quizQuestion :: Text -> ConfigFormQuizQuestion -> FormInput Handler Answer
quizQuestion id (ConfigFormQuizQuestionString _) = AnswerString <$> ireq textField id
quizQuestion id (ConfigFormQuizQuestionInt _) = AnswerInt <$> ireq intField id
......@@ -27,6 +27,8 @@ library
build-depends:
base
, classy-prelude
, containers
, keys
, yesod-core
, yesod-form
default-language: Haskell2010
......@@ -42,6 +44,8 @@ executable surver
build-depends:
base
, classy-prelude
, containers
, keys
, surver
, yesod-core
, yesod-form
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment