liquid_feedback_frontend

view app/main/survey/participate.lua @ 1750:d15767492064

Add newline between description and answers
author bsw
date Mon Oct 11 11:03:04 2021 +0200 (2021-10-11)
parents c723f01a092f
children 6d69bc46440e
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 = function()
35 if survey_member.finished then
36 slot.put(survey.finished_title)
37 else
38 ui.tag{ content = question.question }
39 end
40 end }
41 end }
42 ui.container{ attr = { class = "mdl-card__content mdl-card--border" }, content = function()
43 if survey_member.finished then
44 ui.container{ content = function()
45 slot.put(survey.finished_text)
46 end }
47 slot.put("<br>")
48 ui.link{
49 attr = { class = "mdl-button mdl-js-button mdl-button--raised mdl-button--colored" },
50 module = "index", view = "index", content = _"Go to start page"
51 }
52 return
53 else
54 if question.description then
55 ui.container{ content = question.description }
56 slot.put("<br>")
57 end
58 ui.form{
59 module = "survey", action = "answer",
60 routing = {
61 ok = { mode = "redirect", module = "survey", view = "participate" },
62 error = { mode = "forward", module = "survey", view = "participate" },
63 },
64 content = function()
65 ui.field.hidden{ name = "question_id", value = question.id }
67 if question.answer_type == "radio" then
68 for i, answer_option in ipairs(question.answer_options) do
69 ui.container{ content = function()
70 ui.tag{ tag = "label", attr = {
71 class = "mdl-radio mdl-js-radio mdl-js-ripple-effect",
72 ["for"] = "answer_" .. i
73 },
74 content = function()
75 ui.tag{
76 tag = "input",
77 attr = {
78 id = "answer_" .. i,
79 class = "mdl-radio__button",
80 type = "radio",
81 name = "answer",
82 value = answer_option,
83 checked = param.get("answer") == answer_option and "checked" or nil,
84 }
85 }
86 ui.tag{
87 attr = { class = "mdl-radio__label", ['for'] = "answer_" .. i },
88 content = answer_option
89 }
90 end
91 }
92 end }
93 end
95 elseif question.answer_type == "checkbox" then
96 for i, answer_option in ipairs(question.answer_options) do
97 ui.container{ content = function()
98 ui.tag{ tag = "label", attr = {
99 class = "mdl-checkbox mdl-js-checkbox mdl-js-ripple-effect",
100 ["for"] = "answer_" .. i
101 },
102 content = function()
103 ui.tag{
104 tag = "input",
105 attr = {
106 id = "answer_" .. i,
107 class = "mdl-checkbox__input",
108 type = "checkbox",
109 name = "answer_" .. answer_option,
110 value = "1",
111 checked = param.get("answer_" .. answer_option) and "checked" or nil,
112 }
113 }
114 ui.tag{
115 attr = { class = "mdl-checkbox__label", ['for'] = "answer_" .. i },
116 content = answer_option
117 }
118 end
119 }
120 end }
121 end
122 end
124 slot.put("<br>")
125 ui.tag{
126 tag = "input",
127 attr = {
128 type = "submit",
129 class = "mdl-button mdl-js-button mdl-button--raised mdl-button--colored",
130 value = _"Next step"
131 },
132 content = ""
133 }
134 end
135 }
136 end
137 end }
138 end }
139 end }
140 end }

Impressum / About Us