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