liquid_feedback_frontend

view app/main/survey/participate.lua @ 1742:9f96b7e6e5f2

Changed layout of survey
author bsw
date Mon Oct 11 10:39:23 2021 +0200 (2021-10-11)
parents 772c18d87b54
children 3d61fa0d6474
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 }
59 if question.answer_type == "radio" then
60 for i, answer_option in ipairs(question.answer_options) do
61 ui.container{ content = function()
62 ui.tag{ tag = "label", attr = {
63 class = "mdl-radio mdl-js-radio mdl-js-ripple-effect",
64 ["for"] = "answer_" .. i
65 },
66 content = function()
67 ui.tag{
68 tag = "input",
69 attr = {
70 id = "answer_" .. i,
71 class = "mdl-radio__button",
72 type = "radio",
73 name = "answer",
74 value = answer_option,
75 checked = param.get("answer") == answer_option and "checked" or nil,
76 }
77 }
78 ui.tag{
79 attr = { class = "mdl-radio__label", ['for'] = "answer_" .. i },
80 content = answer_option
81 }
82 end
83 }
84 end }
85 end
86 slot.put("<br>")
87 ui.tag{
88 tag = "input",
89 attr = {
90 type = "submit",
91 class = "mdl-button mdl-js-button mdl-button--raised mdl-button--colored",
92 value = _"Next step"
93 },
94 content = ""
95 }
96 end
97 end
98 }
99 end
100 end }
101 end }
102 end }
103 end }

Impressum / About Us