Annotate

util/dataforms.lua @ 441:e4c0b1d7fd6b

util.dataforms: Update from prosody trunk 5fb6563eee1e keeping from_stanza()
author Kim Alvefur <zash@zash.se>
date Mon, 23 Nov 2020 23:43:58 +0100
parent 335:9e69ee8542d4
child 442:b2ae91f4fec9
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
123
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1 -- Prosody IM
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
2 -- Copyright (C) 2008-2010 Matthew Wild
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
3 -- Copyright (C) 2008-2010 Waqas Hussain
441
e4c0b1d7fd6b util.dataforms: Update from prosody trunk 5fb6563eee1e keeping from_stanza()
Kim Alvefur <zash@zash.se>
parents: 335
diff changeset
4 --
123
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
5 -- This project is MIT/X11 licensed. Please see the
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
6 -- COPYING file in the source package for more information.
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
7 --
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
8
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
9 local setmetatable = setmetatable;
441
e4c0b1d7fd6b util.dataforms: Update from prosody trunk 5fb6563eee1e keeping from_stanza()
Kim Alvefur <zash@zash.se>
parents: 335
diff changeset
10 local ipairs = ipairs;
e4c0b1d7fd6b util.dataforms: Update from prosody trunk 5fb6563eee1e keeping from_stanza()
Kim Alvefur <zash@zash.se>
parents: 335
diff changeset
11 local type, next = type, next;
e4c0b1d7fd6b util.dataforms: Update from prosody trunk 5fb6563eee1e keeping from_stanza()
Kim Alvefur <zash@zash.se>
parents: 335
diff changeset
12 local tonumber = tonumber;
e4c0b1d7fd6b util.dataforms: Update from prosody trunk 5fb6563eee1e keeping from_stanza()
Kim Alvefur <zash@zash.se>
parents: 335
diff changeset
13 local tostring = tostring;
123
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
14 local t_concat = table.concat;
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
15 local st = require "util.stanza";
334
34c52f3b21c4 util.dataforms: Update from Prosody repo
Kim Alvefur <zash@zash.se>
parents: 123
diff changeset
16 local jid_prep = require "util.jid".prep;
123
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
17
441
e4c0b1d7fd6b util.dataforms: Update from prosody trunk 5fb6563eee1e keeping from_stanza()
Kim Alvefur <zash@zash.se>
parents: 335
diff changeset
18 local _ENV = nil;
e4c0b1d7fd6b util.dataforms: Update from prosody trunk 5fb6563eee1e keeping from_stanza()
Kim Alvefur <zash@zash.se>
parents: 335
diff changeset
19 -- luacheck: std none
123
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
20
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
21 local xmlns_forms = 'jabber:x:data';
441
e4c0b1d7fd6b util.dataforms: Update from prosody trunk 5fb6563eee1e keeping from_stanza()
Kim Alvefur <zash@zash.se>
parents: 335
diff changeset
22 local xmlns_validate = 'http://jabber.org/protocol/xdata-validate';
123
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
23
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
24 local form_t = {};
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
25 local form_mt = { __index = form_t };
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
26
441
e4c0b1d7fd6b util.dataforms: Update from prosody trunk 5fb6563eee1e keeping from_stanza()
Kim Alvefur <zash@zash.se>
parents: 335
diff changeset
27 local function new(layout)
123
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
28 return setmetatable(layout, form_mt);
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
29 end
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
30
441
e4c0b1d7fd6b util.dataforms: Update from prosody trunk 5fb6563eee1e keeping from_stanza()
Kim Alvefur <zash@zash.se>
parents: 335
diff changeset
31 local function from_stanza(stanza)
335
9e69ee8542d4 util.dataforms: Add method for converting XML dataforms to tables
Kim Alvefur <zash@zash.se>
parents: 334
diff changeset
32 local layout = {
9e69ee8542d4 util.dataforms: Add method for converting XML dataforms to tables
Kim Alvefur <zash@zash.se>
parents: 334
diff changeset
33 title = stanza:get_child_text("title");
9e69ee8542d4 util.dataforms: Add method for converting XML dataforms to tables
Kim Alvefur <zash@zash.se>
parents: 334
diff changeset
34 instructions = stanza:get_child_text("instructions");
9e69ee8542d4 util.dataforms: Add method for converting XML dataforms to tables
Kim Alvefur <zash@zash.se>
parents: 334
diff changeset
35 };
9e69ee8542d4 util.dataforms: Add method for converting XML dataforms to tables
Kim Alvefur <zash@zash.se>
parents: 334
diff changeset
36 for tag in stanza:childtags("field") do
9e69ee8542d4 util.dataforms: Add method for converting XML dataforms to tables
Kim Alvefur <zash@zash.se>
parents: 334
diff changeset
37 local field = {
9e69ee8542d4 util.dataforms: Add method for converting XML dataforms to tables
Kim Alvefur <zash@zash.se>
parents: 334
diff changeset
38 name = tag.attr.var;
9e69ee8542d4 util.dataforms: Add method for converting XML dataforms to tables
Kim Alvefur <zash@zash.se>
parents: 334
diff changeset
39 label = tag.attr.label;
9e69ee8542d4 util.dataforms: Add method for converting XML dataforms to tables
Kim Alvefur <zash@zash.se>
parents: 334
diff changeset
40 type = tag.attr.type;
9e69ee8542d4 util.dataforms: Add method for converting XML dataforms to tables
Kim Alvefur <zash@zash.se>
parents: 334
diff changeset
41 required = tag:get_child("required") and true or nil;
9e69ee8542d4 util.dataforms: Add method for converting XML dataforms to tables
Kim Alvefur <zash@zash.se>
parents: 334
diff changeset
42 value = tag:get_child_text("value");
9e69ee8542d4 util.dataforms: Add method for converting XML dataforms to tables
Kim Alvefur <zash@zash.se>
parents: 334
diff changeset
43 };
9e69ee8542d4 util.dataforms: Add method for converting XML dataforms to tables
Kim Alvefur <zash@zash.se>
parents: 334
diff changeset
44 layout[#layout+1] = field;
9e69ee8542d4 util.dataforms: Add method for converting XML dataforms to tables
Kim Alvefur <zash@zash.se>
parents: 334
diff changeset
45 if field.type then
9e69ee8542d4 util.dataforms: Add method for converting XML dataforms to tables
Kim Alvefur <zash@zash.se>
parents: 334
diff changeset
46 local value = {};
9e69ee8542d4 util.dataforms: Add method for converting XML dataforms to tables
Kim Alvefur <zash@zash.se>
parents: 334
diff changeset
47 if field.type:match"list%-" then
9e69ee8542d4 util.dataforms: Add method for converting XML dataforms to tables
Kim Alvefur <zash@zash.se>
parents: 334
diff changeset
48 for tag in tag:childtags("option") do
9e69ee8542d4 util.dataforms: Add method for converting XML dataforms to tables
Kim Alvefur <zash@zash.se>
parents: 334
diff changeset
49 value[#value+1] = { label = tag.attr.label, value = tag:get_child_text("value") };
9e69ee8542d4 util.dataforms: Add method for converting XML dataforms to tables
Kim Alvefur <zash@zash.se>
parents: 334
diff changeset
50 end
9e69ee8542d4 util.dataforms: Add method for converting XML dataforms to tables
Kim Alvefur <zash@zash.se>
parents: 334
diff changeset
51 for tag in tag:childtags("value") do
9e69ee8542d4 util.dataforms: Add method for converting XML dataforms to tables
Kim Alvefur <zash@zash.se>
parents: 334
diff changeset
52 value[#value+1] = { label = tag.attr.label, value = tag:get_text(), default = true };
9e69ee8542d4 util.dataforms: Add method for converting XML dataforms to tables
Kim Alvefur <zash@zash.se>
parents: 334
diff changeset
53 end
9e69ee8542d4 util.dataforms: Add method for converting XML dataforms to tables
Kim Alvefur <zash@zash.se>
parents: 334
diff changeset
54 elseif field.type:match"%-multi" then
9e69ee8542d4 util.dataforms: Add method for converting XML dataforms to tables
Kim Alvefur <zash@zash.se>
parents: 334
diff changeset
55 for tag in tag:childtags("value") do
9e69ee8542d4 util.dataforms: Add method for converting XML dataforms to tables
Kim Alvefur <zash@zash.se>
parents: 334
diff changeset
56 value[#value+1] = tag.attr.label and { label = tag.attr.label, value = tag:get_text() } or tag:get_text();
9e69ee8542d4 util.dataforms: Add method for converting XML dataforms to tables
Kim Alvefur <zash@zash.se>
parents: 334
diff changeset
57 end
9e69ee8542d4 util.dataforms: Add method for converting XML dataforms to tables
Kim Alvefur <zash@zash.se>
parents: 334
diff changeset
58 if field.type == "text-multi" then
9e69ee8542d4 util.dataforms: Add method for converting XML dataforms to tables
Kim Alvefur <zash@zash.se>
parents: 334
diff changeset
59 field.value = t_concat(value, "\n");
9e69ee8542d4 util.dataforms: Add method for converting XML dataforms to tables
Kim Alvefur <zash@zash.se>
parents: 334
diff changeset
60 else
9e69ee8542d4 util.dataforms: Add method for converting XML dataforms to tables
Kim Alvefur <zash@zash.se>
parents: 334
diff changeset
61 field.value = value;
9e69ee8542d4 util.dataforms: Add method for converting XML dataforms to tables
Kim Alvefur <zash@zash.se>
parents: 334
diff changeset
62 end
9e69ee8542d4 util.dataforms: Add method for converting XML dataforms to tables
Kim Alvefur <zash@zash.se>
parents: 334
diff changeset
63 end
9e69ee8542d4 util.dataforms: Add method for converting XML dataforms to tables
Kim Alvefur <zash@zash.se>
parents: 334
diff changeset
64 end
9e69ee8542d4 util.dataforms: Add method for converting XML dataforms to tables
Kim Alvefur <zash@zash.se>
parents: 334
diff changeset
65 end
9e69ee8542d4 util.dataforms: Add method for converting XML dataforms to tables
Kim Alvefur <zash@zash.se>
parents: 334
diff changeset
66 return new(layout);
9e69ee8542d4 util.dataforms: Add method for converting XML dataforms to tables
Kim Alvefur <zash@zash.se>
parents: 334
diff changeset
67 end
9e69ee8542d4 util.dataforms: Add method for converting XML dataforms to tables
Kim Alvefur <zash@zash.se>
parents: 334
diff changeset
68
123
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
69 function form_t.form(layout, data, formtype)
441
e4c0b1d7fd6b util.dataforms: Update from prosody trunk 5fb6563eee1e keeping from_stanza()
Kim Alvefur <zash@zash.se>
parents: 335
diff changeset
70 if not formtype then formtype = "form" end
e4c0b1d7fd6b util.dataforms: Update from prosody trunk 5fb6563eee1e keeping from_stanza()
Kim Alvefur <zash@zash.se>
parents: 335
diff changeset
71 local form = st.stanza("x", { xmlns = xmlns_forms, type = formtype });
e4c0b1d7fd6b util.dataforms: Update from prosody trunk 5fb6563eee1e keeping from_stanza()
Kim Alvefur <zash@zash.se>
parents: 335
diff changeset
72 if formtype == "cancel" then
e4c0b1d7fd6b util.dataforms: Update from prosody trunk 5fb6563eee1e keeping from_stanza()
Kim Alvefur <zash@zash.se>
parents: 335
diff changeset
73 return form;
123
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
74 end
441
e4c0b1d7fd6b util.dataforms: Update from prosody trunk 5fb6563eee1e keeping from_stanza()
Kim Alvefur <zash@zash.se>
parents: 335
diff changeset
75 if formtype ~= "submit" then
e4c0b1d7fd6b util.dataforms: Update from prosody trunk 5fb6563eee1e keeping from_stanza()
Kim Alvefur <zash@zash.se>
parents: 335
diff changeset
76 if layout.title then
e4c0b1d7fd6b util.dataforms: Update from prosody trunk 5fb6563eee1e keeping from_stanza()
Kim Alvefur <zash@zash.se>
parents: 335
diff changeset
77 form:tag("title"):text(layout.title):up();
e4c0b1d7fd6b util.dataforms: Update from prosody trunk 5fb6563eee1e keeping from_stanza()
Kim Alvefur <zash@zash.se>
parents: 335
diff changeset
78 end
e4c0b1d7fd6b util.dataforms: Update from prosody trunk 5fb6563eee1e keeping from_stanza()
Kim Alvefur <zash@zash.se>
parents: 335
diff changeset
79 if layout.instructions then
e4c0b1d7fd6b util.dataforms: Update from prosody trunk 5fb6563eee1e keeping from_stanza()
Kim Alvefur <zash@zash.se>
parents: 335
diff changeset
80 form:tag("instructions"):text(layout.instructions):up();
e4c0b1d7fd6b util.dataforms: Update from prosody trunk 5fb6563eee1e keeping from_stanza()
Kim Alvefur <zash@zash.se>
parents: 335
diff changeset
81 end
123
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
82 end
441
e4c0b1d7fd6b util.dataforms: Update from prosody trunk 5fb6563eee1e keeping from_stanza()
Kim Alvefur <zash@zash.se>
parents: 335
diff changeset
83 for _, field in ipairs(layout) do
123
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
84 local field_type = field.type or "text-single";
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
85 -- Add field tag
441
e4c0b1d7fd6b util.dataforms: Update from prosody trunk 5fb6563eee1e keeping from_stanza()
Kim Alvefur <zash@zash.se>
parents: 335
diff changeset
86 form:tag("field", { type = field_type, var = field.var or field.name, label = formtype ~= "submit" and field.label or nil });
e4c0b1d7fd6b util.dataforms: Update from prosody trunk 5fb6563eee1e keeping from_stanza()
Kim Alvefur <zash@zash.se>
parents: 335
diff changeset
87
e4c0b1d7fd6b util.dataforms: Update from prosody trunk 5fb6563eee1e keeping from_stanza()
Kim Alvefur <zash@zash.se>
parents: 335
diff changeset
88 if formtype ~= "submit" then
e4c0b1d7fd6b util.dataforms: Update from prosody trunk 5fb6563eee1e keeping from_stanza()
Kim Alvefur <zash@zash.se>
parents: 335
diff changeset
89 if field.desc then
e4c0b1d7fd6b util.dataforms: Update from prosody trunk 5fb6563eee1e keeping from_stanza()
Kim Alvefur <zash@zash.se>
parents: 335
diff changeset
90 form:text_tag("desc", field.desc);
e4c0b1d7fd6b util.dataforms: Update from prosody trunk 5fb6563eee1e keeping from_stanza()
Kim Alvefur <zash@zash.se>
parents: 335
diff changeset
91 end
e4c0b1d7fd6b util.dataforms: Update from prosody trunk 5fb6563eee1e keeping from_stanza()
Kim Alvefur <zash@zash.se>
parents: 335
diff changeset
92 end
e4c0b1d7fd6b util.dataforms: Update from prosody trunk 5fb6563eee1e keeping from_stanza()
Kim Alvefur <zash@zash.se>
parents: 335
diff changeset
93
e4c0b1d7fd6b util.dataforms: Update from prosody trunk 5fb6563eee1e keeping from_stanza()
Kim Alvefur <zash@zash.se>
parents: 335
diff changeset
94 if formtype == "form" and field.datatype then
e4c0b1d7fd6b util.dataforms: Update from prosody trunk 5fb6563eee1e keeping from_stanza()
Kim Alvefur <zash@zash.se>
parents: 335
diff changeset
95 form:tag("validate", { xmlns = xmlns_validate, datatype = field.datatype });
e4c0b1d7fd6b util.dataforms: Update from prosody trunk 5fb6563eee1e keeping from_stanza()
Kim Alvefur <zash@zash.se>
parents: 335
diff changeset
96 if field.range_min or field.range_max then
e4c0b1d7fd6b util.dataforms: Update from prosody trunk 5fb6563eee1e keeping from_stanza()
Kim Alvefur <zash@zash.se>
parents: 335
diff changeset
97 form:tag("range", {
e4c0b1d7fd6b util.dataforms: Update from prosody trunk 5fb6563eee1e keeping from_stanza()
Kim Alvefur <zash@zash.se>
parents: 335
diff changeset
98 min = field.range_min and tostring(field.range_min),
e4c0b1d7fd6b util.dataforms: Update from prosody trunk 5fb6563eee1e keeping from_stanza()
Kim Alvefur <zash@zash.se>
parents: 335
diff changeset
99 max = field.range_max and tostring(field.range_max),
e4c0b1d7fd6b util.dataforms: Update from prosody trunk 5fb6563eee1e keeping from_stanza()
Kim Alvefur <zash@zash.se>
parents: 335
diff changeset
100 }):up();
e4c0b1d7fd6b util.dataforms: Update from prosody trunk 5fb6563eee1e keeping from_stanza()
Kim Alvefur <zash@zash.se>
parents: 335
diff changeset
101 end
e4c0b1d7fd6b util.dataforms: Update from prosody trunk 5fb6563eee1e keeping from_stanza()
Kim Alvefur <zash@zash.se>
parents: 335
diff changeset
102 -- <basic/> assumed
e4c0b1d7fd6b util.dataforms: Update from prosody trunk 5fb6563eee1e keeping from_stanza()
Kim Alvefur <zash@zash.se>
parents: 335
diff changeset
103 form:up();
e4c0b1d7fd6b util.dataforms: Update from prosody trunk 5fb6563eee1e keeping from_stanza()
Kim Alvefur <zash@zash.se>
parents: 335
diff changeset
104 end
e4c0b1d7fd6b util.dataforms: Update from prosody trunk 5fb6563eee1e keeping from_stanza()
Kim Alvefur <zash@zash.se>
parents: 335
diff changeset
105
e4c0b1d7fd6b util.dataforms: Update from prosody trunk 5fb6563eee1e keeping from_stanza()
Kim Alvefur <zash@zash.se>
parents: 335
diff changeset
106
e4c0b1d7fd6b util.dataforms: Update from prosody trunk 5fb6563eee1e keeping from_stanza()
Kim Alvefur <zash@zash.se>
parents: 335
diff changeset
107 local value = field.value;
e4c0b1d7fd6b util.dataforms: Update from prosody trunk 5fb6563eee1e keeping from_stanza()
Kim Alvefur <zash@zash.se>
parents: 335
diff changeset
108 local options = field.options;
e4c0b1d7fd6b util.dataforms: Update from prosody trunk 5fb6563eee1e keeping from_stanza()
Kim Alvefur <zash@zash.se>
parents: 335
diff changeset
109
e4c0b1d7fd6b util.dataforms: Update from prosody trunk 5fb6563eee1e keeping from_stanza()
Kim Alvefur <zash@zash.se>
parents: 335
diff changeset
110 if data and data[field.name] ~= nil then
e4c0b1d7fd6b util.dataforms: Update from prosody trunk 5fb6563eee1e keeping from_stanza()
Kim Alvefur <zash@zash.se>
parents: 335
diff changeset
111 value = data[field.name];
123
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
112
441
e4c0b1d7fd6b util.dataforms: Update from prosody trunk 5fb6563eee1e keeping from_stanza()
Kim Alvefur <zash@zash.se>
parents: 335
diff changeset
113 if formtype == "form" and type(value) == "table"
e4c0b1d7fd6b util.dataforms: Update from prosody trunk 5fb6563eee1e keeping from_stanza()
Kim Alvefur <zash@zash.se>
parents: 335
diff changeset
114 and (field_type == "list-single" or field_type == "list-multi") then
e4c0b1d7fd6b util.dataforms: Update from prosody trunk 5fb6563eee1e keeping from_stanza()
Kim Alvefur <zash@zash.se>
parents: 335
diff changeset
115 -- Allow passing dynamically generated options as values
e4c0b1d7fd6b util.dataforms: Update from prosody trunk 5fb6563eee1e keeping from_stanza()
Kim Alvefur <zash@zash.se>
parents: 335
diff changeset
116 options, value = value, nil;
e4c0b1d7fd6b util.dataforms: Update from prosody trunk 5fb6563eee1e keeping from_stanza()
Kim Alvefur <zash@zash.se>
parents: 335
diff changeset
117 end
e4c0b1d7fd6b util.dataforms: Update from prosody trunk 5fb6563eee1e keeping from_stanza()
Kim Alvefur <zash@zash.se>
parents: 335
diff changeset
118 end
e4c0b1d7fd6b util.dataforms: Update from prosody trunk 5fb6563eee1e keeping from_stanza()
Kim Alvefur <zash@zash.se>
parents: 335
diff changeset
119
e4c0b1d7fd6b util.dataforms: Update from prosody trunk 5fb6563eee1e keeping from_stanza()
Kim Alvefur <zash@zash.se>
parents: 335
diff changeset
120 if formtype == "form" and options then
e4c0b1d7fd6b util.dataforms: Update from prosody trunk 5fb6563eee1e keeping from_stanza()
Kim Alvefur <zash@zash.se>
parents: 335
diff changeset
121 local defaults = {};
e4c0b1d7fd6b util.dataforms: Update from prosody trunk 5fb6563eee1e keeping from_stanza()
Kim Alvefur <zash@zash.se>
parents: 335
diff changeset
122 for _, val in ipairs(options) do
e4c0b1d7fd6b util.dataforms: Update from prosody trunk 5fb6563eee1e keeping from_stanza()
Kim Alvefur <zash@zash.se>
parents: 335
diff changeset
123 if type(val) == "table" then
e4c0b1d7fd6b util.dataforms: Update from prosody trunk 5fb6563eee1e keeping from_stanza()
Kim Alvefur <zash@zash.se>
parents: 335
diff changeset
124 form:tag("option", { label = val.label }):tag("value"):text(val.value):up():up();
e4c0b1d7fd6b util.dataforms: Update from prosody trunk 5fb6563eee1e keeping from_stanza()
Kim Alvefur <zash@zash.se>
parents: 335
diff changeset
125 if val.default then
e4c0b1d7fd6b util.dataforms: Update from prosody trunk 5fb6563eee1e keeping from_stanza()
Kim Alvefur <zash@zash.se>
parents: 335
diff changeset
126 defaults[#defaults+1] = val.value;
e4c0b1d7fd6b util.dataforms: Update from prosody trunk 5fb6563eee1e keeping from_stanza()
Kim Alvefur <zash@zash.se>
parents: 335
diff changeset
127 end
e4c0b1d7fd6b util.dataforms: Update from prosody trunk 5fb6563eee1e keeping from_stanza()
Kim Alvefur <zash@zash.se>
parents: 335
diff changeset
128 else
e4c0b1d7fd6b util.dataforms: Update from prosody trunk 5fb6563eee1e keeping from_stanza()
Kim Alvefur <zash@zash.se>
parents: 335
diff changeset
129 form:tag("option", { label= val }):tag("value"):text(val):up():up();
e4c0b1d7fd6b util.dataforms: Update from prosody trunk 5fb6563eee1e keeping from_stanza()
Kim Alvefur <zash@zash.se>
parents: 335
diff changeset
130 end
e4c0b1d7fd6b util.dataforms: Update from prosody trunk 5fb6563eee1e keeping from_stanza()
Kim Alvefur <zash@zash.se>
parents: 335
diff changeset
131 end
e4c0b1d7fd6b util.dataforms: Update from prosody trunk 5fb6563eee1e keeping from_stanza()
Kim Alvefur <zash@zash.se>
parents: 335
diff changeset
132 if not value then
e4c0b1d7fd6b util.dataforms: Update from prosody trunk 5fb6563eee1e keeping from_stanza()
Kim Alvefur <zash@zash.se>
parents: 335
diff changeset
133 if field_type == "list-single" then
e4c0b1d7fd6b util.dataforms: Update from prosody trunk 5fb6563eee1e keeping from_stanza()
Kim Alvefur <zash@zash.se>
parents: 335
diff changeset
134 value = defaults[1];
e4c0b1d7fd6b util.dataforms: Update from prosody trunk 5fb6563eee1e keeping from_stanza()
Kim Alvefur <zash@zash.se>
parents: 335
diff changeset
135 elseif field_type == "list-multi" then
e4c0b1d7fd6b util.dataforms: Update from prosody trunk 5fb6563eee1e keeping from_stanza()
Kim Alvefur <zash@zash.se>
parents: 335
diff changeset
136 value = defaults;
e4c0b1d7fd6b util.dataforms: Update from prosody trunk 5fb6563eee1e keeping from_stanza()
Kim Alvefur <zash@zash.se>
parents: 335
diff changeset
137 end
e4c0b1d7fd6b util.dataforms: Update from prosody trunk 5fb6563eee1e keeping from_stanza()
Kim Alvefur <zash@zash.se>
parents: 335
diff changeset
138 end
e4c0b1d7fd6b util.dataforms: Update from prosody trunk 5fb6563eee1e keeping from_stanza()
Kim Alvefur <zash@zash.se>
parents: 335
diff changeset
139 end
e4c0b1d7fd6b util.dataforms: Update from prosody trunk 5fb6563eee1e keeping from_stanza()
Kim Alvefur <zash@zash.se>
parents: 335
diff changeset
140
e4c0b1d7fd6b util.dataforms: Update from prosody trunk 5fb6563eee1e keeping from_stanza()
Kim Alvefur <zash@zash.se>
parents: 335
diff changeset
141 if value ~= nil then
e4c0b1d7fd6b util.dataforms: Update from prosody trunk 5fb6563eee1e keeping from_stanza()
Kim Alvefur <zash@zash.se>
parents: 335
diff changeset
142 if type(value) == "number" then
e4c0b1d7fd6b util.dataforms: Update from prosody trunk 5fb6563eee1e keeping from_stanza()
Kim Alvefur <zash@zash.se>
parents: 335
diff changeset
143 -- TODO validate that this is ok somehow, eg check field.datatype
e4c0b1d7fd6b util.dataforms: Update from prosody trunk 5fb6563eee1e keeping from_stanza()
Kim Alvefur <zash@zash.se>
parents: 335
diff changeset
144 value = ("%g"):format(value);
e4c0b1d7fd6b util.dataforms: Update from prosody trunk 5fb6563eee1e keeping from_stanza()
Kim Alvefur <zash@zash.se>
parents: 335
diff changeset
145 end
123
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
146 -- Add value, depending on type
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
147 if field_type == "hidden" then
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
148 if type(value) == "table" then
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
149 -- Assume an XML snippet
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
150 form:tag("value")
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
151 :add_child(value)
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
152 :up();
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
153 else
441
e4c0b1d7fd6b util.dataforms: Update from prosody trunk 5fb6563eee1e keeping from_stanza()
Kim Alvefur <zash@zash.se>
parents: 335
diff changeset
154 form:tag("value"):text(value):up();
123
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
155 end
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
156 elseif field_type == "boolean" then
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
157 form:tag("value"):text((value and "1") or "0"):up();
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
158 elseif field_type == "fixed" then
441
e4c0b1d7fd6b util.dataforms: Update from prosody trunk 5fb6563eee1e keeping from_stanza()
Kim Alvefur <zash@zash.se>
parents: 335
diff changeset
159 form:tag("value"):text(value):up();
123
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
160 elseif field_type == "jid-multi" then
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
161 for _, jid in ipairs(value) do
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
162 form:tag("value"):text(jid):up();
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
163 end
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
164 elseif field_type == "jid-single" then
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
165 form:tag("value"):text(value):up();
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
166 elseif field_type == "text-single" or field_type == "text-private" then
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
167 form:tag("value"):text(value):up();
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
168 elseif field_type == "text-multi" then
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
169 -- Split into multiple <value> tags, one for each line
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
170 for line in value:gmatch("([^\r\n]+)\r?\n*") do
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
171 form:tag("value"):text(line):up();
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
172 end
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
173 elseif field_type == "list-single" then
441
e4c0b1d7fd6b util.dataforms: Update from prosody trunk 5fb6563eee1e keeping from_stanza()
Kim Alvefur <zash@zash.se>
parents: 335
diff changeset
174 form:tag("value"):text(value):up();
123
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
175 elseif field_type == "list-multi" then
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
176 for _, val in ipairs(value) do
441
e4c0b1d7fd6b util.dataforms: Update from prosody trunk 5fb6563eee1e keeping from_stanza()
Kim Alvefur <zash@zash.se>
parents: 335
diff changeset
177 form:tag("value"):text(val):up();
123
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
178 end
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
179 end
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
180 end
441
e4c0b1d7fd6b util.dataforms: Update from prosody trunk 5fb6563eee1e keeping from_stanza()
Kim Alvefur <zash@zash.se>
parents: 335
diff changeset
181
e4c0b1d7fd6b util.dataforms: Update from prosody trunk 5fb6563eee1e keeping from_stanza()
Kim Alvefur <zash@zash.se>
parents: 335
diff changeset
182 local media = field.media;
e4c0b1d7fd6b util.dataforms: Update from prosody trunk 5fb6563eee1e keeping from_stanza()
Kim Alvefur <zash@zash.se>
parents: 335
diff changeset
183 if media then
e4c0b1d7fd6b util.dataforms: Update from prosody trunk 5fb6563eee1e keeping from_stanza()
Kim Alvefur <zash@zash.se>
parents: 335
diff changeset
184 form:tag("media", { xmlns = "urn:xmpp:media-element", height = ("%g"):format(media.height), width = ("%g"):format(media.width) });
e4c0b1d7fd6b util.dataforms: Update from prosody trunk 5fb6563eee1e keeping from_stanza()
Kim Alvefur <zash@zash.se>
parents: 335
diff changeset
185 for _, val in ipairs(media) do
e4c0b1d7fd6b util.dataforms: Update from prosody trunk 5fb6563eee1e keeping from_stanza()
Kim Alvefur <zash@zash.se>
parents: 335
diff changeset
186 form:tag("uri", { type = val.type }):text(val.uri):up()
e4c0b1d7fd6b util.dataforms: Update from prosody trunk 5fb6563eee1e keeping from_stanza()
Kim Alvefur <zash@zash.se>
parents: 335
diff changeset
187 end
e4c0b1d7fd6b util.dataforms: Update from prosody trunk 5fb6563eee1e keeping from_stanza()
Kim Alvefur <zash@zash.se>
parents: 335
diff changeset
188 form:up();
e4c0b1d7fd6b util.dataforms: Update from prosody trunk 5fb6563eee1e keeping from_stanza()
Kim Alvefur <zash@zash.se>
parents: 335
diff changeset
189 end
e4c0b1d7fd6b util.dataforms: Update from prosody trunk 5fb6563eee1e keeping from_stanza()
Kim Alvefur <zash@zash.se>
parents: 335
diff changeset
190
e4c0b1d7fd6b util.dataforms: Update from prosody trunk 5fb6563eee1e keeping from_stanza()
Kim Alvefur <zash@zash.se>
parents: 335
diff changeset
191 if formtype == "form" and field.required then
123
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
192 form:tag("required"):up();
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
193 end
441
e4c0b1d7fd6b util.dataforms: Update from prosody trunk 5fb6563eee1e keeping from_stanza()
Kim Alvefur <zash@zash.se>
parents: 335
diff changeset
194
123
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
195 -- Jump back up to list of fields
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
196 form:up();
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
197 end
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
198 return form;
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
199 end
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
200
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
201 local field_readers = {};
441
e4c0b1d7fd6b util.dataforms: Update from prosody trunk 5fb6563eee1e keeping from_stanza()
Kim Alvefur <zash@zash.se>
parents: 335
diff changeset
202 local data_validators = {};
123
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
203
441
e4c0b1d7fd6b util.dataforms: Update from prosody trunk 5fb6563eee1e keeping from_stanza()
Kim Alvefur <zash@zash.se>
parents: 335
diff changeset
204 function form_t.data(layout, stanza, current)
123
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
205 local data = {};
334
34c52f3b21c4 util.dataforms: Update from Prosody repo
Kim Alvefur <zash@zash.se>
parents: 123
diff changeset
206 local errors = {};
441
e4c0b1d7fd6b util.dataforms: Update from prosody trunk 5fb6563eee1e keeping from_stanza()
Kim Alvefur <zash@zash.se>
parents: 335
diff changeset
207 local present = {};
334
34c52f3b21c4 util.dataforms: Update from Prosody repo
Kim Alvefur <zash@zash.se>
parents: 123
diff changeset
208
34c52f3b21c4 util.dataforms: Update from Prosody repo
Kim Alvefur <zash@zash.se>
parents: 123
diff changeset
209 for _, field in ipairs(layout) do
34c52f3b21c4 util.dataforms: Update from Prosody repo
Kim Alvefur <zash@zash.se>
parents: 123
diff changeset
210 local tag;
441
e4c0b1d7fd6b util.dataforms: Update from prosody trunk 5fb6563eee1e keeping from_stanza()
Kim Alvefur <zash@zash.se>
parents: 335
diff changeset
211 for field_tag in stanza:childtags("field") do
e4c0b1d7fd6b util.dataforms: Update from prosody trunk 5fb6563eee1e keeping from_stanza()
Kim Alvefur <zash@zash.se>
parents: 335
diff changeset
212 if (field.var or field.name) == field_tag.attr.var then
334
34c52f3b21c4 util.dataforms: Update from Prosody repo
Kim Alvefur <zash@zash.se>
parents: 123
diff changeset
213 tag = field_tag;
123
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
214 break;
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
215 end
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
216 end
334
34c52f3b21c4 util.dataforms: Update from Prosody repo
Kim Alvefur <zash@zash.se>
parents: 123
diff changeset
217
34c52f3b21c4 util.dataforms: Update from Prosody repo
Kim Alvefur <zash@zash.se>
parents: 123
diff changeset
218 if not tag then
441
e4c0b1d7fd6b util.dataforms: Update from prosody trunk 5fb6563eee1e keeping from_stanza()
Kim Alvefur <zash@zash.se>
parents: 335
diff changeset
219 if current and current[field.name] ~= nil then
e4c0b1d7fd6b util.dataforms: Update from prosody trunk 5fb6563eee1e keeping from_stanza()
Kim Alvefur <zash@zash.se>
parents: 335
diff changeset
220 data[field.name] = current[field.name];
e4c0b1d7fd6b util.dataforms: Update from prosody trunk 5fb6563eee1e keeping from_stanza()
Kim Alvefur <zash@zash.se>
parents: 335
diff changeset
221 elseif field.required then
334
34c52f3b21c4 util.dataforms: Update from Prosody repo
Kim Alvefur <zash@zash.se>
parents: 123
diff changeset
222 errors[field.name] = "Required value missing";
34c52f3b21c4 util.dataforms: Update from Prosody repo
Kim Alvefur <zash@zash.se>
parents: 123
diff changeset
223 end
441
e4c0b1d7fd6b util.dataforms: Update from prosody trunk 5fb6563eee1e keeping from_stanza()
Kim Alvefur <zash@zash.se>
parents: 335
diff changeset
224 elseif field.name then
e4c0b1d7fd6b util.dataforms: Update from prosody trunk 5fb6563eee1e keeping from_stanza()
Kim Alvefur <zash@zash.se>
parents: 335
diff changeset
225 present[field.name] = true;
334
34c52f3b21c4 util.dataforms: Update from Prosody repo
Kim Alvefur <zash@zash.se>
parents: 123
diff changeset
226 local reader = field_readers[field.type];
34c52f3b21c4 util.dataforms: Update from Prosody repo
Kim Alvefur <zash@zash.se>
parents: 123
diff changeset
227 if reader then
441
e4c0b1d7fd6b util.dataforms: Update from prosody trunk 5fb6563eee1e keeping from_stanza()
Kim Alvefur <zash@zash.se>
parents: 335
diff changeset
228 local value, err = reader(tag, field.required);
e4c0b1d7fd6b util.dataforms: Update from prosody trunk 5fb6563eee1e keeping from_stanza()
Kim Alvefur <zash@zash.se>
parents: 335
diff changeset
229 local validator = field.datatype and data_validators[field.datatype];
e4c0b1d7fd6b util.dataforms: Update from prosody trunk 5fb6563eee1e keeping from_stanza()
Kim Alvefur <zash@zash.se>
parents: 335
diff changeset
230 if value ~= nil and validator then
e4c0b1d7fd6b util.dataforms: Update from prosody trunk 5fb6563eee1e keeping from_stanza()
Kim Alvefur <zash@zash.se>
parents: 335
diff changeset
231 local valid, ret = validator(value, field);
e4c0b1d7fd6b util.dataforms: Update from prosody trunk 5fb6563eee1e keeping from_stanza()
Kim Alvefur <zash@zash.se>
parents: 335
diff changeset
232 if valid then
e4c0b1d7fd6b util.dataforms: Update from prosody trunk 5fb6563eee1e keeping from_stanza()
Kim Alvefur <zash@zash.se>
parents: 335
diff changeset
233 value = ret;
e4c0b1d7fd6b util.dataforms: Update from prosody trunk 5fb6563eee1e keeping from_stanza()
Kim Alvefur <zash@zash.se>
parents: 335
diff changeset
234 else
e4c0b1d7fd6b util.dataforms: Update from prosody trunk 5fb6563eee1e keeping from_stanza()
Kim Alvefur <zash@zash.se>
parents: 335
diff changeset
235 value, err = nil, ret or ("Invalid value for data of type " .. field.datatype);
e4c0b1d7fd6b util.dataforms: Update from prosody trunk 5fb6563eee1e keeping from_stanza()
Kim Alvefur <zash@zash.se>
parents: 335
diff changeset
236 end
e4c0b1d7fd6b util.dataforms: Update from prosody trunk 5fb6563eee1e keeping from_stanza()
Kim Alvefur <zash@zash.se>
parents: 335
diff changeset
237 end
e4c0b1d7fd6b util.dataforms: Update from prosody trunk 5fb6563eee1e keeping from_stanza()
Kim Alvefur <zash@zash.se>
parents: 335
diff changeset
238 data[field.name], errors[field.name] = value, err;
334
34c52f3b21c4 util.dataforms: Update from Prosody repo
Kim Alvefur <zash@zash.se>
parents: 123
diff changeset
239 end
123
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
240 end
334
34c52f3b21c4 util.dataforms: Update from Prosody repo
Kim Alvefur <zash@zash.se>
parents: 123
diff changeset
241 end
34c52f3b21c4 util.dataforms: Update from Prosody repo
Kim Alvefur <zash@zash.se>
parents: 123
diff changeset
242 if next(errors) then
441
e4c0b1d7fd6b util.dataforms: Update from prosody trunk 5fb6563eee1e keeping from_stanza()
Kim Alvefur <zash@zash.se>
parents: 335
diff changeset
243 return data, errors, present;
123
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
244 end
441
e4c0b1d7fd6b util.dataforms: Update from prosody trunk 5fb6563eee1e keeping from_stanza()
Kim Alvefur <zash@zash.se>
parents: 335
diff changeset
245 return data, nil, present;
123
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
246 end
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
247
441
e4c0b1d7fd6b util.dataforms: Update from prosody trunk 5fb6563eee1e keeping from_stanza()
Kim Alvefur <zash@zash.se>
parents: 335
diff changeset
248 local function simple_text(field_tag, required)
e4c0b1d7fd6b util.dataforms: Update from prosody trunk 5fb6563eee1e keeping from_stanza()
Kim Alvefur <zash@zash.se>
parents: 335
diff changeset
249 local data = field_tag:get_child_text("value");
e4c0b1d7fd6b util.dataforms: Update from prosody trunk 5fb6563eee1e keeping from_stanza()
Kim Alvefur <zash@zash.se>
parents: 335
diff changeset
250 -- XEP-0004 does not say if an empty string is acceptable for a required value
e4c0b1d7fd6b util.dataforms: Update from prosody trunk 5fb6563eee1e keeping from_stanza()
Kim Alvefur <zash@zash.se>
parents: 335
diff changeset
251 -- so we will follow HTML5 which says that empty string means missing
e4c0b1d7fd6b util.dataforms: Update from prosody trunk 5fb6563eee1e keeping from_stanza()
Kim Alvefur <zash@zash.se>
parents: 335
diff changeset
252 if required and (data == nil or data == "") then
e4c0b1d7fd6b util.dataforms: Update from prosody trunk 5fb6563eee1e keeping from_stanza()
Kim Alvefur <zash@zash.se>
parents: 335
diff changeset
253 return nil, "Required value missing";
123
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
254 end
441
e4c0b1d7fd6b util.dataforms: Update from prosody trunk 5fb6563eee1e keeping from_stanza()
Kim Alvefur <zash@zash.se>
parents: 335
diff changeset
255 return data; -- Return whatever get_child_text returned, even if empty string
e4c0b1d7fd6b util.dataforms: Update from prosody trunk 5fb6563eee1e keeping from_stanza()
Kim Alvefur <zash@zash.se>
parents: 335
diff changeset
256 end
123
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
257
441
e4c0b1d7fd6b util.dataforms: Update from prosody trunk 5fb6563eee1e keeping from_stanza()
Kim Alvefur <zash@zash.se>
parents: 335
diff changeset
258 field_readers["text-single"] = simple_text;
e4c0b1d7fd6b util.dataforms: Update from prosody trunk 5fb6563eee1e keeping from_stanza()
Kim Alvefur <zash@zash.se>
parents: 335
diff changeset
259
e4c0b1d7fd6b util.dataforms: Update from prosody trunk 5fb6563eee1e keeping from_stanza()
Kim Alvefur <zash@zash.se>
parents: 335
diff changeset
260 field_readers["text-private"] = simple_text;
123
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
261
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
262 field_readers["jid-single"] =
334
34c52f3b21c4 util.dataforms: Update from Prosody repo
Kim Alvefur <zash@zash.se>
parents: 123
diff changeset
263 function (field_tag, required)
441
e4c0b1d7fd6b util.dataforms: Update from prosody trunk 5fb6563eee1e keeping from_stanza()
Kim Alvefur <zash@zash.se>
parents: 335
diff changeset
264 local raw_data, err = simple_text(field_tag, required);
e4c0b1d7fd6b util.dataforms: Update from prosody trunk 5fb6563eee1e keeping from_stanza()
Kim Alvefur <zash@zash.se>
parents: 335
diff changeset
265 if not raw_data then return raw_data, err; end
334
34c52f3b21c4 util.dataforms: Update from Prosody repo
Kim Alvefur <zash@zash.se>
parents: 123
diff changeset
266 local data = jid_prep(raw_data);
441
e4c0b1d7fd6b util.dataforms: Update from prosody trunk 5fb6563eee1e keeping from_stanza()
Kim Alvefur <zash@zash.se>
parents: 335
diff changeset
267 if not data then
334
34c52f3b21c4 util.dataforms: Update from Prosody repo
Kim Alvefur <zash@zash.se>
parents: 123
diff changeset
268 return nil, "Invalid JID: " .. raw_data;
34c52f3b21c4 util.dataforms: Update from Prosody repo
Kim Alvefur <zash@zash.se>
parents: 123
diff changeset
269 end
441
e4c0b1d7fd6b util.dataforms: Update from prosody trunk 5fb6563eee1e keeping from_stanza()
Kim Alvefur <zash@zash.se>
parents: 335
diff changeset
270 return data;
334
34c52f3b21c4 util.dataforms: Update from Prosody repo
Kim Alvefur <zash@zash.se>
parents: 123
diff changeset
271 end
123
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
272
334
34c52f3b21c4 util.dataforms: Update from Prosody repo
Kim Alvefur <zash@zash.se>
parents: 123
diff changeset
273 field_readers["jid-multi"] =
34c52f3b21c4 util.dataforms: Update from Prosody repo
Kim Alvefur <zash@zash.se>
parents: 123
diff changeset
274 function (field_tag, required)
123
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
275 local result = {};
334
34c52f3b21c4 util.dataforms: Update from Prosody repo
Kim Alvefur <zash@zash.se>
parents: 123
diff changeset
276 local err = {};
34c52f3b21c4 util.dataforms: Update from Prosody repo
Kim Alvefur <zash@zash.se>
parents: 123
diff changeset
277 for value_tag in field_tag:childtags("value") do
34c52f3b21c4 util.dataforms: Update from Prosody repo
Kim Alvefur <zash@zash.se>
parents: 123
diff changeset
278 local raw_value = value_tag:get_text();
34c52f3b21c4 util.dataforms: Update from Prosody repo
Kim Alvefur <zash@zash.se>
parents: 123
diff changeset
279 local value = jid_prep(raw_value);
34c52f3b21c4 util.dataforms: Update from Prosody repo
Kim Alvefur <zash@zash.se>
parents: 123
diff changeset
280 result[#result+1] = value;
34c52f3b21c4 util.dataforms: Update from Prosody repo
Kim Alvefur <zash@zash.se>
parents: 123
diff changeset
281 if raw_value and not value then
34c52f3b21c4 util.dataforms: Update from Prosody repo
Kim Alvefur <zash@zash.se>
parents: 123
diff changeset
282 err[#err+1] = ("Invalid JID: " .. raw_value);
123
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
283 end
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
284 end
334
34c52f3b21c4 util.dataforms: Update from Prosody repo
Kim Alvefur <zash@zash.se>
parents: 123
diff changeset
285 if #result > 0 then
34c52f3b21c4 util.dataforms: Update from Prosody repo
Kim Alvefur <zash@zash.se>
parents: 123
diff changeset
286 return result, (#err > 0 and t_concat(err, "\n") or nil);
34c52f3b21c4 util.dataforms: Update from Prosody repo
Kim Alvefur <zash@zash.se>
parents: 123
diff changeset
287 elseif required then
34c52f3b21c4 util.dataforms: Update from Prosody repo
Kim Alvefur <zash@zash.se>
parents: 123
diff changeset
288 return nil, "Required value missing";
34c52f3b21c4 util.dataforms: Update from Prosody repo
Kim Alvefur <zash@zash.se>
parents: 123
diff changeset
289 end
123
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
290 end
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
291
334
34c52f3b21c4 util.dataforms: Update from Prosody repo
Kim Alvefur <zash@zash.se>
parents: 123
diff changeset
292 field_readers["list-multi"] =
34c52f3b21c4 util.dataforms: Update from Prosody repo
Kim Alvefur <zash@zash.se>
parents: 123
diff changeset
293 function (field_tag, required)
123
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
294 local result = {};
334
34c52f3b21c4 util.dataforms: Update from Prosody repo
Kim Alvefur <zash@zash.se>
parents: 123
diff changeset
295 for value in field_tag:childtags("value") do
34c52f3b21c4 util.dataforms: Update from Prosody repo
Kim Alvefur <zash@zash.se>
parents: 123
diff changeset
296 result[#result+1] = value:get_text();
123
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
297 end
441
e4c0b1d7fd6b util.dataforms: Update from prosody trunk 5fb6563eee1e keeping from_stanza()
Kim Alvefur <zash@zash.se>
parents: 335
diff changeset
298 if #result > 0 then
e4c0b1d7fd6b util.dataforms: Update from prosody trunk 5fb6563eee1e keeping from_stanza()
Kim Alvefur <zash@zash.se>
parents: 335
diff changeset
299 return result;
e4c0b1d7fd6b util.dataforms: Update from prosody trunk 5fb6563eee1e keeping from_stanza()
Kim Alvefur <zash@zash.se>
parents: 335
diff changeset
300 elseif required then
e4c0b1d7fd6b util.dataforms: Update from prosody trunk 5fb6563eee1e keeping from_stanza()
Kim Alvefur <zash@zash.se>
parents: 335
diff changeset
301 return nil, "Required value missing";
e4c0b1d7fd6b util.dataforms: Update from prosody trunk 5fb6563eee1e keeping from_stanza()
Kim Alvefur <zash@zash.se>
parents: 335
diff changeset
302 end
334
34c52f3b21c4 util.dataforms: Update from Prosody repo
Kim Alvefur <zash@zash.se>
parents: 123
diff changeset
303 end
34c52f3b21c4 util.dataforms: Update from Prosody repo
Kim Alvefur <zash@zash.se>
parents: 123
diff changeset
304
34c52f3b21c4 util.dataforms: Update from Prosody repo
Kim Alvefur <zash@zash.se>
parents: 123
diff changeset
305 field_readers["text-multi"] =
34c52f3b21c4 util.dataforms: Update from Prosody repo
Kim Alvefur <zash@zash.se>
parents: 123
diff changeset
306 function (field_tag, required)
34c52f3b21c4 util.dataforms: Update from Prosody repo
Kim Alvefur <zash@zash.se>
parents: 123
diff changeset
307 local data, err = field_readers["list-multi"](field_tag, required);
34c52f3b21c4 util.dataforms: Update from Prosody repo
Kim Alvefur <zash@zash.se>
parents: 123
diff changeset
308 if data then
34c52f3b21c4 util.dataforms: Update from Prosody repo
Kim Alvefur <zash@zash.se>
parents: 123
diff changeset
309 data = t_concat(data, "\n");
34c52f3b21c4 util.dataforms: Update from Prosody repo
Kim Alvefur <zash@zash.se>
parents: 123
diff changeset
310 end
34c52f3b21c4 util.dataforms: Update from Prosody repo
Kim Alvefur <zash@zash.se>
parents: 123
diff changeset
311 return data, err;
123
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
312 end
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
313
441
e4c0b1d7fd6b util.dataforms: Update from prosody trunk 5fb6563eee1e keeping from_stanza()
Kim Alvefur <zash@zash.se>
parents: 335
diff changeset
314 field_readers["list-single"] = simple_text;
123
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
315
334
34c52f3b21c4 util.dataforms: Update from Prosody repo
Kim Alvefur <zash@zash.se>
parents: 123
diff changeset
316 local boolean_values = {
34c52f3b21c4 util.dataforms: Update from Prosody repo
Kim Alvefur <zash@zash.se>
parents: 123
diff changeset
317 ["1"] = true, ["true"] = true,
34c52f3b21c4 util.dataforms: Update from Prosody repo
Kim Alvefur <zash@zash.se>
parents: 123
diff changeset
318 ["0"] = false, ["false"] = false,
34c52f3b21c4 util.dataforms: Update from Prosody repo
Kim Alvefur <zash@zash.se>
parents: 123
diff changeset
319 };
34c52f3b21c4 util.dataforms: Update from Prosody repo
Kim Alvefur <zash@zash.se>
parents: 123
diff changeset
320
34c52f3b21c4 util.dataforms: Update from Prosody repo
Kim Alvefur <zash@zash.se>
parents: 123
diff changeset
321 field_readers["boolean"] =
34c52f3b21c4 util.dataforms: Update from Prosody repo
Kim Alvefur <zash@zash.se>
parents: 123
diff changeset
322 function (field_tag, required)
441
e4c0b1d7fd6b util.dataforms: Update from prosody trunk 5fb6563eee1e keeping from_stanza()
Kim Alvefur <zash@zash.se>
parents: 335
diff changeset
323 local raw_value, err = simple_text(field_tag, required);
e4c0b1d7fd6b util.dataforms: Update from prosody trunk 5fb6563eee1e keeping from_stanza()
Kim Alvefur <zash@zash.se>
parents: 335
diff changeset
324 if not raw_value then return raw_value, err; end
e4c0b1d7fd6b util.dataforms: Update from prosody trunk 5fb6563eee1e keeping from_stanza()
Kim Alvefur <zash@zash.se>
parents: 335
diff changeset
325 local value = boolean_values[raw_value];
e4c0b1d7fd6b util.dataforms: Update from prosody trunk 5fb6563eee1e keeping from_stanza()
Kim Alvefur <zash@zash.se>
parents: 335
diff changeset
326 if value == nil then
e4c0b1d7fd6b util.dataforms: Update from prosody trunk 5fb6563eee1e keeping from_stanza()
Kim Alvefur <zash@zash.se>
parents: 335
diff changeset
327 return nil, "Invalid boolean representation:" .. raw_value;
123
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
328 end
441
e4c0b1d7fd6b util.dataforms: Update from prosody trunk 5fb6563eee1e keeping from_stanza()
Kim Alvefur <zash@zash.se>
parents: 335
diff changeset
329 return value;
123
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
330 end
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
331
334
34c52f3b21c4 util.dataforms: Update from Prosody repo
Kim Alvefur <zash@zash.se>
parents: 123
diff changeset
332 field_readers["hidden"] =
123
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
333 function (field_tag)
334
34c52f3b21c4 util.dataforms: Update from Prosody repo
Kim Alvefur <zash@zash.se>
parents: 123
diff changeset
334 return field_tag:get_child_text("value");
123
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
335 end
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
336
441
e4c0b1d7fd6b util.dataforms: Update from prosody trunk 5fb6563eee1e keeping from_stanza()
Kim Alvefur <zash@zash.se>
parents: 335
diff changeset
337 data_validators["xs:integer"] =
e4c0b1d7fd6b util.dataforms: Update from prosody trunk 5fb6563eee1e keeping from_stanza()
Kim Alvefur <zash@zash.se>
parents: 335
diff changeset
338 function (data, field)
e4c0b1d7fd6b util.dataforms: Update from prosody trunk 5fb6563eee1e keeping from_stanza()
Kim Alvefur <zash@zash.se>
parents: 335
diff changeset
339 local n = tonumber(data);
e4c0b1d7fd6b util.dataforms: Update from prosody trunk 5fb6563eee1e keeping from_stanza()
Kim Alvefur <zash@zash.se>
parents: 335
diff changeset
340 if not n then
e4c0b1d7fd6b util.dataforms: Update from prosody trunk 5fb6563eee1e keeping from_stanza()
Kim Alvefur <zash@zash.se>
parents: 335
diff changeset
341 return false, "not a number";
e4c0b1d7fd6b util.dataforms: Update from prosody trunk 5fb6563eee1e keeping from_stanza()
Kim Alvefur <zash@zash.se>
parents: 335
diff changeset
342 elseif n % 1 ~= 0 then
e4c0b1d7fd6b util.dataforms: Update from prosody trunk 5fb6563eee1e keeping from_stanza()
Kim Alvefur <zash@zash.se>
parents: 335
diff changeset
343 return false, "not an integer";
e4c0b1d7fd6b util.dataforms: Update from prosody trunk 5fb6563eee1e keeping from_stanza()
Kim Alvefur <zash@zash.se>
parents: 335
diff changeset
344 end
e4c0b1d7fd6b util.dataforms: Update from prosody trunk 5fb6563eee1e keeping from_stanza()
Kim Alvefur <zash@zash.se>
parents: 335
diff changeset
345 if field.range_max and n > field.range_max then
e4c0b1d7fd6b util.dataforms: Update from prosody trunk 5fb6563eee1e keeping from_stanza()
Kim Alvefur <zash@zash.se>
parents: 335
diff changeset
346 return false, "out of bounds";
e4c0b1d7fd6b util.dataforms: Update from prosody trunk 5fb6563eee1e keeping from_stanza()
Kim Alvefur <zash@zash.se>
parents: 335
diff changeset
347 elseif field.range_min and n < field.range_min then
e4c0b1d7fd6b util.dataforms: Update from prosody trunk 5fb6563eee1e keeping from_stanza()
Kim Alvefur <zash@zash.se>
parents: 335
diff changeset
348 return false, "out of bounds";
e4c0b1d7fd6b util.dataforms: Update from prosody trunk 5fb6563eee1e keeping from_stanza()
Kim Alvefur <zash@zash.se>
parents: 335
diff changeset
349 end
e4c0b1d7fd6b util.dataforms: Update from prosody trunk 5fb6563eee1e keeping from_stanza()
Kim Alvefur <zash@zash.se>
parents: 335
diff changeset
350 return true, n;
e4c0b1d7fd6b util.dataforms: Update from prosody trunk 5fb6563eee1e keeping from_stanza()
Kim Alvefur <zash@zash.se>
parents: 335
diff changeset
351 end
e4c0b1d7fd6b util.dataforms: Update from prosody trunk 5fb6563eee1e keeping from_stanza()
Kim Alvefur <zash@zash.se>
parents: 335
diff changeset
352
e4c0b1d7fd6b util.dataforms: Update from prosody trunk 5fb6563eee1e keeping from_stanza()
Kim Alvefur <zash@zash.se>
parents: 335
diff changeset
353
e4c0b1d7fd6b util.dataforms: Update from prosody trunk 5fb6563eee1e keeping from_stanza()
Kim Alvefur <zash@zash.se>
parents: 335
diff changeset
354 local function get_form_type(form)
e4c0b1d7fd6b util.dataforms: Update from prosody trunk 5fb6563eee1e keeping from_stanza()
Kim Alvefur <zash@zash.se>
parents: 335
diff changeset
355 if not st.is_stanza(form) then
e4c0b1d7fd6b util.dataforms: Update from prosody trunk 5fb6563eee1e keeping from_stanza()
Kim Alvefur <zash@zash.se>
parents: 335
diff changeset
356 return nil, "not a stanza object";
e4c0b1d7fd6b util.dataforms: Update from prosody trunk 5fb6563eee1e keeping from_stanza()
Kim Alvefur <zash@zash.se>
parents: 335
diff changeset
357 elseif form.attr.xmlns ~= "jabber:x:data" or form.name ~= "x" then
e4c0b1d7fd6b util.dataforms: Update from prosody trunk 5fb6563eee1e keeping from_stanza()
Kim Alvefur <zash@zash.se>
parents: 335
diff changeset
358 return nil, "not a dataform element";
e4c0b1d7fd6b util.dataforms: Update from prosody trunk 5fb6563eee1e keeping from_stanza()
Kim Alvefur <zash@zash.se>
parents: 335
diff changeset
359 end
e4c0b1d7fd6b util.dataforms: Update from prosody trunk 5fb6563eee1e keeping from_stanza()
Kim Alvefur <zash@zash.se>
parents: 335
diff changeset
360 for field in form:childtags("field") do
e4c0b1d7fd6b util.dataforms: Update from prosody trunk 5fb6563eee1e keeping from_stanza()
Kim Alvefur <zash@zash.se>
parents: 335
diff changeset
361 if field.attr.var == "FORM_TYPE" then
e4c0b1d7fd6b util.dataforms: Update from prosody trunk 5fb6563eee1e keeping from_stanza()
Kim Alvefur <zash@zash.se>
parents: 335
diff changeset
362 return field:get_child_text("value");
e4c0b1d7fd6b util.dataforms: Update from prosody trunk 5fb6563eee1e keeping from_stanza()
Kim Alvefur <zash@zash.se>
parents: 335
diff changeset
363 end
e4c0b1d7fd6b util.dataforms: Update from prosody trunk 5fb6563eee1e keeping from_stanza()
Kim Alvefur <zash@zash.se>
parents: 335
diff changeset
364 end
e4c0b1d7fd6b util.dataforms: Update from prosody trunk 5fb6563eee1e keeping from_stanza()
Kim Alvefur <zash@zash.se>
parents: 335
diff changeset
365 return "";
e4c0b1d7fd6b util.dataforms: Update from prosody trunk 5fb6563eee1e keeping from_stanza()
Kim Alvefur <zash@zash.se>
parents: 335
diff changeset
366 end
e4c0b1d7fd6b util.dataforms: Update from prosody trunk 5fb6563eee1e keeping from_stanza()
Kim Alvefur <zash@zash.se>
parents: 335
diff changeset
367
e4c0b1d7fd6b util.dataforms: Update from prosody trunk 5fb6563eee1e keeping from_stanza()
Kim Alvefur <zash@zash.se>
parents: 335
diff changeset
368 return {
e4c0b1d7fd6b util.dataforms: Update from prosody trunk 5fb6563eee1e keeping from_stanza()
Kim Alvefur <zash@zash.se>
parents: 335
diff changeset
369 new = new;
e4c0b1d7fd6b util.dataforms: Update from prosody trunk 5fb6563eee1e keeping from_stanza()
Kim Alvefur <zash@zash.se>
parents: 335
diff changeset
370 from_stanza = from_stanza;
e4c0b1d7fd6b util.dataforms: Update from prosody trunk 5fb6563eee1e keeping from_stanza()
Kim Alvefur <zash@zash.se>
parents: 335
diff changeset
371 get_type = get_form_type;
e4c0b1d7fd6b util.dataforms: Update from prosody trunk 5fb6563eee1e keeping from_stanza()
Kim Alvefur <zash@zash.se>
parents: 335
diff changeset
372 };
123
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
373
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
374
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
375 --[=[
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
376
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
377 Layout:
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
378 {
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
379
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
380 title = "MUC Configuration",
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
381 instructions = [[Use this form to configure options for this MUC room.]],
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
382
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
383 { name = "FORM_TYPE", type = "hidden", required = true };
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
384 { name = "field-name", type = "field-type", required = false };
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
385 }
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
386
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
387
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
388 --]=]