liquid_feedback_frontend
view app/main/survey/participate.lua @ 1745:49cb472e12d5
Fixed syntax error
| author | bsw | 
|---|---|
| date | Mon Oct 11 10:49:12 2021 +0200 (2021-10-11) | 
| parents | f5c41bffb3ff | 
| children | c7dbb36ce1e0 | 
 line source
     1 local survey = Survey:get_open()
     2 if not survey then
     3   return execute.view { module = "index", view = "404" }
     4 end
     6 local survey_member = SurveyMember:by_pk(survey.id, app.session.member_id)
     7 if not survey_member then
     8   return execute.view { module = "index", view = "404" }
     9 end
    11 local question
    13 if survey_member then
    14   local answer_set = survey_member.answer_set
    15   if answer_set then
    16     local answers_by_question_id = {}
    17     for i, answer in ipairs(answer_set.answers) do
    18       answers_by_question_id[answer.survey_question_id] = answer
    19     end
    20     for i, q in ipairs(survey.questions) do
    21       if not question and not answers_by_question_id[q.id] then
    22         question = q
    23       end
    24     end
    25   end
    26 end
    28 ui.title(survey.title)
    29 ui.grid{ content = function()
    30   ui.cell_main{ content = function()
    32     ui.container{ attr = { class = "mdl-card mdl-card__fullwidth mdl-shadow--2dp survey" }, content = function()
    33       ui.container{ attr = { class = "mdl-card__title mdl-card--border" }, content = function()
    34         ui.heading { attr = { class = "mdl-card__title-text" }, level = 2, content = question.question }
    35       end }
    36       ui.container{ attr = { class = "mdl-card__content mdl-card--border" }, content = function()
    37         if survey_member.finished then
    38           ui.container{ content = function()
    39             slot.put(survey.finished_text)
    40           end }
    41           slot.put("<br>")
    42           ui.link{
    43             attr = { class = "mdl-button mdl-js-button mdl-button--raised mdl-button--colored" },
    44             module = "index", view = "index", content = _"Go to start page"
    45           }
    46           return
    47         else
    48           if question.description then
    49             ui.container{ content = question.description }
    50           end
    51           ui.form{
    52             module = "survey", action = "answer",
    53             routing = {
    54               ok = { mode = "redirect", module = "survey", view = "participate" },
    55               error = { mode = "forward", module = "survey", view = "participate" },
    56             },
    57             content = function()
    58               ui.field.hidden{ name = "question_id", value = question.id }
    60               if question.answer_type == "radio" then
    61                 for i, answer_option in ipairs(question.answer_options) do
    62                   ui.container{ content = function()
    63                     ui.tag{ tag = "label", attr = {
    64                         class = "mdl-radio mdl-js-radio mdl-js-ripple-effect",
    65                         ["for"] = "answer_" .. i
    66                       },
    67                       content = function()
    68                         ui.tag{
    69                           tag = "input",
    70                           attr = {
    71                             id = "answer_" .. i,
    72                             class = "mdl-radio__button",
    73                             type = "radio",
    74                             name = "answer",
    75                             value = answer_option,
    76                             checked = param.get("answer") == answer_option and "checked" or nil,
    77                           }
    78                         }
    79                         ui.tag{
    80                           attr = { class = "mdl-radio__label", ['for'] = "answer_" .. i },
    81                           content = answer_option
    82                         }
    83                       end
    84                     }
    85                   end }
    86                 end
    88               elseif question.answer_type == "checkbox" then
    89                 for i, answer_option in ipairs(question.answer_options) do
    90                   ui.container{ content = function()
    91                     ui.tag{ tag = "label", attr = {
    92                         class = "mdl-checkbox mdl-js-checkbox mdl-js-ripple-effect",
    93                         ["for"] = "answer_" .. i
    94                       },
    95                       content = function()
    96                         ui.tag{
    97                           tag = "input",
    98                           attr = {
    99                             id = "answer_" .. i,
   100                             class = "mdl-checkbox__button",
   101                             type = "checkbox",
   102                             name = "answer_" .. answer_option,
   103                             value = "1",
   104                             checked = param.get("answer_" .. answer_option) and "checked" or nil,
   105                           }
   106                         }
   107                         ui.tag{
   108                           attr = { class = "mdl-checkbox__label", ['for'] = "answer_" .. i },
   109                           content = answer_option
   110                         }
   111                       end
   112                     }
   113                   end }
   114                 end
   115               end
   117               slot.put("<br>")
   118               ui.tag{
   119                 tag = "input",
   120                 attr = {
   121                   type = "submit",
   122                   class = "mdl-button mdl-js-button mdl-button--raised mdl-button--colored",
   123                   value = _"Next step"
   124                 },
   125                 content = ""
   126               }
   127             end
   128           }
   129         end
   130       end }
   131     end }
   132   end }
   133 end }
