rev |
line source |
bsw@1735
|
1 local survey = Survey:get_open()
|
bsw@1735
|
2 if not survey then
|
bsw@1735
|
3 return execute.view { module = "index", view = "404" }
|
bsw@1735
|
4 end
|
bsw@1735
|
5
|
bsw@1735
|
6 local survey_member = SurveyMember:by_pk(survey.id, app.session.member_id)
|
bsw@1735
|
7 if not survey_member then
|
bsw@1735
|
8 return execute.view { module = "index", view = "404" }
|
bsw@1735
|
9 end
|
bsw@1735
|
10
|
bsw@1735
|
11 local question
|
bsw@1752
|
12 local question_number = #survey.questions
|
bsw@1735
|
13
|
bsw@1735
|
14 if survey_member then
|
bsw@1735
|
15 local answer_set = survey_member.answer_set
|
bsw@1735
|
16 if answer_set then
|
bsw@1735
|
17 local answers_by_question_id = {}
|
bsw@1735
|
18 for i, answer in ipairs(answer_set.answers) do
|
bsw@1735
|
19 answers_by_question_id[answer.survey_question_id] = answer
|
bsw@1735
|
20 end
|
bsw@1735
|
21 for i, q in ipairs(survey.questions) do
|
bsw@1735
|
22 if not question and not answers_by_question_id[q.id] then
|
bsw@1735
|
23 question = q
|
bsw@1752
|
24 question_number = i - 1
|
bsw@1735
|
25 end
|
bsw@1735
|
26 end
|
bsw@1735
|
27 end
|
bsw@1735
|
28 end
|
bsw@1735
|
29
|
bsw@1742
|
30 ui.title(survey.title)
|
bsw@1735
|
31 ui.grid{ content = function()
|
bsw@1735
|
32 ui.cell_main{ content = function()
|
bsw@1735
|
33
|
bsw@1740
|
34 ui.container{ attr = { class = "mdl-card mdl-card__fullwidth mdl-shadow--2dp survey" }, content = function()
|
bsw@1752
|
35 ui.container{ attr = { class = "mdl-card__title" }, content = function()
|
bsw@1746
|
36 ui.heading { attr = { class = "mdl-card__title-text" }, level = 2, content = function()
|
bsw@1746
|
37 if survey_member.finished then
|
bsw@1746
|
38 slot.put(survey.finished_title)
|
bsw@1746
|
39 else
|
bsw@1752
|
40 ui.tag{ tag = "span", content = question.question }
|
bsw@1752
|
41 ui.tag{ attr = { class = "survey_counter" }, content = (question_number + 1) .. " / " .. #survey.questions }
|
bsw@1746
|
42 end
|
bsw@1747
|
43 end }
|
bsw@1735
|
44 end }
|
bsw@1752
|
45 slot.put('<div id = "progressbar1" style="width: 100%;" class = "mdl-progress mdl-js-progress"></div>')
|
bsw@1752
|
46
|
bsw@1752
|
47 ui.script{ script = [[
|
bsw@1752
|
48 document.querySelector('#progressbar1').addEventListener('mdl-componentupgraded',
|
bsw@1752
|
49 function() {
|
bsw@1752
|
50 this.MaterialProgress.setProgress(]] .. question_number / #survey.questions * 100 .. [[);
|
bsw@1752
|
51 });
|
bsw@1752
|
52
|
bsw@1752
|
53 ]] }
|
bsw@1735
|
54 ui.container{ attr = { class = "mdl-card__content mdl-card--border" }, content = function()
|
bsw@1735
|
55 if survey_member.finished then
|
bsw@1735
|
56 ui.container{ content = function()
|
bsw@1735
|
57 slot.put(survey.finished_text)
|
bsw@1735
|
58 end }
|
bsw@1735
|
59 slot.put("<br>")
|
bsw@1735
|
60 ui.link{
|
bsw@1735
|
61 attr = { class = "mdl-button mdl-js-button mdl-button--raised mdl-button--colored" },
|
bsw@1735
|
62 module = "index", view = "index", content = _"Go to start page"
|
bsw@1735
|
63 }
|
bsw@1735
|
64 return
|
bsw@1735
|
65 else
|
bsw@1735
|
66 if question.description then
|
bsw@1735
|
67 ui.container{ content = question.description }
|
bsw@1750
|
68 slot.put("<br>")
|
bsw@1735
|
69 end
|
bsw@1735
|
70 ui.form{
|
bsw@1735
|
71 module = "survey", action = "answer",
|
bsw@1735
|
72 routing = {
|
bsw@1735
|
73 ok = { mode = "redirect", module = "survey", view = "participate" },
|
bsw@1735
|
74 error = { mode = "forward", module = "survey", view = "participate" },
|
bsw@1735
|
75 },
|
bsw@1735
|
76 content = function()
|
bsw@1752
|
77
|
bsw@1735
|
78 ui.field.hidden{ name = "question_id", value = question.id }
|
bsw@1743
|
79
|
bsw@1735
|
80 if question.answer_type == "radio" then
|
bsw@1735
|
81 for i, answer_option in ipairs(question.answer_options) do
|
bsw@1735
|
82 ui.container{ content = function()
|
bsw@1735
|
83 ui.tag{ tag = "label", attr = {
|
bsw@1735
|
84 class = "mdl-radio mdl-js-radio mdl-js-ripple-effect",
|
bsw@1735
|
85 ["for"] = "answer_" .. i
|
bsw@1735
|
86 },
|
bsw@1735
|
87 content = function()
|
bsw@1735
|
88 ui.tag{
|
bsw@1735
|
89 tag = "input",
|
bsw@1735
|
90 attr = {
|
bsw@1735
|
91 id = "answer_" .. i,
|
bsw@1735
|
92 class = "mdl-radio__button",
|
bsw@1735
|
93 type = "radio",
|
bsw@1735
|
94 name = "answer",
|
bsw@1735
|
95 value = answer_option,
|
bsw@1735
|
96 checked = param.get("answer") == answer_option and "checked" or nil,
|
bsw@1735
|
97 }
|
bsw@1735
|
98 }
|
bsw@1735
|
99 ui.tag{
|
bsw@1735
|
100 attr = { class = "mdl-radio__label", ['for'] = "answer_" .. i },
|
bsw@1735
|
101 content = answer_option
|
bsw@1735
|
102 }
|
bsw@1735
|
103 end
|
bsw@1735
|
104 }
|
bsw@1735
|
105 end }
|
bsw@1745
|
106 end
|
bsw@1743
|
107
|
bsw@1744
|
108 elseif question.answer_type == "checkbox" then
|
bsw@1743
|
109 for i, answer_option in ipairs(question.answer_options) do
|
bsw@1743
|
110 ui.container{ content = function()
|
bsw@1743
|
111 ui.tag{ tag = "label", attr = {
|
bsw@1743
|
112 class = "mdl-checkbox mdl-js-checkbox mdl-js-ripple-effect",
|
bsw@1743
|
113 ["for"] = "answer_" .. i
|
bsw@1743
|
114 },
|
bsw@1743
|
115 content = function()
|
bsw@1743
|
116 ui.tag{
|
bsw@1743
|
117 tag = "input",
|
bsw@1743
|
118 attr = {
|
bsw@1743
|
119 id = "answer_" .. i,
|
bsw@1749
|
120 class = "mdl-checkbox__input",
|
bsw@1743
|
121 type = "checkbox",
|
bsw@1743
|
122 name = "answer_" .. answer_option,
|
bsw@1743
|
123 value = "1",
|
bsw@1743
|
124 checked = param.get("answer_" .. answer_option) and "checked" or nil,
|
bsw@1743
|
125 }
|
bsw@1743
|
126 }
|
bsw@1743
|
127 ui.tag{
|
bsw@1743
|
128 attr = { class = "mdl-checkbox__label", ['for'] = "answer_" .. i },
|
bsw@1743
|
129 content = answer_option
|
bsw@1743
|
130 }
|
bsw@1743
|
131 end
|
bsw@1743
|
132 }
|
bsw@1743
|
133 end }
|
bsw@1735
|
134 end
|
bsw@1745
|
135 end
|
bsw@1743
|
136
|
bsw@1745
|
137 slot.put("<br>")
|
bsw@1745
|
138 ui.tag{
|
bsw@1745
|
139 tag = "input",
|
bsw@1745
|
140 attr = {
|
bsw@1745
|
141 type = "submit",
|
bsw@1745
|
142 class = "mdl-button mdl-js-button mdl-button--raised mdl-button--colored",
|
bsw@1745
|
143 value = _"Next step"
|
bsw@1745
|
144 },
|
bsw@1745
|
145 content = ""
|
bsw@1745
|
146 }
|
bsw@1735
|
147 end
|
bsw@1735
|
148 }
|
bsw@1735
|
149 end
|
bsw@1735
|
150 end }
|
bsw@1735
|
151 end }
|
bsw@1735
|
152 end }
|
bsw@1735
|
153 end }
|