liquid_feedback_frontend

diff app/main/survey/participate.lua @ 1735:5a8a09119865

Added survey feature
author bsw
date Fri Oct 08 00:09:23 2021 +0200 (2021-10-08)
parents
children b94cf0ea5942
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/app/main/survey/participate.lua	Fri Oct 08 00:09:23 2021 +0200
     1.3 @@ -0,0 +1,110 @@
     1.4 +local survey = Survey:get_open()
     1.5 +if not survey then
     1.6 +  return execute.view { module = "index", view = "404" }
     1.7 +end
     1.8 +
     1.9 +local survey_member = SurveyMember:by_pk(survey.id, app.session.member_id)
    1.10 +if not survey_member then
    1.11 +  return execute.view { module = "index", view = "404" }
    1.12 +end
    1.13 +
    1.14 +local question
    1.15 +
    1.16 +if survey_member then
    1.17 +  local answer_set = survey_member.answer_set
    1.18 +  if answer_set then
    1.19 +    local answers_by_question_id = {}
    1.20 +    for i, answer in ipairs(answer_set.answers) do
    1.21 +      answers_by_question_id[answer.survey_question_id] = answer
    1.22 +    end
    1.23 +    for i, q in ipairs(survey.questions) do
    1.24 +      if not question and not answers_by_question_id[q.id] then
    1.25 +        question = q
    1.26 +      end
    1.27 +    end
    1.28 +  end
    1.29 +end
    1.30 +
    1.31 +ui.title(_"Survey")
    1.32 +ui.grid{ content = function()
    1.33 +  ui.cell_main{ content = function()
    1.34 +
    1.35 +    ui.container{ attr = { class = "mdl-card mdl-card__fullwidth mdl-shadow--2dp" }, content = function()
    1.36 +      ui.container{ attr = { class = "mdl-card__title mdl-card--border" }, content = function()
    1.37 +        ui.heading { attr = { class = "mdl-card__title-text" }, level = 2, content = survey.title }
    1.38 +        ui.container{ 
    1.39 +          content = _(
    1.40 +            "This survey closes in #{closing}.", 
    1.41 +            { closing = format.interval_text(survey.time_left) }
    1.42 +          )
    1.43 +        }
    1.44 +      end }
    1.45 +      ui.container{ attr = { class = "mdl-card__content mdl-card--border" }, content = function()
    1.46 +        if survey_member.finished then
    1.47 +          ui.container{ content = function()
    1.48 +            slot.put(survey.finished_text)
    1.49 +          end }
    1.50 +          slot.put("<br>")
    1.51 +          ui.link{
    1.52 +            attr = { class = "mdl-button mdl-js-button mdl-button--raised mdl-button--colored" },
    1.53 +            module = "index", view = "index", content = _"Go to start page"
    1.54 +          }
    1.55 +          return
    1.56 +        else
    1.57 +          ui.heading{ level = 2, content = question.question }
    1.58 +          if question.description then
    1.59 +            ui.container{ content = question.description }
    1.60 +          end
    1.61 +          ui.form{
    1.62 +            module = "survey", action = "answer",
    1.63 +            routing = {
    1.64 +              ok = { mode = "redirect", module = "survey", view = "participate" },
    1.65 +              error = { mode = "forward", module = "survey", view = "participate" },
    1.66 +            },
    1.67 +            content = function()
    1.68 +              ui.field.hidden{ name = "question_id", value = question.id }
    1.69 +              if question.answer_type == "radio" then
    1.70 +                for i, answer_option in ipairs(question.answer_options) do
    1.71 +                  ui.container{ content = function()
    1.72 +                    ui.tag{ tag = "label", attr = {
    1.73 +                        class = "mdl-radio mdl-js-radio mdl-js-ripple-effect",
    1.74 +                        ["for"] = "answer_" .. i
    1.75 +                      },
    1.76 +                      content = function()
    1.77 +                        ui.tag{
    1.78 +                          tag = "input",
    1.79 +                          attr = {
    1.80 +                            id = "answer_" .. i,
    1.81 +                            class = "mdl-radio__button",
    1.82 +                            type = "radio",
    1.83 +                            name = "answer",
    1.84 +                            value = answer_option,
    1.85 +                            checked = param.get("answer") == answer_option and "checked" or nil,
    1.86 +                          }
    1.87 +                        }
    1.88 +                        ui.tag{
    1.89 +                          attr = { class = "mdl-radio__label", ['for'] = "answer_" .. i },
    1.90 +                          content = answer_option
    1.91 +                        }
    1.92 +                      end
    1.93 +                    }
    1.94 +                  end }
    1.95 +                end
    1.96 +                slot.put("<br>")
    1.97 +                ui.tag{
    1.98 +                  tag = "input",
    1.99 +                  attr = {
   1.100 +                    type = "submit",
   1.101 +                    class = "mdl-button mdl-js-button mdl-button--raised mdl-button--colored",
   1.102 +                    value = _"Next step"
   1.103 +                  },
   1.104 +                  content = ""
   1.105 +                }
   1.106 +              end
   1.107 +            end
   1.108 +          }
   1.109 +        end
   1.110 +      end }
   1.111 +    end }
   1.112 +  end }
   1.113 +end }

Impressum / About Us