postSurveyR :: Handler Html
postSurveyR = do
  ((formResult, formWidget), formEnctype) <- runFormPost $ renderBootstrap3 BootstrapBasicForm testForm
  case formResult of
    FormSuccess answers -> do
      muserId <- maybeAuthId
      runDB . forM_ answers $ \(question, manswer) -> case manswer of
         Nothing -> return ()
         Just answer -> insert_ $ Survey muserId question answer
      fullLayout Nothing "Qua-kit user survey" $ do
        -- render all html
        [whamlet|
          <div class="row">
            <div class="col-lg-9 col-md-9 col-sm-9 col-xs-9">
              <div.card>
                    <div.card-main>
                      <div.card-header>
                        <div.card-inner.>
                          <h3.h5.margin-bottom-no.margin-top-no>
                            Thank you!
                      <div.card-inner>
                       Your answers have been saved.
        |]
    _ -> do
      fullLayout Nothing "Qua-kit user survey" $ do

        -- render all html
        [whamlet|
          <div class="row">
            <div class="col-lg-9 col-md-9 col-sm-9 col-xs-9">
              <div.card>
                    <div.card-main>
                      <div.card-header>
                        <div.card-inner.>
                          <h3.h5.margin-bottom-no.margin-top-no>
                            Dear edX student!
                      <div.card-inner>
                       <p>
                        Thank you for your participation in the course and in qua-kit series of exercises.
                        As you may know, qua-kit is an experimental educational and research platform.
                       <p>
                        You will help us a lot if you answer a series of questions related to your experience in qua-kit.
                        This should take not more than five minutes.
                        All questions are optional, so feel free to omit some of them if you do have difficulties with any.

              <div.card>
                    <div.card-main>
                      <div.card-inner>
                        <form role=form method=post action=@{SurveyR} enctype=#{formEnctype}>
                          ^{formWidget}
                          <button type="submit" .btn .btn-default>Submit
        |]
postSurveyR :: Handler Html
postSurveyR = do
  ((formResult, formWidget), formEnctype) <- runFormPost $ renderBootstrap3 BootstrapBasicForm testForm
  case formResult of
    FormSuccess answers -> do
      muserId <- maybeAuthId
      runDB . forM_ answers $ \(question, manswer) -> case manswer of
         Nothing -> return ()
         Just answer -> insert_ $ Survey muserId question answer
      fullLayout Nothing "Qua-kit user survey" $ do
        -- render all html
        [whamlet|
          <div class="row">
            <div class="col-lg-9 col-md-9 col-sm-9 col-xs-9">
              <div.card>
                    <div.card-main>
                      <div.card-header>
                        <div.card-inner.>
                          <h3.h5.margin-bottom-no.margin-top-no>
                            Thank you!
                      <div.card-inner>
                       Your answers have been saved.
        |]
    _ -> do
      fullLayout Nothing "Qua-kit user survey" $ do

        -- render all html
        [whamlet|
          <div class="row">
            <div class="col-lg-9 col-md-9 col-sm-9 col-xs-9">
              <div.card>
                    <div.card-main>
                      <div.card-header>
                        <div.card-inner.>
                          <h3.h5.margin-bottom-no.margin-top-no>
                            Dear edX student!
                      <div.card-inner>
                       <p>
                        Thank you for your participation in the course and in qua-kit series of exercises.
                        As you may know, qua-kit is an experimental educational and research platform.
                       <p>
                        You will help us a lot if you answer a series of questions related to your experience in qua-kit.
                        This should take not more than five minutes.
                        All questions are optional, so feel free to omit some of them if you do have difficulties with any.

              <div.card>
                    <div.card-main>
                      <div.card-inner>
                        <form role=form method=post action=@{SurveyR} enctype=#{formEnctype}>
                          ^{formWidget}
                          <button type="submit" .btn .btn-default>Submit
        |]
postSurveyR = do
  ((formResult, formWidget), formEnctype) <- runFormPost $ renderBootstrap3 BootstrapBasicForm testForm
  case formResult of
    FormSuccess answers -> do
      muserId <- maybeAuthId
      runDB . forM_ answers $ \(question, manswer) -> case manswer of
         Nothing -> return ()
         Just answer -> insert_ $ Survey muserId question answer
      fullLayout Nothing "Qua-kit user survey" $ do
        -- render all html
        [whamlet|
          <div class="row">
            <div class="col-lg-9 col-md-9 col-sm-9 col-xs-9">
              <div.card>
                    <div.card-main>
                      <div.card-header>
                        <div.card-inner.>
                          <h3.h5.margin-bottom-no.margin-top-no>
                            Thank you!
                      <div.card-inner>
                       Your answers have been saved.
        |]
    _ -> do
      fullLayout Nothing "Qua-kit user survey" $ do

        -- render all html
        [whamlet|
          <div class="row">
            <div class="col-lg-9 col-md-9 col-sm-9 col-xs-9">
              <div.card>
                    <div.card-main>
                      <div.card-header>
                        <div.card-inner.>
                          <h3.h5.margin-bottom-no.margin-top-no>
                            Dear edX student!
                      <div.card-inner>
                       <p>
                        Thank you for your participation in the course and in qua-kit series of exercises.
                        As you may know, qua-kit is an experimental educational and research platform.
                       <p>
                        You will help us a lot if you answer a series of questions related to your experience in qua-kit.
                        This should take not more than five minutes.
                        All questions are optional, so feel free to omit some of them if you do have difficulties with any.

              <div.card>
                    <div.card-main>
                      <div.card-inner>
                        <form role=form method=post action=@{SurveyR} enctype=#{formEnctype}>
                          ^{formWidget}
                          <button type="submit" .btn .btn-default>Submit
        |]