liquid_feedback_frontend
view app/main/registration/_register_form.lua @ 1393:a0ee4204f6c1
Changed style of register image upload 3
| author | bsw |
|---|---|
| date | Mon Aug 13 19:20:15 2018 +0200 (2018-08-13) |
| parents | 41e3da074385 |
| children | eb0b7f728ed8 |
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 for i = 2002, 1900, -1 do
56 table.insert(years, { id = i, name = i })
57 end
58 ui.field.select{
59 container_attr = { style = "display: inline-block; " },
60 attr = { class = class },
61 foreign_records = days,
62 foreign_id = "id",
63 foreign_name = "name",
64 name = "verification_data_" .. field.name .. "_day",
65 value = tonumber(request.get_param{ name = "verification_data_" .. field.name .. "_day" })
66 }
67 slot.put(" ")
68 ui.field.select{
69 container_attr = { style = "display: inline-block; " },
70 attr = { class = class },
71 foreign_records = months,
72 foreign_id = "id",
73 foreign_name = "name",
74 name = "verification_data_" .. field.name .. "_month",
75 value = tonumber(request.get_param{ name = "verification_data_" .. field.name .. "_month" })
76 }
77 slot.put(" ")
78 ui.field.select{
79 container_attr = { style = "display: inline-block; " },
80 attr = { class = class },
81 foreign_records = years,
82 foreign_id = "id",
83 foreign_name = "name",
84 name = "verification_data_" .. field.name .. "_year",
85 value = tonumber(request.get_param{ name = "verification_data_" .. field.name .. "_year" })
86 }
87 slot.put("<br />")
89 elseif field.type == "dropdown" then
90 local options = { { id = "", name = "" } }
91 for i_options, option in ipairs(field.options) do
92 table.insert(options, option)
93 end
94 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 .. ":" }
95 slot.put(" ")
96 ui.field.select{
97 container_attr = { style = "display: inline-block; " },
98 attr = { class = class },
99 foreign_records = options,
100 foreign_id = "id",
101 foreign_name = "name",
102 name = "verification_data_" .. field.name,
103 value = tonumber(request.get_param{ name = "verification_data_" .. field.name })
104 }
105 slot.put("<br />")
107 elseif field.type == "image" then
108 slot.put("<br />")
109 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 .. ":" }
110 slot.put("<br />")
111 ui.script{ script = [[
112 function getFile(){
113 document.getElementById("fileInput").click();
114 }
115 function fileChoosen(obj){
116 var file = obj.value;
117 var fileName = file.split("\\");
118 document.getElementById("fileBtn").innerHTML = fileName[fileName.length-1];
119 event.preventDefault();
120 }
121 ]] }
122 ui.tag{ tag = "input", attr = { id = "fileInput", style = "display: none;", type = "file", name = "verification_data_" .. field.name, onchange = "fileChoosen(this);" } }
123 ui.tag{ attr = { id = "fileBtn", onclick = "getFile();"}, content = field.upload_label }
124 if field.optional_checkbox then
125 slot.put(" ")
126 ui.tag{ tag = "label", attr = {
127 class = "mdl-checkbox mdl-js-checkbox mdl-js-ripple-effect",
128 ["for"] = "verification_data_" .. field.name .. "_optout"
129 },
130 content = function()
131 ui.tag{
132 tag = "input",
133 attr = {
134 type = "checkbox",
135 class = "mdl-checkbox__input",
136 id = "verification_data_" .. field.name .. "_optout",
137 name = "verification_data_" .. field.name .. "_optout",
138 value = "1",
139 style = "float: left;",
140 checked = request.get_param{ name = "verification_data_" .. field.name .. "_optout" } and "checked" or nil,
141 }
142 }
143 ui.tag{
144 attr = { class = "mdl-checkbox__label" },
145 content = field.optional_checkbox
146 }
147 end
148 }
149 end
151 elseif field.name == "unit" then
152 local units_selector = Unit:new_selector()
153 :add_where{ "active" }
154 if field.where then
155 units_selector:add_where(field.where)
156 end
157 local units = {}
158 if field.optional then
159 table.insert(units, {
160 id = "",
161 name = _"None"
162 })
163 end
164 for i_unit, unit in ipairs(units_selector:exec()) do
165 table.insert(units, unit)
166 end
167 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 .. ":" }
168 slot.put(" ")
169 ui.field.select{
170 container_attr = { style = "display: inline-block; " },
171 foreign_records = units,
172 foreign_id = "id",
173 foreign_name = "name",
174 name = "verification_data_" .. field.name,
175 value = tonumber(request.get_param{ name = "verification_data_" .. field.name })
176 }
177 slot.put("<br />")
178 else
179 if field.name == "mobile_phone" then
180 if config.self_registration.lang ~= "en" then
181 ui.tag{ content = "+39" }
182 slot.put(" ")
183 end
184 end
185 ui.field.text{
186 container_attr = { class = "mdl-textfield mdl-js-textfield mdl-textfield--floating-label" .. class },
187 attr = { id = "lf-register__data_" .. field.name, class = "mdl-textfield__input" },
188 label_attr = { class = "mdl-textfield__label", ["for"] = "lf-register__data" .. field.name },
189 label = field.label,
190 name = "verification_data_" .. field.name,
191 value = request.get_param{ name = "verification_data_" .. field.name }
192 }
193 end
194 slot.put("<br />")
195 end
196 end
