liquid_feedback_frontend

view app/main/registration/_register_form.lua @ 1423:4232b30dfb11

Allow additional comments in registration form
author bsw
date Thu Sep 20 13:49:19 2018 +0200 (2018-09-20)
parents 6c9729cbff73
children 63ce1a5c05c1
line source
1 for i, field in ipairs(config.self_registration.fields) do
2 local class = ""
3 local field_error = slot.get_content("self_registration__invalid_" .. field.name)
4 if field_error == "" then
5 field_error = nil
6 end
7 if field_error then
8 class = " is-invalid"
9 end
10 if not field.internal then
11 if field.type == "comment" then
12 ui.tag { content = field.label }
13 elseif field.name == "date_of_birth" then
14 local label = field.label
15 if field.optional then
16 label = label .. config.self_registration.optional_field_indicator
17 end
18 ui.tag{ tag = "label", attr = { style = "vertical-align: bottom; border-bottom: 1px solid rgba(0,0,0, 0.12); color: #777; font-size: 16px;" }, content = field.label .. ":" }
19 slot.put("   ")
20 local days = { { id = 0, name = _"day" } }
21 for i = 1, 31 do
22 table.insert(days, { id = i, name = i })
23 end
24 local months = {
25 { id = 0, name = _"month" },
26 { id = 1, name = "gennaio" },
27 { id = 2, name = "febbraio" },
28 { id = 3, name = "marzo" },
29 { id = 4, name = "aprile" },
30 { id = 5, name = "maggio" },
31 { id = 6, name = "giugno" },
32 { id = 7, name = "luglio" },
33 { id = 8, name = "agosto" },
34 { id = 9, name = "settembre" },
35 { id = 10, name = "ottobre" },
36 { id = 11, name = "novembre" },
37 { id = 12, name = "dicembre" },
38 }
39 if config.self_registration.lang == "en" then
40 months = {
41 { id = 0, name = _"month" },
42 { id = 1, name = "January" },
43 { id = 2, name = "February" },
44 { id = 3, name = "March" },
45 { id = 4, name = "April" },
46 { id = 5, name = "May" },
47 { id = 6, name = "June" },
48 { id = 7, name = "July" },
49 { id = 8, name = "August" },
50 { id = 9, name = "September" },
51 { id = 10, name = "October" },
52 { id = 11, name = "November" },
53 { id = 12, name = "December" },
54 }
55 end
56 local years = { { id = 0, name = _"year" } }
57 local min_age = config.self_registration.min_age or 16
58 for i = (atom.date:get_current()).year - min_age, 1900, -1 do
59 table.insert(years, { id = i, name = i })
60 end
61 ui.field.select{
62 container_attr = { style = "display: inline-block; " },
63 attr = { class = class },
64 foreign_records = days,
65 foreign_id = "id",
66 foreign_name = "name",
67 name = "verification_data_" .. field.name .. "_day",
68 value = tonumber(request.get_param{ name = "verification_data_" .. field.name .. "_day" })
69 }
70 slot.put("   ")
71 ui.field.select{
72 container_attr = { style = "display: inline-block; " },
73 attr = { class = class },
74 foreign_records = months,
75 foreign_id = "id",
76 foreign_name = "name",
77 name = "verification_data_" .. field.name .. "_month",
78 value = tonumber(request.get_param{ name = "verification_data_" .. field.name .. "_month" })
79 }
80 slot.put("   ")
81 ui.field.select{
82 container_attr = { style = "display: inline-block; " },
83 attr = { class = class },
84 foreign_records = years,
85 foreign_id = "id",
86 foreign_name = "name",
87 name = "verification_data_" .. field.name .. "_year",
88 value = tonumber(request.get_param{ name = "verification_data_" .. field.name .. "_year" })
89 }
90 slot.put("<br />")
92 elseif field.type == "dropdown" then
93 local options = { { id = "", name = "" } }
94 for i_options, option in ipairs(field.options) do
95 table.insert(options, option)
96 end
97 ui.tag{ tag = "label", attr = { style = "vertical-align: bottom; border-bottom: 1px solid rgba(0,0,0, 0.12); color: #777; font-size: 16px;" }, content = field.label .. ":" }
98 slot.put(" &nbsp; ")
99 ui.field.select{
100 container_attr = { style = "display: inline-block; " },
101 attr = { class = class },
102 foreign_records = options,
103 foreign_id = "id",
104 foreign_name = "name",
105 name = "verification_data_" .. field.name,
106 value = tonumber(request.get_param{ name = "verification_data_" .. field.name })
107 }
108 slot.put("<br />")
110 elseif field.type == "image" then
111 slot.put("<br />")
112 ui.tag{ tag = "label", attr = { style = "vertical-align: bottom; border-bottom: 1px solid rgba(0,0,0, 0.12); color: #777; font-size: 16px;" }, content = field.label .. ":" }
113 slot.put("<br />")
114 ui.script{ script = [[
115 function getFile(){
116 document.getElementById("fileInput").click();
117 }
118 function fileChoosen(obj){
119 var file = obj.value;
120 var fileName = file.split("\\");
121 var checked = false;
122 var label = "]] .. field.upload_label .. [[";
123 if (fileName[fileName.length-1].length > 0) {
124 label = fileName[fileName.length-1];
125 }
126 document.getElementById("fileBtn").innerHTML = label;
127 event.preventDefault();
128 }
129 ]] }
130 ui.tag{ tag = "input", attr = { id = "fileInput", style = "display: none;", type = "file", name = "verification_data_" .. field.name, onchange = "fileChoosen(this);" } }
131 ui.tag{
132 attr = { id = "fileBtn", class = "mdl-button mdl-js-button mdl-button--underlined", onclick = "getFile();" },
133 content = field.upload_label
134 }
135 if field.optional_checkbox then
136 slot.put(" &nbsp; ")
137 ui.tag{ tag = "label", attr = {
138 class = "mdl-checkbox mdl-js-checkbox mdl-js-ripple-effect",
139 style = "display: inline;",
140 ["for"] = "verification_data_" .. field.name .. "_optout"
141 },
142 content = function()
143 ui.tag{
144 tag = "input",
145 attr = {
146 type = "checkbox",
147 class = "mdl-checkbox__input",
148 id = "verification_data_" .. field.name .. "_optout",
149 name = "verification_data_" .. field.name .. "_optout",
150 value = "1",
151 style = "float: left;",
152 checked = request.get_param{ name = "verification_data_" .. field.name .. "_optout" } and "checked" or nil,
153 }
154 }
155 ui.tag{
156 attr = { class = "mdl-checkbox__label" },
157 content = field.optional_checkbox
158 }
159 end
160 }
161 end
163 elseif field.name == "unit" then
164 local units_selector = Unit:new_selector()
165 :add_where{ "active" }
166 :add_order_by("name")
167 if field.where then
168 units_selector:add_where(field.where)
169 end
170 local units = {}
171 if field.optional then
172 table.insert(units, {
173 id = "",
174 name = _"none"
175 })
176 end
177 for i_unit, unit in ipairs(units_selector:exec()) do
178 table.insert(units, unit)
179 end
180 ui.tag{ tag = "label", attr = { style = "vertical-align: bottom; border-bottom: 1px solid rgba(0,0,0, 0.12); color: #777; font-size: 16px;" }, content = field.label .. ":" }
181 slot.put(" &nbsp; ")
182 ui.field.select{
183 container_attr = { style = "display: inline-block; " },
184 foreign_records = units,
185 foreign_id = "id",
186 foreign_name = "name",
187 name = "verification_data_" .. field.name,
188 value = tonumber(request.get_param{ name = "verification_data_" .. field.name })
189 }
190 slot.put("<br />")
191 else
192 if field.name == "mobile_phone" then
193 if config.self_registration.lang ~= "en" then
194 ui.tag{ content = "+39" }
195 slot.put(" ")
196 end
197 end
198 local label = field.label
199 if field.optional then
200 label = label .. config.self_registration.optional_field_indicator
201 end
202 ui.field.text{
203 container_attr = { class = "mdl-textfield mdl-js-textfield mdl-textfield--floating-label" .. class },
204 attr = { id = "lf-register__data_" .. field.name, class = "mdl-textfield__input" },
205 label_attr = { class = "mdl-textfield__label", ["for"] = "lf-register__data" .. field.name },
206 label = label,
207 name = "verification_data_" .. field.name,
208 value = request.get_param{ name = "verification_data_" .. field.name }
209 }
210 end
211 slot.put("<br />")
212 end
213 end

Impressum / About Us