diff options
author | Matthew Wild <mwild1@gmail.com> | 2009-02-27 17:56:07 +0000 |
---|---|---|
committer | Matthew Wild <mwild1@gmail.com> | 2009-02-27 17:56:07 +0000 |
commit | 2a5e41bed0c75505a5367e87c7c6e48220443434 (patch) | |
tree | 8ea371bfad9c9210942d37339339891a82c51335 /util | |
parent | 219c84da4a2f42938e84ad60b53fbf1ed98954b8 (diff) | |
download | prosody-2a5e41bed0c75505a5367e87c7c6e48220443434.tar.gz prosody-2a5e41bed0c75505a5367e87c7c6e48220443434.zip |
util.dataforms: First commit, incomplete
Diffstat (limited to 'util')
-rw-r--r-- | util/dataforms.lua | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/util/dataforms.lua b/util/dataforms.lua new file mode 100644 index 00000000..ba751f6f --- /dev/null +++ b/util/dataforms.lua @@ -0,0 +1,69 @@ + +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 +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 }; +} + + +--]] |