liquid_feedback_frontend
view app/main/registration/_register_form.lua @ 1564:15f33adc0e31
Fixed layout in revoke initiative view
| author | bsw |
|---|---|
| date | Tue Nov 10 21:09:34 2020 +0100 (2020-11-10) |
| parents | 63ce1a5c05c1 |
| children | ac45e0fe1221 |
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 if config.self_registration.lang == "de" then
57 months = {
58 { id = 0, name = _"month" },
59 { id = 1, name = "Januar" },
60 { id = 2, name = "Februar" },
61 { id = 3, name = "März" },
62 { id = 4, name = "April" },
63 { id = 5, name = "Mai" },
64 { id = 6, name = "Juni" },
65 { id = 7, name = "Juli" },
66 { id = 8, name = "August" },
67 { id = 9, name = "September" },
68 { id = 10, name = "Oktober" },
69 { id = 11, name = "November" },
70 { id = 12, name = "Dezember" },
71 }
72 end
73 local years = { { id = 0, name = _"year" } }
74 local min_age = config.self_registration.min_age or 16
75 for i = (atom.date:get_current()).year - min_age, 1900, -1 do
76 table.insert(years, { id = i, name = i })
77 end
78 ui.field.select{
79 container_attr = { style = "display: inline-block; " },
80 attr = { class = class },
81 foreign_records = days,
82 foreign_id = "id",
83 foreign_name = "name",
84 name = "verification_data_" .. field.name .. "_day",
85 value = tonumber(request.get_param{ name = "verification_data_" .. field.name .. "_day" })
86 }
87 slot.put(" ")
88 ui.field.select{
89 container_attr = { style = "display: inline-block; " },
90 attr = { class = class },
91 foreign_records = months,
92 foreign_id = "id",
93 foreign_name = "name",
94 name = "verification_data_" .. field.name .. "_month",
95 value = tonumber(request.get_param{ name = "verification_data_" .. field.name .. "_month" })
96 }
97 slot.put(" ")
98 ui.field.select{
99 container_attr = { style = "display: inline-block; " },
100 attr = { class = class },
101 foreign_records = years,
102 foreign_id = "id",
103 foreign_name = "name",
104 name = "verification_data_" .. field.name .. "_year",
105 value = tonumber(request.get_param{ name = "verification_data_" .. field.name .. "_year" })
106 }
107 slot.put("<br />")
109 elseif field.type == "dropdown" then
110 local options = { { id = "", name = "" } }
111 for i_options, option in ipairs(field.options) do
112 table.insert(options, option)
113 end
114 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 .. ":" }
115 slot.put(" ")
116 ui.field.select{
117 container_attr = { style = "display: inline-block; " },
118 attr = { class = class },
119 foreign_records = options,
120 foreign_id = "id",
121 foreign_name = "name",
122 name = "verification_data_" .. field.name,
123 value = tonumber(request.get_param{ name = "verification_data_" .. field.name })
124 }
125 slot.put("<br />")
127 elseif field.type == "image" then
128 slot.put("<br />")
129 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 .. ":" }
130 slot.put("<br />")
131 ui.script{ script = [[
132 function getFile(){
133 document.getElementById("fileInput").click();
134 }
135 function fileChoosen(obj){
136 var file = obj.value;
137 var fileName = file.split("\\");
138 var checked = false;
139 var label = "]] .. field.upload_label .. [[";
140 if (fileName[fileName.length-1].length > 0) {
141 label = fileName[fileName.length-1];
142 }
143 document.getElementById("fileBtn").innerHTML = label;
144 event.preventDefault();
145 }
146 ]] }
147 ui.tag{ tag = "input", attr = { id = "fileInput", style = "display: none;", type = "file", name = "verification_data_" .. field.name, onchange = "fileChoosen(this);" } }
148 ui.tag{
149 attr = { id = "fileBtn", class = "mdl-button mdl-js-button mdl-button--underlined", onclick = "getFile();" },
150 content = field.upload_label
151 }
152 if field.optional_checkbox then
153 slot.put(" ")
154 ui.tag{ tag = "label", attr = {
155 class = "mdl-checkbox mdl-js-checkbox mdl-js-ripple-effect",
156 style = "display: inline;",
157 ["for"] = "verification_data_" .. field.name .. "_optout"
158 },
159 content = function()
160 ui.tag{
161 tag = "input",
162 attr = {
163 type = "checkbox",
164 class = "mdl-checkbox__input",
165 id = "verification_data_" .. field.name .. "_optout",
166 name = "verification_data_" .. field.name .. "_optout",
167 value = "1",
168 style = "float: left;",
169 checked = request.get_param{ name = "verification_data_" .. field.name .. "_optout" } and "checked" or nil,
170 }
171 }
172 ui.tag{
173 attr = { class = "mdl-checkbox__label" },
174 content = field.optional_checkbox
175 }
176 end
177 }
178 end
180 elseif field.name == "unit" then
181 local units_selector = Unit:new_selector()
182 :add_where{ "active" }
183 :add_order_by("name")
184 if field.where then
185 units_selector:add_where(field.where)
186 end
187 local units = {}
188 if field.optional then
189 table.insert(units, {
190 id = "",
191 name = _"none"
192 })
193 end
194 for i_unit, unit in ipairs(units_selector:exec()) do
195 table.insert(units, unit)
196 end
197 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 .. ":" }
198 slot.put(" ")
199 ui.field.select{
200 container_attr = { style = "display: inline-block; " },
201 foreign_records = units,
202 foreign_id = "id",
203 foreign_name = "name",
204 name = "verification_data_" .. field.name,
205 value = tonumber(request.get_param{ name = "verification_data_" .. field.name })
206 }
207 slot.put("<br />")
208 else
209 if field.name == "mobile_phone" then
210 if config.self_registration.lang ~= "en" then
211 ui.tag{ content = "+39" }
212 slot.put(" ")
213 end
214 end
215 local label = field.label
216 if field.optional then
217 label = label .. config.self_registration.optional_field_indicator
218 end
219 ui.field.text{
220 container_attr = { class = "mdl-textfield mdl-js-textfield mdl-textfield--floating-label" .. class },
221 attr = { id = "lf-register__data_" .. field.name, class = "mdl-textfield__input" },
222 label_attr = { class = "mdl-textfield__label", ["for"] = "lf-register__data" .. field.name },
223 label = label,
224 name = "verification_data_" .. field.name,
225 value = request.get_param{ name = "verification_data_" .. field.name }
226 }
227 end
228 slot.put("<br />")
229 end
230 end
