diff options
author | Tobias Markmann <tm@ayena.de> | 2009-03-03 17:48:04 +0100 |
---|---|---|
committer | Tobias Markmann <tm@ayena.de> | 2009-03-03 17:48:04 +0100 |
commit | 7a7a89844a038b071f02fd1af309ba9ebbcda7de (patch) | |
tree | 73946c977be10a965d59de85b3ce6ba3743bc771 /util/dataforms.lua | |
parent | 3d1e7adbbc0afb8395f02ecd42fe3c38ce6a8d36 (diff) | |
parent | b6b9906c3c653935b55ad79ad4a2c41118f0a0e3 (diff) | |
download | prosody-7a7a89844a038b071f02fd1af309ba9ebbcda7de.tar.gz prosody-7a7a89844a038b071f02fd1af309ba9ebbcda7de.zip |
Merged with main tip.
Diffstat (limited to 'util/dataforms.lua')
-rw-r--r-- | util/dataforms.lua | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/util/dataforms.lua b/util/dataforms.lua new file mode 100644 index 00000000..c10a0244 --- /dev/null +++ b/util/dataforms.lua @@ -0,0 +1,70 @@ + +module "dataforms" + +local xmlns_forms = 'jabber:x:data'; + +local form_t = {}; +local form_mt = { __index = form_t }; + +function new(layout) + return setmetatable(layout, form_mt); +end + +local form_x_attr = { xmlns = xmlns_forms }; + +function form_t.form(layout, data) + local form = st.tag("x", form_x_attr); + for n, field in ipairs(layout) do + local field_type = field.type; + -- Add field tag + form:tag("field", { type = field_type, var = field.name }); + + local value = data[field.name]; + + -- Add value, depending on type + if field_type == "hidden" then + if type(value) == "table" then + -- Assume an XML snippet + form:add_child(value); + elseif value then + form:text(tostring(value)); + end + elseif field_type == "boolean" then + form:text((value and "1") or "0"); + elseif field_type == "fixed" then + + elseif field_type == "jid-multi" then + for _, jid in ipairs(value) do + form:tag("value"):text(jid):up(); + end + elseif field_type == "jid-single" then + form:tag("value"):text(value):up(); + + end + + -- Jump back up to list of fields + form:up(); + end + return form; +end + +function form_t.data(layout, stanza) + +end + + + +--[[ + +Layout: +{ + + title = "MUC Configuration", + instructions = [[Use this form to configure options for this MUC room.]], + + { name = "FORM_TYPE", type = "hidden", required = true }; + { name = "field-name", type = "field-type", required = false }; +} + + +--]] |