liquid_feedback_frontend
view app/main/survey/participate.lua @ 1744:f5c41bffb3ff
Fixed syntax error
author | bsw |
---|---|
date | Mon Oct 11 10:48:00 2021 +0200 (2021-10-11) |
parents | 3d61fa0d6474 |
children | 49cb472e12d5 |
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 }
87 elseif question.answer_type == "checkbox" then
88 for i, answer_option in ipairs(question.answer_options) do
89 ui.container{ content = function()
90 ui.tag{ tag = "label", attr = {
91 class = "mdl-checkbox mdl-js-checkbox mdl-js-ripple-effect",
92 ["for"] = "answer_" .. i
93 },
94 content = function()
95 ui.tag{
96 tag = "input",
97 attr = {
98 id = "answer_" .. i,
99 class = "mdl-checkbox__button",
100 type = "checkbox",
101 name = "answer_" .. answer_option,
102 value = "1",
103 checked = param.get("answer_" .. answer_option) and "checked" or nil,
104 }
105 }
106 ui.tag{
107 attr = { class = "mdl-checkbox__label", ['for'] = "answer_" .. i },
108 content = answer_option
109 }
110 end
111 }
112 end }
113 end
115 slot.put("<br>")
116 ui.tag{
117 tag = "input",
118 attr = {
119 type = "submit",
120 class = "mdl-button mdl-js-button mdl-button--raised mdl-button--colored",
121 value = _"Next step"
122 },
123 content = ""
124 }
125 end
126 end
127 }
128 end
129 end }
130 end }
131 end }
132 end }