liquid_feedback_frontend

view app/main/survey/participate.lua @ 1746:c7dbb36ce1e0

Show finished title at end of survey
author bsw
date Mon Oct 11 10:51:56 2021 +0200 (2021-10-11)
parents 49cb472e12d5
children eb34fe00cf5c
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 }
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 end
57 ui.form{
58 module = "survey", action = "answer",
59 routing = {
60 ok = { mode = "redirect", module = "survey", view = "participate" },
61 error = { mode = "forward", module = "survey", view = "participate" },
62 },
63 content = function()
64 ui.field.hidden{ name = "question_id", value = question.id }
66 if question.answer_type == "radio" then
67 for i, answer_option in ipairs(question.answer_options) do
68 ui.container{ content = function()
69 ui.tag{ tag = "label", attr = {
70 class = "mdl-radio mdl-js-radio mdl-js-ripple-effect",
71 ["for"] = "answer_" .. i
72 },
73 content = function()
74 ui.tag{
75 tag = "input",
76 attr = {
77 id = "answer_" .. i,
78 class = "mdl-radio__button",
79 type = "radio",
80 name = "answer",
81 value = answer_option,
82 checked = param.get("answer") == answer_option and "checked" or nil,
83 }
84 }
85 ui.tag{
86 attr = { class = "mdl-radio__label", ['for'] = "answer_" .. i },
87 content = answer_option
88 }
89 end
90 }
91 end }
92 end
94 elseif question.answer_type == "checkbox" then
95 for i, answer_option in ipairs(question.answer_options) do
96 ui.container{ content = function()
97 ui.tag{ tag = "label", attr = {
98 class = "mdl-checkbox mdl-js-checkbox mdl-js-ripple-effect",
99 ["for"] = "answer_" .. i
100 },
101 content = function()
102 ui.tag{
103 tag = "input",
104 attr = {
105 id = "answer_" .. i,
106 class = "mdl-checkbox__button",
107 type = "checkbox",
108 name = "answer_" .. answer_option,
109 value = "1",
110 checked = param.get("answer_" .. answer_option) and "checked" or nil,
111 }
112 }
113 ui.tag{
114 attr = { class = "mdl-checkbox__label", ['for'] = "answer_" .. i },
115 content = answer_option
116 }
117 end
118 }
119 end }
120 end
121 end
123 slot.put("<br>")
124 ui.tag{
125 tag = "input",
126 attr = {
127 type = "submit",
128 class = "mdl-button mdl-js-button mdl-button--raised mdl-button--colored",
129 value = _"Next step"
130 },
131 content = ""
132 }
133 end
134 }
135 end
136 end }
137 end }
138 end }
139 end }

Impressum / About Us