aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthew Wild <mwild1@gmail.com>2009-04-04 15:32:32 +0100
committerMatthew Wild <mwild1@gmail.com>2009-04-04 15:32:32 +0100
commit938c08a108e7b26ede1494a8d27cc37af9d0be48 (patch)
treefdb61afc994acf2e1fd287b3cbcbf8cf050a887d
parent4ec39b859c9b5d75e74e93c50044d86883f5e33d (diff)
downloadprosody-938c08a108e7b26ede1494a8d27cc37af9d0be48.tar.gz
prosody-938c08a108e7b26ede1494a8d27cc37af9d0be48.zip
util.dataforms: Fixed to actually work, mostly
-rw-r--r--util/dataforms.lua30
1 files changed, 23 insertions, 7 deletions
diff --git a/util/dataforms.lua b/util/dataforms.lua
index c10a0244..73a78f08 100644
--- a/util/dataforms.lua
+++ b/util/dataforms.lua
@@ -1,3 +1,6 @@
+local setmetatable = setmetatable;
+local pairs, ipairs = pairs, ipairs;
+local st = require "util.stanza";
module "dataforms"
@@ -13,11 +16,17 @@ end
local form_x_attr = { xmlns = xmlns_forms };
function form_t.form(layout, data)
- local form = st.tag("x", form_x_attr);
+ local form = st.stanza("x", form_x_attr);
+ if layout.title then
+ form:tag("title"):text(layout.title):up();
+ end
+ if layout.instructions then
+ form:tag("instructions"):text(layout.instructions):up();
+ end
for n, field in ipairs(layout) do
- local field_type = field.type;
+ local field_type = field.type or "text-single";
-- Add field tag
- form:tag("field", { type = field_type, var = field.name });
+ form:tag("field", { type = field_type, var = field.name, label = field.label });
local value = data[field.name];
@@ -30,7 +39,7 @@ function form_t.form(layout, data)
form:text(tostring(value));
end
elseif field_type == "boolean" then
- form:text((value and "1") or "0");
+ form:tag("value"):text((value and "1") or "0");
elseif field_type == "fixed" then
elseif field_type == "jid-multi" then
@@ -39,7 +48,13 @@ function form_t.form(layout, data)
end
elseif field_type == "jid-single" then
form:tag("value"):text(value):up();
-
+ elseif field_type == "text-single" or field_type == "text-private" then
+ form:tag("value"):text(value):up();
+ elseif field_type == "text-multi" then
+ -- Split into multiple <value> tags, one for each line
+ for line in value:gmatch("([^\r\n]+)\r?\n*") do
+ form:tag("value"):text(line):up();
+ end
end
-- Jump back up to list of fields
@@ -52,9 +67,10 @@ function form_t.data(layout, stanza)
end
+return _M;
---[[
+--[=[
Layout:
{
@@ -67,4 +83,4 @@ Layout:
}
---]]
+--]=]