rev |
line source |
bsw/jbe@1309
|
1 for i, field in ipairs(config.self_registration.fields) do
|
bsw/jbe@1309
|
2 local class = ""
|
bsw/jbe@1309
|
3 local field_error = slot.get_content("self_registration__invalid_" .. field.name)
|
bsw/jbe@1309
|
4 if field_error == "" then
|
bsw/jbe@1309
|
5 field_error = nil
|
bsw/jbe@1309
|
6 end
|
bsw/jbe@1309
|
7 if field_error then
|
bsw/jbe@1309
|
8 class = " is-invalid"
|
bsw/jbe@1309
|
9 end
|
bsw@1684
|
10 if field.title then
|
bsw@1684
|
11 ui.container{ attr = { style = "font-weight: bold;" }, content = field.title }
|
bsw@1684
|
12 end
|
bsw@1684
|
13 if field.text then
|
bsw@1684
|
14 ui.container{ content = field.text }
|
bsw@1684
|
15 end
|
bsw@1359
|
16 if not field.internal then
|
bsw@1423
|
17 if field.type == "comment" then
|
bsw@1423
|
18 ui.tag { content = field.label }
|
bsw@1423
|
19 elseif field.name == "date_of_birth" then
|
bsw@1359
|
20 local label = field.label
|
bsw@1359
|
21 if field.optional then
|
bsw@1359
|
22 label = label .. config.self_registration.optional_field_indicator
|
bsw@1359
|
23 end
|
bsw@1359
|
24 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 .. ":" }
|
bsw@1359
|
25 slot.put(" ")
|
bsw@1359
|
26 local days = { { id = 0, name = _"day" } }
|
bsw@1359
|
27 for i = 1, 31 do
|
bsw@1359
|
28 table.insert(days, { id = i, name = i })
|
bsw@1359
|
29 end
|
bsw@1359
|
30 local months = {
|
bsw/jbe@1309
|
31 { id = 0, name = _"month" },
|
bsw@1359
|
32 { id = 1, name = "gennaio" },
|
bsw@1359
|
33 { id = 2, name = "febbraio" },
|
bsw@1359
|
34 { id = 3, name = "marzo" },
|
bsw@1359
|
35 { id = 4, name = "aprile" },
|
bsw@1359
|
36 { id = 5, name = "maggio" },
|
bsw@1359
|
37 { id = 6, name = "giugno" },
|
bsw@1359
|
38 { id = 7, name = "luglio" },
|
bsw@1359
|
39 { id = 8, name = "agosto" },
|
bsw@1359
|
40 { id = 9, name = "settembre" },
|
bsw@1359
|
41 { id = 10, name = "ottobre" },
|
bsw@1359
|
42 { id = 11, name = "novembre" },
|
bsw@1359
|
43 { id = 12, name = "dicembre" },
|
bsw@1359
|
44 }
|
bsw@1359
|
45 if config.self_registration.lang == "en" then
|
bsw@1359
|
46 months = {
|
bsw@1359
|
47 { id = 0, name = _"month" },
|
bsw@1359
|
48 { id = 1, name = "January" },
|
bsw@1359
|
49 { id = 2, name = "February" },
|
bsw@1359
|
50 { id = 3, name = "March" },
|
bsw@1359
|
51 { id = 4, name = "April" },
|
bsw@1359
|
52 { id = 5, name = "May" },
|
bsw@1359
|
53 { id = 6, name = "June" },
|
bsw@1359
|
54 { id = 7, name = "July" },
|
bsw@1359
|
55 { id = 8, name = "August" },
|
bsw@1359
|
56 { id = 9, name = "September" },
|
bsw@1359
|
57 { id = 10, name = "October" },
|
bsw@1359
|
58 { id = 11, name = "November" },
|
bsw@1359
|
59 { id = 12, name = "December" },
|
bsw@1359
|
60 }
|
bsw@1359
|
61 end
|
bsw@1490
|
62 if config.self_registration.lang == "de" then
|
bsw@1490
|
63 months = {
|
bsw@1490
|
64 { id = 0, name = _"month" },
|
bsw@1490
|
65 { id = 1, name = "Januar" },
|
bsw@1490
|
66 { id = 2, name = "Februar" },
|
bsw@1490
|
67 { id = 3, name = "März" },
|
bsw@1490
|
68 { id = 4, name = "April" },
|
bsw@1490
|
69 { id = 5, name = "Mai" },
|
bsw@1490
|
70 { id = 6, name = "Juni" },
|
bsw@1490
|
71 { id = 7, name = "Juli" },
|
bsw@1490
|
72 { id = 8, name = "August" },
|
bsw@1490
|
73 { id = 9, name = "September" },
|
bsw@1490
|
74 { id = 10, name = "Oktober" },
|
bsw@1490
|
75 { id = 11, name = "November" },
|
bsw@1490
|
76 { id = 12, name = "Dezember" },
|
bsw@1490
|
77 }
|
bsw@1490
|
78 end
|
bsw@1359
|
79 local years = { { id = 0, name = _"year" } }
|
bsw@1422
|
80 local min_age = config.self_registration.min_age or 16
|
bsw@1422
|
81 for i = (atom.date:get_current()).year - min_age, 1900, -1 do
|
bsw@1359
|
82 table.insert(years, { id = i, name = i })
|
bsw@1359
|
83 end
|
bsw@1359
|
84 ui.field.select{
|
bsw@1359
|
85 container_attr = { style = "display: inline-block; " },
|
bsw@1359
|
86 attr = { class = class },
|
bsw@1359
|
87 foreign_records = days,
|
bsw@1359
|
88 foreign_id = "id",
|
bsw@1359
|
89 foreign_name = "name",
|
bsw@1359
|
90 name = "verification_data_" .. field.name .. "_day",
|
bsw@1359
|
91 value = tonumber(request.get_param{ name = "verification_data_" .. field.name .. "_day" })
|
bsw@1359
|
92 }
|
bsw@1359
|
93 slot.put(" ")
|
bsw@1359
|
94 ui.field.select{
|
bsw@1359
|
95 container_attr = { style = "display: inline-block; " },
|
bsw@1359
|
96 attr = { class = class },
|
bsw@1359
|
97 foreign_records = months,
|
bsw@1359
|
98 foreign_id = "id",
|
bsw@1359
|
99 foreign_name = "name",
|
bsw@1359
|
100 name = "verification_data_" .. field.name .. "_month",
|
bsw@1359
|
101 value = tonumber(request.get_param{ name = "verification_data_" .. field.name .. "_month" })
|
bsw@1359
|
102 }
|
bsw@1359
|
103 slot.put(" ")
|
bsw@1359
|
104 ui.field.select{
|
bsw@1359
|
105 container_attr = { style = "display: inline-block; " },
|
bsw@1359
|
106 attr = { class = class },
|
bsw@1359
|
107 foreign_records = years,
|
bsw@1359
|
108 foreign_id = "id",
|
bsw@1359
|
109 foreign_name = "name",
|
bsw@1359
|
110 name = "verification_data_" .. field.name .. "_year",
|
bsw@1359
|
111 value = tonumber(request.get_param{ name = "verification_data_" .. field.name .. "_year" })
|
bsw@1359
|
112 }
|
bsw@1359
|
113 slot.put("<br />")
|
bsw@1377
|
114
|
bsw@1377
|
115 elseif field.type == "dropdown" then
|
bsw@1380
|
116 local options = { { id = "", name = "" } }
|
bsw@1684
|
117 local other_option_id
|
bsw@1377
|
118 for i_options, option in ipairs(field.options) do
|
bsw@1679
|
119 if not option.id then
|
bsw@1679
|
120 option.id = option.name
|
bsw@1679
|
121 end
|
bsw@1684
|
122 if option.other then
|
bsw@1684
|
123 other_option_id = option.id
|
bsw@1684
|
124 end
|
bsw@1377
|
125 table.insert(options, option)
|
bsw@1377
|
126 end
|
bsw@1684
|
127 if field.label then
|
bsw@1684
|
128 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 .. ":" }
|
bsw@1684
|
129 slot.put(" ")
|
bsw@1684
|
130 end
|
bsw@1684
|
131 local onchange_script
|
bsw@1684
|
132 if other_option_id then
|
bsw@1684
|
133 onchange_script = "var el = document.getElementById('lf-register__data_other_container_" .. field.name .. "'); if (this.value == '" .. other_option_id .. "') { console.log(el); el.classList.remove('hidden'); } else { el.classList.add('hidden'); };"
|
bsw@1684
|
134 end
|
bsw@1377
|
135 ui.field.select{
|
bsw@1377
|
136 container_attr = { style = "display: inline-block; " },
|
bsw@1684
|
137 attr = { class = class, onchange = onchange_script },
|
bsw@1377
|
138 foreign_records = options,
|
bsw@1377
|
139 foreign_id = "id",
|
bsw@1377
|
140 foreign_name = "name",
|
bsw@1377
|
141 name = "verification_data_" .. field.name,
|
bsw@1686
|
142 value = request.get_param{ name = "verification_data_" .. field.name }
|
bsw@1377
|
143 }
|
bsw@1684
|
144 if other_option_id then
|
bsw@1684
|
145 slot.put(" ")
|
bsw@1684
|
146 ui.field.text{
|
bsw@1684
|
147 container_attr = { id = "lf-register__data_other_container_" .. field.name, class = "hidden mdl-textfield mdl-js-textfield mdl-textfield--floating-label" .. class },
|
bsw@1684
|
148 attr = { id = "lf-register__data_other_" .. field.name, class = "mdl-textfield__input" },
|
bsw@1684
|
149 name = "verification_data_" .. field.name .. "_other",
|
bsw@1684
|
150 label_attr = { class = "mdl-textfield__label", ["for"] = "lf-register__data" .. field.name },
|
bsw@1684
|
151 label = field.name,
|
bsw@1684
|
152 value = request.get_param{ name = "verification_data_" .. field.name .. "_other" }
|
bsw@1684
|
153 }
|
bsw@1684
|
154 end
|
bsw@1381
|
155 slot.put("<br />")
|
bsw@1377
|
156
|
bsw@1685
|
157 elseif field.type == "multiselect" then
|
bsw@1685
|
158 local options = { { id = "", name = "" } }
|
bsw@1685
|
159 local other_option_id
|
bsw@1685
|
160 for i_options, option in ipairs(field.options) do
|
bsw@1685
|
161 if not option.id then
|
bsw@1685
|
162 option.id = option.name
|
bsw@1685
|
163 end
|
bsw@1685
|
164 local onchange_script
|
bsw@1685
|
165 if option.other then
|
bsw@1685
|
166 onchange_script = "var el = document.getElementById('lf-register__data_other_container_" .. field.name .. "'); if (this.checked) { console.log(el); el.classList.remove('hidden'); } else { el.classList.add('hidden'); };"
|
bsw@1685
|
167 end
|
bsw@1685
|
168 ui.container{ content = function()
|
bsw@1685
|
169 ui.tag{ tag = "label", attr = {
|
bsw@1685
|
170 class = "mdl-checkbox mdl-js-checkbox mdl-js-ripple-effect",
|
bsw@1685
|
171 style = "display: inline;",
|
bsw@1685
|
172 ["for"] = "verification_data_" .. field.name .. "__" .. option.id,
|
bsw@1685
|
173 },
|
bsw@1685
|
174 content = function()
|
bsw@1685
|
175 ui.tag{
|
bsw@1685
|
176 tag = "input",
|
bsw@1685
|
177 attr = {
|
bsw@1685
|
178 type = "checkbox",
|
bsw@1685
|
179 class = "mdl-checkbox__input",
|
bsw@1685
|
180 onchange = onchange_script,
|
bsw@1685
|
181 id = "verification_data_" .. field.name .. "__" .. option.id,
|
bsw@1685
|
182 name = "verification_data_" .. field.name .. "__" .. option.id,
|
bsw@1685
|
183 value = "1",
|
bsw@1685
|
184 style = "float: left;",
|
bsw@1685
|
185 checked = request.get_param{ name = "verification_data_" .. field.name .. "__" .. option.id } and "checked" or nil,
|
bsw@1685
|
186 }
|
bsw@1685
|
187 }
|
bsw@1685
|
188 ui.tag{
|
bsw@1685
|
189 attr = { class = "mdl-checkbox__label" },
|
bsw@1685
|
190 content = option.name
|
bsw@1685
|
191 }
|
bsw@1685
|
192 end
|
bsw@1685
|
193 }
|
bsw@1685
|
194 end }
|
bsw@1685
|
195 if option.other then
|
bsw@1685
|
196 slot.put(" ")
|
bsw@1685
|
197 ui.field.text{
|
bsw@1685
|
198 container_attr = { id = "lf-register__data_other_container_" .. field.name, class = "hidden mdl-textfield mdl-js-textfield mdl-textfield--floating-label" .. class },
|
bsw@1685
|
199 attr = { id = "lf-register__data_other_" .. field.name, class = "mdl-textfield__input" },
|
bsw@1685
|
200 name = "verification_data_" .. field.name .. "_other",
|
bsw@1685
|
201 label_attr = { class = "mdl-textfield__label", ["for"] = "lf-register__data" .. field.name },
|
bsw@1685
|
202 label = field.name,
|
bsw@1685
|
203 value = request.get_param{ name = "verification_data_" .. field.name .. "_other" }
|
bsw@1685
|
204 }
|
bsw@1685
|
205 end
|
bsw@1685
|
206 end
|
bsw@1685
|
207 slot.put("<br />")
|
bsw@1685
|
208
|
bsw@1359
|
209 elseif field.type == "image" then
|
bsw@1386
|
210 slot.put("<br />")
|
bsw@1392
|
211 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 .. ":" }
|
bsw@1392
|
212 slot.put("<br />")
|
bsw@1391
|
213 ui.script{ script = [[
|
bsw@1391
|
214 function getFile(){
|
bsw@1392
|
215 document.getElementById("fileInput").click();
|
bsw@1391
|
216 }
|
bsw@1391
|
217 function fileChoosen(obj){
|
bsw@1391
|
218 var file = obj.value;
|
bsw@1391
|
219 var fileName = file.split("\\");
|
bsw@1399
|
220 var checked = false;
|
bsw@1399
|
221 var label = "]] .. field.upload_label .. [[";
|
bsw@1402
|
222 if (fileName[fileName.length-1].length > 0) {
|
bsw@1398
|
223 label = fileName[fileName.length-1];
|
bsw@1398
|
224 }
|
bsw@1399
|
225 document.getElementById("fileBtn").innerHTML = label;
|
bsw@1391
|
226 event.preventDefault();
|
bsw@1391
|
227 }
|
bsw@1391
|
228 ]] }
|
bsw@1393
|
229 ui.tag{ tag = "input", attr = { id = "fileInput", style = "display: none;", type = "file", name = "verification_data_" .. field.name, onchange = "fileChoosen(this);" } }
|
bsw@1400
|
230 ui.tag{
|
bsw@1403
|
231 attr = { id = "fileBtn", class = "mdl-button mdl-js-button mdl-button--underlined", onclick = "getFile();" },
|
bsw@1400
|
232 content = field.upload_label
|
bsw@1395
|
233 }
|
bsw@1367
|
234 if field.optional_checkbox then
|
bsw@1391
|
235 slot.put(" ")
|
bsw@1375
|
236 ui.tag{ tag = "label", attr = {
|
bsw@1375
|
237 class = "mdl-checkbox mdl-js-checkbox mdl-js-ripple-effect",
|
bsw@1394
|
238 style = "display: inline;",
|
bsw@1375
|
239 ["for"] = "verification_data_" .. field.name .. "_optout"
|
bsw@1375
|
240 },
|
bsw@1375
|
241 content = function()
|
bsw@1375
|
242 ui.tag{
|
bsw@1375
|
243 tag = "input",
|
bsw@1375
|
244 attr = {
|
bsw@1375
|
245 type = "checkbox",
|
bsw@1375
|
246 class = "mdl-checkbox__input",
|
bsw@1375
|
247 id = "verification_data_" .. field.name .. "_optout",
|
bsw@1375
|
248 name = "verification_data_" .. field.name .. "_optout",
|
bsw@1375
|
249 value = "1",
|
bsw@1375
|
250 style = "float: left;",
|
bsw@1375
|
251 checked = request.get_param{ name = "verification_data_" .. field.name .. "_optout" } and "checked" or nil,
|
bsw@1375
|
252 }
|
bsw@1375
|
253 }
|
bsw@1375
|
254 ui.tag{
|
bsw@1375
|
255 attr = { class = "mdl-checkbox__label" },
|
bsw@1375
|
256 content = field.optional_checkbox
|
bsw@1375
|
257 }
|
bsw@1375
|
258 end
|
bsw@1375
|
259 }
|
bsw@1367
|
260 end
|
bsw@1359
|
261
|
bsw@1359
|
262 elseif field.name == "unit" then
|
bsw@1359
|
263 local units_selector = Unit:new_selector()
|
bsw@1359
|
264 :add_where{ "active" }
|
bsw@1412
|
265 :add_order_by("name")
|
bsw@1359
|
266 if field.where then
|
bsw@1359
|
267 units_selector:add_where(field.where)
|
bsw@1359
|
268 end
|
bsw@1683
|
269 local units = { { id = "", name = "" } }
|
bsw@1359
|
270 if field.optional then
|
bsw@1359
|
271 table.insert(units, {
|
bsw@1359
|
272 id = "",
|
bsw@1404
|
273 name = _"none"
|
bsw@1359
|
274 })
|
bsw@1359
|
275 end
|
bsw@1359
|
276 for i_unit, unit in ipairs(units_selector:exec()) do
|
bsw@1359
|
277 table.insert(units, unit)
|
bsw@1359
|
278 end
|
bsw@1382
|
279 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 .. ":" }
|
bsw@1382
|
280 slot.put(" ")
|
bsw@1359
|
281 ui.field.select{
|
bsw@1383
|
282 container_attr = { style = "display: inline-block; " },
|
bsw@1359
|
283 foreign_records = units,
|
bsw@1359
|
284 foreign_id = "id",
|
bsw@1359
|
285 foreign_name = "name",
|
bsw@1359
|
286 name = "verification_data_" .. field.name,
|
bsw@1359
|
287 value = tonumber(request.get_param{ name = "verification_data_" .. field.name })
|
bsw@1359
|
288 }
|
bsw@1386
|
289 slot.put("<br />")
|
bsw@1359
|
290 else
|
bsw@1359
|
291 if field.name == "mobile_phone" then
|
bsw@1359
|
292 if config.self_registration.lang ~= "en" then
|
bsw@1359
|
293 ui.tag{ content = "+39" }
|
bsw@1359
|
294 slot.put(" ")
|
bsw@1359
|
295 end
|
bsw@1359
|
296 end
|
bsw@1405
|
297 local label = field.label
|
bsw@1405
|
298 if field.optional then
|
bsw@1405
|
299 label = label .. config.self_registration.optional_field_indicator
|
bsw@1405
|
300 end
|
bsw@1359
|
301 ui.field.text{
|
bsw@1359
|
302 container_attr = { class = "mdl-textfield mdl-js-textfield mdl-textfield--floating-label" .. class },
|
bsw@1359
|
303 attr = { id = "lf-register__data_" .. field.name, class = "mdl-textfield__input" },
|
bsw@1359
|
304 label_attr = { class = "mdl-textfield__label", ["for"] = "lf-register__data" .. field.name },
|
bsw@1406
|
305 label = label,
|
bsw@1359
|
306 name = "verification_data_" .. field.name,
|
bsw@1359
|
307 value = request.get_param{ name = "verification_data_" .. field.name }
|
bsw/jbe@1309
|
308 }
|
bsw/jbe@1309
|
309 end
|
bsw@1327
|
310 slot.put("<br />")
|
bsw/jbe@1309
|
311 end
|
bsw/jbe@1309
|
312 end
|