liquid_feedback_frontend

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

Impressum / About Us