Software / code / prosody
Comparison
util/dataforms.lua @ 1958:e2b0026143c4
util.dataforms: Incorporate slightly modified patch for list-single type from Florob
| author | Matthew Wild <mwild1@gmail.com> |
|---|---|
| date | Fri, 16 Oct 2009 19:52:09 +0100 |
| parent | 1945:adfd7f3720f5 |
| child | 2061:e34fdca432a9 |
comparison
equal
deleted
inserted
replaced
| 1957:5856b2dcf81e | 1958:e2b0026143c4 |
|---|---|
| 8 | 8 |
| 9 local setmetatable = setmetatable; | 9 local setmetatable = setmetatable; |
| 10 local pairs, ipairs = pairs, ipairs; | 10 local pairs, ipairs = pairs, ipairs; |
| 11 local tostring, type = tostring, type; | 11 local tostring, type = tostring, type; |
| 12 local t_concat = table.concat; | 12 local t_concat = table.concat; |
| 13 | |
| 14 local st = require "util.stanza"; | 13 local st = require "util.stanza"; |
| 15 | 14 |
| 16 module "dataforms" | 15 module "dataforms" |
| 17 | 16 |
| 18 local xmlns_forms = 'jabber:x:data'; | 17 local xmlns_forms = 'jabber:x:data'; |
| 64 elseif field_type == "text-multi" then | 63 elseif field_type == "text-multi" then |
| 65 -- Split into multiple <value> tags, one for each line | 64 -- Split into multiple <value> tags, one for each line |
| 66 for line in value:gmatch("([^\r\n]+)\r?\n*") do | 65 for line in value:gmatch("([^\r\n]+)\r?\n*") do |
| 67 form:tag("value"):text(line):up(); | 66 form:tag("value"):text(line):up(); |
| 68 end | 67 end |
| 68 elseif field_type == "list-single" then | |
| 69 for _, val in ipairs(value) do | |
| 70 if type(val) == "table" then | |
| 71 form:tag("option", { label = val.label }):tag("value"):text(val.value):up():up(); | |
| 72 else | |
| 73 form:tag("option", { label= val }):tag("value"):text(tostring(val)):up():up(); | |
| 74 end | |
| 75 end | |
| 69 end | 76 end |
| 70 | 77 |
| 71 if field.required then | 78 if field.required then |
| 72 form:tag("required"):up(); | 79 form:tag("required"):up(); |
| 73 end | 80 end |
| 118 end | 125 end |
| 119 end | 126 end |
| 120 return t_concat(result, "\n"); | 127 return t_concat(result, "\n"); |
| 121 end | 128 end |
| 122 | 129 |
| 130 field_readers["list-single"] = | |
| 131 field_readers["text-single"]; | |
| 132 | |
| 123 field_readers["boolean"] = | 133 field_readers["boolean"] = |
| 124 function (field_tag) | 134 function (field_tag) |
| 125 local value = field_tag:child_with_name("value"); | 135 local value = field_tag:child_with_name("value"); |
| 126 if value then | 136 if value then |
| 127 if value[1] == "1" or value[1] == "true" then | 137 if value[1] == "1" or value[1] == "true" then |