Software / code / prosody
Comparison
util/dataforms.lua @ 3381:28cb5ad72870
Merge Florob->trunk
| author | Matthew Wild <mwild1@gmail.com> |
|---|---|
| date | Fri, 16 Jul 2010 16:53:54 +0100 |
| parent | 3380:e74e80b454a1 |
| child | 3540:bc139431830b |
comparison
equal
deleted
inserted
replaced
| 3378:bb49ada7cf45 | 3381:28cb5ad72870 |
|---|---|
| 65 -- Split into multiple <value> tags, one for each line | 65 -- Split into multiple <value> tags, one for each line |
| 66 for line in value:gmatch("([^\r\n]+)\r?\n*") do | 66 for line in value:gmatch("([^\r\n]+)\r?\n*") do |
| 67 form:tag("value"):text(line):up(); | 67 form:tag("value"):text(line):up(); |
| 68 end | 68 end |
| 69 elseif field_type == "list-single" then | 69 elseif field_type == "list-single" then |
| 70 local has_default = false; | |
| 70 for _, val in ipairs(value) do | 71 for _, val in ipairs(value) do |
| 71 if type(val) == "table" then | 72 if type(val) == "table" then |
| 72 form:tag("option", { label = val.label }):tag("value"):text(val.value):up():up(); | 73 form:tag("option", { label = val.label }):tag("value"):text(val.value):up():up(); |
| 74 if val.default and (not has_default) then | |
| 75 form:tag("value"):text(val.value):up(); | |
| 76 has_default = true; | |
| 77 end | |
| 78 else | |
| 79 form:tag("option", { label= val }):tag("value"):text(tostring(val)):up():up(); | |
| 80 end | |
| 81 end | |
| 82 elseif field_type == "list-multi" then | |
| 83 for _, val in ipairs(value) do | |
| 84 if type(val) == "table" then | |
| 85 form:tag("option", { label = val.label }):tag("value"):text(val.value):up():up(); | |
| 86 if val.default then | |
| 87 form:tag("value"):text(val.value):up(); | |
| 88 end | |
| 73 else | 89 else |
| 74 form:tag("option", { label= val }):tag("value"):text(tostring(val)):up():up(); | 90 form:tag("option", { label= val }):tag("value"):text(tostring(val)):up():up(); |
| 75 end | 91 end |
| 76 end | 92 end |
| 77 end | 93 end |
| 147 end | 163 end |
| 148 | 164 |
| 149 field_readers["list-single"] = | 165 field_readers["list-single"] = |
| 150 field_readers["text-single"]; | 166 field_readers["text-single"]; |
| 151 | 167 |
| 168 field_readers["list-multi"] = | |
| 169 function (field_tag) | |
| 170 local result = {}; | |
| 171 for value_tag in field_tag:childtags() do | |
| 172 if value_tag.name == "value" then | |
| 173 result[#result+1] = value_tag[1]; | |
| 174 end | |
| 175 end | |
| 176 return result; | |
| 177 end | |
| 178 | |
| 152 field_readers["boolean"] = | 179 field_readers["boolean"] = |
| 153 function (field_tag) | 180 function (field_tag) |
| 154 local value = field_tag:child_with_name("value"); | 181 local value = field_tag:child_with_name("value"); |
| 155 if value then | 182 if value then |
| 156 if value[1] == "1" or value[1] == "true" then | 183 if value[1] == "1" or value[1] == "true" then |