bsw/jbe@1309: for i, field in ipairs(config.self_registration.fields) do bsw/jbe@1309: local class = "" bsw/jbe@1309: local field_error = slot.get_content("self_registration__invalid_" .. field.name) bsw/jbe@1309: if field_error == "" then bsw/jbe@1309: field_error = nil bsw/jbe@1309: end bsw/jbe@1309: if field_error then bsw/jbe@1309: class = " is-invalid" bsw/jbe@1309: end bsw@1359: if not field.internal then bsw@1359: if field.name == "date_of_birth" then bsw@1359: local label = field.label bsw@1359: if field.optional then bsw@1359: label = label .. config.self_registration.optional_field_indicator bsw@1359: end bsw@1359: 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: slot.put("   ") bsw@1359: local days = { { id = 0, name = _"day" } } bsw@1359: for i = 1, 31 do bsw@1359: table.insert(days, { id = i, name = i }) bsw@1359: end bsw@1359: local months = { bsw/jbe@1309: { id = 0, name = _"month" }, bsw@1359: { id = 1, name = "gennaio" }, bsw@1359: { id = 2, name = "febbraio" }, bsw@1359: { id = 3, name = "marzo" }, bsw@1359: { id = 4, name = "aprile" }, bsw@1359: { id = 5, name = "maggio" }, bsw@1359: { id = 6, name = "giugno" }, bsw@1359: { id = 7, name = "luglio" }, bsw@1359: { id = 8, name = "agosto" }, bsw@1359: { id = 9, name = "settembre" }, bsw@1359: { id = 10, name = "ottobre" }, bsw@1359: { id = 11, name = "novembre" }, bsw@1359: { id = 12, name = "dicembre" }, bsw@1359: } bsw@1359: if config.self_registration.lang == "en" then bsw@1359: months = { bsw@1359: { id = 0, name = _"month" }, bsw@1359: { id = 1, name = "January" }, bsw@1359: { id = 2, name = "February" }, bsw@1359: { id = 3, name = "March" }, bsw@1359: { id = 4, name = "April" }, bsw@1359: { id = 5, name = "May" }, bsw@1359: { id = 6, name = "June" }, bsw@1359: { id = 7, name = "July" }, bsw@1359: { id = 8, name = "August" }, bsw@1359: { id = 9, name = "September" }, bsw@1359: { id = 10, name = "October" }, bsw@1359: { id = 11, name = "November" }, bsw@1359: { id = 12, name = "December" }, bsw@1359: } bsw@1359: end bsw@1359: local years = { { id = 0, name = _"year" } } bsw@1359: for i = 2002, 1900, -1 do bsw@1359: table.insert(years, { id = i, name = i }) bsw@1359: end bsw@1359: ui.field.select{ bsw@1359: container_attr = { style = "display: inline-block; " }, bsw@1359: attr = { class = class }, bsw@1359: foreign_records = days, bsw@1359: foreign_id = "id", bsw@1359: foreign_name = "name", bsw@1359: name = "verification_data_" .. field.name .. "_day", bsw@1359: value = tonumber(request.get_param{ name = "verification_data_" .. field.name .. "_day" }) bsw@1359: } bsw@1359: slot.put("   ") bsw@1359: ui.field.select{ bsw@1359: container_attr = { style = "display: inline-block; " }, bsw@1359: attr = { class = class }, bsw@1359: foreign_records = months, bsw@1359: foreign_id = "id", bsw@1359: foreign_name = "name", bsw@1359: name = "verification_data_" .. field.name .. "_month", bsw@1359: value = tonumber(request.get_param{ name = "verification_data_" .. field.name .. "_month" }) bsw@1359: } bsw@1359: slot.put("   ") bsw@1359: ui.field.select{ bsw@1359: container_attr = { style = "display: inline-block; " }, bsw@1359: attr = { class = class }, bsw@1359: foreign_records = years, bsw@1359: foreign_id = "id", bsw@1359: foreign_name = "name", bsw@1359: name = "verification_data_" .. field.name .. "_year", bsw@1359: value = tonumber(request.get_param{ name = "verification_data_" .. field.name .. "_year" }) bsw@1359: } bsw@1359: slot.put("
") bsw@1377: bsw@1377: elseif field.type == "dropdown" then bsw@1380: local options = { { id = "", name = "" } } bsw@1377: for i_options, option in ipairs(field.options) do bsw@1377: table.insert(options, option) bsw@1377: end bsw@1380: 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: slot.put("   ") bsw@1377: ui.field.select{ bsw@1377: container_attr = { style = "display: inline-block; " }, bsw@1377: attr = { class = class }, bsw@1377: foreign_records = options, bsw@1377: foreign_id = "id", bsw@1377: foreign_name = "name", bsw@1377: name = "verification_data_" .. field.name, bsw@1377: value = tonumber(request.get_param{ name = "verification_data_" .. field.name }) bsw@1377: } bsw@1381: slot.put("
") bsw@1377: bsw@1359: elseif field.type == "image" then bsw@1386: slot.put("
") bsw@1392: 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: slot.put("
") bsw@1391: ui.script{ script = [[ bsw@1391: function getFile(){ bsw@1392: document.getElementById("fileInput").click(); bsw@1391: } bsw@1391: function fileChoosen(obj){ bsw@1391: var file = obj.value; bsw@1391: var fileName = file.split("\\"); bsw@1391: document.getElementById("fileBtn").innerHTML = fileName[fileName.length-1]; bsw@1396: document.getElementById("fileCheckbox").checked = fileName.length > 0 ? true : false; bsw@1391: event.preventDefault(); bsw@1391: } bsw@1391: ]] } bsw@1393: ui.tag{ tag = "input", attr = { id = "fileInput", style = "display: none;", type = "file", name = "verification_data_" .. field.name, onchange = "fileChoosen(this);" } } bsw@1396: ui.tag{ tag = "label", attr = { bsw@1396: class = "mdl-checkbox mdl-js-checkbox mdl-js-ripple-effect", bsw@1396: style = "display: inline;", bsw@1396: }, bsw@1396: content = function() bsw@1396: ui.tag{ bsw@1396: tag = "input", bsw@1396: attr = { bsw@1396: type = "checkbox", bsw@1396: class = "mdl-checkbox__input", bsw@1396: id = "fileCheckbox", bsw@1396: style = "float: left;", bsw@1396: onclick = "getFile();" bsw@1396: } bsw@1396: } bsw@1396: ui.tag{ bsw@1396: attr = { id = "fileBtn", class = "mdl-checkbox__label", onclick = "getFile();" }, bsw@1396: content = field.upload_label bsw@1396: } bsw@1395: } bsw@1395: } bsw@1367: if field.optional_checkbox then bsw@1391: slot.put("   ") bsw@1375: ui.tag{ tag = "label", attr = { bsw@1375: class = "mdl-checkbox mdl-js-checkbox mdl-js-ripple-effect", bsw@1394: style = "display: inline;", bsw@1375: ["for"] = "verification_data_" .. field.name .. "_optout" bsw@1375: }, bsw@1375: content = function() bsw@1375: ui.tag{ bsw@1375: tag = "input", bsw@1375: attr = { bsw@1375: type = "checkbox", bsw@1375: class = "mdl-checkbox__input", bsw@1375: id = "verification_data_" .. field.name .. "_optout", bsw@1375: name = "verification_data_" .. field.name .. "_optout", bsw@1375: value = "1", bsw@1375: style = "float: left;", bsw@1375: checked = request.get_param{ name = "verification_data_" .. field.name .. "_optout" } and "checked" or nil, bsw@1375: } bsw@1375: } bsw@1375: ui.tag{ bsw@1375: attr = { class = "mdl-checkbox__label" }, bsw@1375: content = field.optional_checkbox bsw@1375: } bsw@1375: end bsw@1375: } bsw@1367: end bsw@1359: bsw@1359: elseif field.name == "unit" then bsw@1359: local units_selector = Unit:new_selector() bsw@1359: :add_where{ "active" } bsw@1359: if field.where then bsw@1359: units_selector:add_where(field.where) bsw@1359: end bsw@1359: local units = {} bsw@1359: if field.optional then bsw@1359: table.insert(units, { bsw@1359: id = "", bsw@1359: name = _"None" bsw@1359: }) bsw@1359: end bsw@1359: for i_unit, unit in ipairs(units_selector:exec()) do bsw@1359: table.insert(units, unit) bsw@1359: end bsw@1382: 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: slot.put("   ") bsw@1359: ui.field.select{ bsw@1383: container_attr = { style = "display: inline-block; " }, bsw@1359: foreign_records = units, bsw@1359: foreign_id = "id", bsw@1359: foreign_name = "name", bsw@1359: name = "verification_data_" .. field.name, bsw@1359: value = tonumber(request.get_param{ name = "verification_data_" .. field.name }) bsw@1359: } bsw@1386: slot.put("
") bsw@1359: else bsw@1359: if field.name == "mobile_phone" then bsw@1359: if config.self_registration.lang ~= "en" then bsw@1359: ui.tag{ content = "+39" } bsw@1359: slot.put(" ") bsw@1359: end bsw@1359: end bsw@1359: ui.field.text{ bsw@1359: container_attr = { class = "mdl-textfield mdl-js-textfield mdl-textfield--floating-label" .. class }, bsw@1359: attr = { id = "lf-register__data_" .. field.name, class = "mdl-textfield__input" }, bsw@1359: label_attr = { class = "mdl-textfield__label", ["for"] = "lf-register__data" .. field.name }, bsw@1359: label = field.label, bsw@1359: name = "verification_data_" .. field.name, bsw@1359: value = request.get_param{ name = "verification_data_" .. field.name } bsw/jbe@1309: } bsw/jbe@1309: end bsw@1327: slot.put("
") bsw/jbe@1309: end bsw/jbe@1309: end