Annotate

util/dataforms.lua @ 283:39ce7535887c

plugins.pubsub: Add a local variable to save some table lookups
author Kim Alvefur <zash@zash.se>
date Mon, 05 Mar 2012 20:18:54 +0100
parent 123:8a079aa70b84
child 334:34c52f3b21c4
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
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
4 --
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;
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
10 local pairs, ipairs = pairs, ipairs;
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
11 local tostring, type = tostring, type;
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
12 local t_concat = table.concat;
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
13 local st = require "util.stanza";
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
14
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
15 module "dataforms"
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
16
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
17 local xmlns_forms = 'jabber:x:data';
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
18
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
19 local form_t = {};
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
20 local form_mt = { __index = form_t };
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
21
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
22 function new(layout)
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
23 return setmetatable(layout, form_mt);
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
24 end
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
25
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
26 function form_t.form(layout, data, formtype)
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
27 local form = st.stanza("x", { xmlns = xmlns_forms, type = formtype or "form" });
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
28 if layout.title then
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
29 form:tag("title"):text(layout.title):up();
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
30 end
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
31 if layout.instructions then
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
32 form:tag("instructions"):text(layout.instructions):up();
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
33 end
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
34 for n, field in ipairs(layout) do
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
35 local field_type = field.type or "text-single";
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
36 -- Add field tag
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
37 form:tag("field", { type = field_type, var = field.name, label = field.label });
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
38
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
39 local value = (data and data[field.name]) or field.value;
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
40
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
41 if value then
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
42 -- Add value, depending on type
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
43 if field_type == "hidden" then
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
44 if type(value) == "table" then
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
45 -- Assume an XML snippet
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
46 form:tag("value")
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
47 :add_child(value)
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
48 :up();
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
49 else
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
50 form:tag("value"):text(tostring(value)):up();
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
51 end
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
52 elseif field_type == "boolean" then
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
53 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
54 elseif field_type == "fixed" then
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
55
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
56 elseif field_type == "jid-multi" then
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
57 for _, jid in ipairs(value) do
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
58 form:tag("value"):text(jid):up();
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
59 end
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
60 elseif field_type == "jid-single" then
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
61 form:tag("value"):text(value):up();
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
62 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
63 form:tag("value"):text(value):up();
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
64 elseif field_type == "text-multi" then
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
65 -- 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
66 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
67 form:tag("value"):text(line):up();
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
68 end
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
69 elseif field_type == "list-single" then
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
70 local has_default = false;
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
71 if type(value) == "string" then
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
72 form:tag("value"):text(value):up();
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
73 else
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
74 for _, val in ipairs(value) do
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
75 if type(val) == "table" then
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
76 form:tag("option", { label = val.label }):tag("value"):text(val.value):up():up();
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
77 if val.default and (not has_default) then
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
78 form:tag("value"):text(val.value):up();
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
79 has_default = true;
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
80 end
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
81 else
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
82 form:tag("option", { label= val }):tag("value"):text(tostring(val)):up():up();
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
83 end
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
84 end
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
85 end
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
86 elseif field_type == "list-multi" then
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
87 for _, val in ipairs(value) do
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
88 if type(val) == "table" then
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
89 form:tag("option", { label = val.label }):tag("value"):text(val.value):up():up();
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
90 if val.default then
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
91 form:tag("value"):text(val.value):up();
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
92 end
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
93 else
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
94 form:tag("option", { label= val }):tag("value"):text(tostring(val)):up():up();
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
95 end
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
96 end
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
97 end
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
98 end
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
99
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
100 if field.required then
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
101 form:tag("required"):up();
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
102 end
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
103
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
104 -- Jump back up to list of fields
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
105 form:up();
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
106 end
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
107 return form;
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
108 end
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
109
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
110 local field_readers = {};
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
111
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
112 function form_t.data(layout, stanza)
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
113 local data = {};
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
114
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
115 for field_tag in stanza:childtags() do
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
116 local field_type;
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
117 for n, field in ipairs(layout) do
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
118 if field.name == field_tag.attr.var then
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
119 field_type = field.type;
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
120 break;
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
121 end
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
122 end
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
123
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
124 local reader = field_readers[field_type];
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
125 if reader then
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
126 data[field_tag.attr.var] = reader(field_tag);
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
127 end
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
128
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
129 end
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
130 return data;
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
131 end
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
132
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
133 field_readers["text-single"] =
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
134 function (field_tag)
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
135 local value = field_tag:child_with_name("value");
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
136 if value then
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
137 return value[1];
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
138 end
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
139 end
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
140
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
141 field_readers["text-private"] =
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
142 field_readers["text-single"];
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
143
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
144 field_readers["jid-single"] =
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
145 field_readers["text-single"];
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
146
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
147 field_readers["jid-multi"] =
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
148 function (field_tag)
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
149 local result = {};
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
150 for value_tag in field_tag:childtags() do
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
151 if value_tag.name == "value" then
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
152 result[#result+1] = value_tag[1];
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
153 end
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
154 end
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
155 return result;
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
156 end
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
157
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
158 field_readers["text-multi"] =
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
159 function (field_tag)
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
160 local result = {};
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
161 for value_tag in field_tag:childtags() do
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
162 if value_tag.name == "value" then
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
163 result[#result+1] = value_tag[1];
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
164 end
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
165 end
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
166 return t_concat(result, "\n");
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
167 end
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
168
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
169 field_readers["list-single"] =
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
170 field_readers["text-single"];
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
171
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
172 field_readers["list-multi"] =
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
173 function (field_tag)
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
174 local result = {};
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
175 for value_tag in field_tag:childtags() do
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
176 if value_tag.name == "value" then
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
177 result[#result+1] = value_tag[1];
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 return result;
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
181 end
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
182
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
183 field_readers["boolean"] =
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
184 function (field_tag)
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
185 local value = field_tag:child_with_name("value");
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
186 if value then
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
187 if value[1] == "1" or value[1] == "true" then
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
188 return true;
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
189 else
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
190 return false;
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
191 end
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
192 end
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
193 end
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
194
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
195 field_readers["hidden"] =
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
196 function (field_tag)
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
197 local value = field_tag:child_with_name("value");
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
198 if value then
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
199 return value[1];
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
200 end
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
201 end
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
202
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
203 return _M;
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
204
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
205
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
206 --[=[
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
207
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
208 Layout:
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
209 {
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
210
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
211 title = "MUC Configuration",
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
212 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
213
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
214 { name = "FORM_TYPE", type = "hidden", required = true };
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
215 { name = "field-name", type = "field-type", required = false };
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
216 }
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
217
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
218
8a079aa70b84 util.dataforms, squishy: Add util.dataforms library
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
219 --]=]