diff --git a/routes b/routes index 941fe5b63..445e0c311 100644 --- a/routes +++ b/routes @@ -4,7 +4,7 @@ /favicon.ico FaviconR GET /robots.txt RobotsR GET -/ HomeR GET +/ HomeR GET POST /profile ProfileR GET diff --git a/src/Handler/Home.hs b/src/Handler/Home.hs index 1ee3d187b..21b6ea6ee 100644 --- a/src/Handler/Home.hs +++ b/src/Handler/Home.hs @@ -24,5 +24,23 @@ import qualified Data.UUID.Cryptographic as UUID getHomeR :: Handler Html getHomeR = defaultLayout $ do + (crInfWdgt, crInfEnctype) <- generateFormPost $ postButtonForm "Informatik" + (crMatWdgt, crMatEnctype) <- generateFormPost $ postButtonForm "Mathematik" setTitle "Willkommen zum ReWorX Test!" $(widgetFile "home") + + +postHomeR :: Handler Html +postHomeR = do + ((infResult,_), _) <- runFormPost $ postButtonForm "Informatik" + ((matResult,_), _) <- runFormPost $ postButtonForm "Mathematik" + setMessage "ButtonTest" + case infResult of + (FormSuccess ()) -> setMessage "Informatik anlegen" -- does not work somehow + -- TODO runDB + _other -> return () + case matResult of + (FormSuccess ()) -> setMessage "Mathematik anlegen" + -- TODO runDB + _other -> return () + getHomeR diff --git a/src/Handler/Utils/Form.hs b/src/Handler/Utils/Form.hs index 03911e11d..9702b4cad 100644 --- a/src/Handler/Utils/Form.hs +++ b/src/Handler/Utils/Form.hs @@ -17,8 +17,12 @@ import Data.String (IsString(..)) import qualified Data.Text as T -- import Yesod.Form.Types import Yesod.Form.Functions (parseHelper) +import Yesod.Form.Bootstrap3 +------------- +-- Buttons -- +------------- formBtnSave :: (Text,Text,Text) formBtnSave = ("save" ,"Speichern" ,"btn-primary") @@ -44,6 +48,16 @@ defaultFormActions = [ formBtnDelete , formBtnSave ] +-- Post-Buttons +-- postButtonForm :: MonadHandler m => +-- Text -> Text.Blaze.Internal.Markup -> MForm m (FormResult (), WidgetT (HandlerSite m) IO ()) +postButtonForm lblId = identifyForm lblId buttonF + where + buttonF = renderBootstrap3 BootstrapInlineForm $ pure () <* bootstrapSubmit bProps + bProps :: BootstrapSubmit Text + bProps = fromString $ unpack lblId + + ------------ -- Fields -- ------------ diff --git a/templates/home.hamlet b/templates/home.hamlet index a5ce5e971..04114a2a1 100644 --- a/templates/home.hamlet +++ b/templates/home.hamlet @@ -58,3 +58,19 @@