Software /
code /
prosody
Annotate
util/dataforms.lua @ 3279:8b0a4a7d2c6e
MUC: Added room:can_set_role().
author | Waqas Hussain <waqas20@gmail.com> |
---|---|
date | Sat, 19 Jun 2010 23:35:53 +0500 |
parent | 2923:b7049746bd29 |
child | 3379:17d4298b2a58 |
rev | line source |
---|---|
1522
569d58d21612
Add copyright header to those files missing one
Matthew Wild <mwild1@gmail.com>
parents:
957
diff
changeset
|
1 -- Prosody IM |
2923
b7049746bd29
Update copyright headers for 2010
Matthew Wild <mwild1@gmail.com>
parents:
2838
diff
changeset
|
2 -- Copyright (C) 2008-2010 Matthew Wild |
b7049746bd29
Update copyright headers for 2010
Matthew Wild <mwild1@gmail.com>
parents:
2838
diff
changeset
|
3 -- Copyright (C) 2008-2010 Waqas Hussain |
1522
569d58d21612
Add copyright header to those files missing one
Matthew Wild <mwild1@gmail.com>
parents:
957
diff
changeset
|
4 -- |
569d58d21612
Add copyright header to those files missing one
Matthew Wild <mwild1@gmail.com>
parents:
957
diff
changeset
|
5 -- This project is MIT/X11 licensed. Please see the |
569d58d21612
Add copyright header to those files missing one
Matthew Wild <mwild1@gmail.com>
parents:
957
diff
changeset
|
6 -- COPYING file in the source package for more information. |
569d58d21612
Add copyright header to those files missing one
Matthew Wild <mwild1@gmail.com>
parents:
957
diff
changeset
|
7 -- |
569d58d21612
Add copyright header to those files missing one
Matthew Wild <mwild1@gmail.com>
parents:
957
diff
changeset
|
8 |
951
4b9207949735
util.dataforms: Fixed to actually work, mostly
Matthew Wild <mwild1@gmail.com>
parents:
851
diff
changeset
|
9 local setmetatable = setmetatable; |
4b9207949735
util.dataforms: Fixed to actually work, mostly
Matthew Wild <mwild1@gmail.com>
parents:
851
diff
changeset
|
10 local pairs, ipairs = pairs, ipairs; |
954
72e4639c9310
util.dataforms: Fixes for hidden field type
Matthew Wild <mwild1@gmail.com>
parents:
953
diff
changeset
|
11 local tostring, type = tostring, type; |
72e4639c9310
util.dataforms: Fixes for hidden field type
Matthew Wild <mwild1@gmail.com>
parents:
953
diff
changeset
|
12 local t_concat = table.concat; |
951
4b9207949735
util.dataforms: Fixed to actually work, mostly
Matthew Wild <mwild1@gmail.com>
parents:
851
diff
changeset
|
13 local st = require "util.stanza"; |
845
fc3dced9801e
util.dataforms: First commit, incomplete
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
14 |
fc3dced9801e
util.dataforms: First commit, incomplete
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
15 module "dataforms" |
fc3dced9801e
util.dataforms: First commit, incomplete
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
16 |
fc3dced9801e
util.dataforms: First commit, incomplete
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
17 local xmlns_forms = 'jabber:x:data'; |
fc3dced9801e
util.dataforms: First commit, incomplete
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
18 |
fc3dced9801e
util.dataforms: First commit, incomplete
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
19 local form_t = {}; |
fc3dced9801e
util.dataforms: First commit, incomplete
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
20 local form_mt = { __index = form_t }; |
fc3dced9801e
util.dataforms: First commit, incomplete
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
21 |
fc3dced9801e
util.dataforms: First commit, incomplete
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
22 function new(layout) |
fc3dced9801e
util.dataforms: First commit, incomplete
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
23 return setmetatable(layout, form_mt); |
fc3dced9801e
util.dataforms: First commit, incomplete
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
24 end |
fc3dced9801e
util.dataforms: First commit, incomplete
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
25 |
2838
586893d29eaf
util.dataforms: Add optional type parameters (defaults to 'form')
Matthew Wild <mwild1@gmail.com>
parents:
2219
diff
changeset
|
26 function form_t.form(layout, data, formtype) |
586893d29eaf
util.dataforms: Add optional type parameters (defaults to 'form')
Matthew Wild <mwild1@gmail.com>
parents:
2219
diff
changeset
|
27 local form = st.stanza("x", { xmlns = xmlns_forms, type = formtype or "form" }); |
951
4b9207949735
util.dataforms: Fixed to actually work, mostly
Matthew Wild <mwild1@gmail.com>
parents:
851
diff
changeset
|
28 if layout.title then |
4b9207949735
util.dataforms: Fixed to actually work, mostly
Matthew Wild <mwild1@gmail.com>
parents:
851
diff
changeset
|
29 form:tag("title"):text(layout.title):up(); |
4b9207949735
util.dataforms: Fixed to actually work, mostly
Matthew Wild <mwild1@gmail.com>
parents:
851
diff
changeset
|
30 end |
4b9207949735
util.dataforms: Fixed to actually work, mostly
Matthew Wild <mwild1@gmail.com>
parents:
851
diff
changeset
|
31 if layout.instructions then |
4b9207949735
util.dataforms: Fixed to actually work, mostly
Matthew Wild <mwild1@gmail.com>
parents:
851
diff
changeset
|
32 form:tag("instructions"):text(layout.instructions):up(); |
4b9207949735
util.dataforms: Fixed to actually work, mostly
Matthew Wild <mwild1@gmail.com>
parents:
851
diff
changeset
|
33 end |
845
fc3dced9801e
util.dataforms: First commit, incomplete
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
34 for n, field in ipairs(layout) do |
951
4b9207949735
util.dataforms: Fixed to actually work, mostly
Matthew Wild <mwild1@gmail.com>
parents:
851
diff
changeset
|
35 local field_type = field.type or "text-single"; |
845
fc3dced9801e
util.dataforms: First commit, incomplete
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
36 -- Add field tag |
951
4b9207949735
util.dataforms: Fixed to actually work, mostly
Matthew Wild <mwild1@gmail.com>
parents:
851
diff
changeset
|
37 form:tag("field", { type = field_type, var = field.name, label = field.label }); |
845
fc3dced9801e
util.dataforms: First commit, incomplete
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
38 |
1945
adfd7f3720f5
util.dataforms: Small fix to allow generating forms without specifying any input data
Matthew Wild <mwild1@gmail.com>
parents:
1944
diff
changeset
|
39 local value = (data and data[field.name]) or field.value; |
845
fc3dced9801e
util.dataforms: First commit, incomplete
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
40 |
2061
e34fdca432a9
util.dataforms: Only add value to rendered form if supplied in the data
Florian Zeitz
parents:
1958
diff
changeset
|
41 if value then |
e34fdca432a9
util.dataforms: Only add value to rendered form if supplied in the data
Florian Zeitz
parents:
1958
diff
changeset
|
42 -- Add value, depending on type |
e34fdca432a9
util.dataforms: Only add value to rendered form if supplied in the data
Florian Zeitz
parents:
1958
diff
changeset
|
43 if field_type == "hidden" then |
e34fdca432a9
util.dataforms: Only add value to rendered form if supplied in the data
Florian Zeitz
parents:
1958
diff
changeset
|
44 if type(value) == "table" then |
e34fdca432a9
util.dataforms: Only add value to rendered form if supplied in the data
Florian Zeitz
parents:
1958
diff
changeset
|
45 -- Assume an XML snippet |
e34fdca432a9
util.dataforms: Only add value to rendered form if supplied in the data
Florian Zeitz
parents:
1958
diff
changeset
|
46 form:tag("value") |
e34fdca432a9
util.dataforms: Only add value to rendered form if supplied in the data
Florian Zeitz
parents:
1958
diff
changeset
|
47 :add_child(value) |
e34fdca432a9
util.dataforms: Only add value to rendered form if supplied in the data
Florian Zeitz
parents:
1958
diff
changeset
|
48 :up(); |
1958
e2b0026143c4
util.dataforms: Incorporate slightly modified patch for list-single type from Florob
Matthew Wild <mwild1@gmail.com>
parents:
1945
diff
changeset
|
49 else |
2061
e34fdca432a9
util.dataforms: Only add value to rendered form if supplied in the data
Florian Zeitz
parents:
1958
diff
changeset
|
50 form:tag("value"):text(tostring(value)):up(); |
e34fdca432a9
util.dataforms: Only add value to rendered form if supplied in the data
Florian Zeitz
parents:
1958
diff
changeset
|
51 end |
e34fdca432a9
util.dataforms: Only add value to rendered form if supplied in the data
Florian Zeitz
parents:
1958
diff
changeset
|
52 elseif field_type == "boolean" then |
e34fdca432a9
util.dataforms: Only add value to rendered form if supplied in the data
Florian Zeitz
parents:
1958
diff
changeset
|
53 form:tag("value"):text((value and "1") or "0"):up(); |
e34fdca432a9
util.dataforms: Only add value to rendered form if supplied in the data
Florian Zeitz
parents:
1958
diff
changeset
|
54 elseif field_type == "fixed" then |
e34fdca432a9
util.dataforms: Only add value to rendered form if supplied in the data
Florian Zeitz
parents:
1958
diff
changeset
|
55 |
e34fdca432a9
util.dataforms: Only add value to rendered form if supplied in the data
Florian Zeitz
parents:
1958
diff
changeset
|
56 elseif field_type == "jid-multi" then |
e34fdca432a9
util.dataforms: Only add value to rendered form if supplied in the data
Florian Zeitz
parents:
1958
diff
changeset
|
57 for _, jid in ipairs(value) do |
e34fdca432a9
util.dataforms: Only add value to rendered form if supplied in the data
Florian Zeitz
parents:
1958
diff
changeset
|
58 form:tag("value"):text(jid):up(); |
e34fdca432a9
util.dataforms: Only add value to rendered form if supplied in the data
Florian Zeitz
parents:
1958
diff
changeset
|
59 end |
e34fdca432a9
util.dataforms: Only add value to rendered form if supplied in the data
Florian Zeitz
parents:
1958
diff
changeset
|
60 elseif field_type == "jid-single" then |
e34fdca432a9
util.dataforms: Only add value to rendered form if supplied in the data
Florian Zeitz
parents:
1958
diff
changeset
|
61 form:tag("value"):text(value):up(); |
e34fdca432a9
util.dataforms: Only add value to rendered form if supplied in the data
Florian Zeitz
parents:
1958
diff
changeset
|
62 elseif field_type == "text-single" or field_type == "text-private" then |
e34fdca432a9
util.dataforms: Only add value to rendered form if supplied in the data
Florian Zeitz
parents:
1958
diff
changeset
|
63 form:tag("value"):text(value):up(); |
e34fdca432a9
util.dataforms: Only add value to rendered form if supplied in the data
Florian Zeitz
parents:
1958
diff
changeset
|
64 elseif field_type == "text-multi" then |
e34fdca432a9
util.dataforms: Only add value to rendered form if supplied in the data
Florian Zeitz
parents:
1958
diff
changeset
|
65 -- Split into multiple <value> tags, one for each line |
e34fdca432a9
util.dataforms: Only add value to rendered form if supplied in the data
Florian Zeitz
parents:
1958
diff
changeset
|
66 for line in value:gmatch("([^\r\n]+)\r?\n*") do |
e34fdca432a9
util.dataforms: Only add value to rendered form if supplied in the data
Florian Zeitz
parents:
1958
diff
changeset
|
67 form:tag("value"):text(line):up(); |
e34fdca432a9
util.dataforms: Only add value to rendered form if supplied in the data
Florian Zeitz
parents:
1958
diff
changeset
|
68 end |
e34fdca432a9
util.dataforms: Only add value to rendered form if supplied in the data
Florian Zeitz
parents:
1958
diff
changeset
|
69 elseif field_type == "list-single" then |
e34fdca432a9
util.dataforms: Only add value to rendered form if supplied in the data
Florian Zeitz
parents:
1958
diff
changeset
|
70 for _, val in ipairs(value) do |
e34fdca432a9
util.dataforms: Only add value to rendered form if supplied in the data
Florian Zeitz
parents:
1958
diff
changeset
|
71 if type(val) == "table" then |
e34fdca432a9
util.dataforms: Only add value to rendered form if supplied in the data
Florian Zeitz
parents:
1958
diff
changeset
|
72 form:tag("option", { label = val.label }):tag("value"):text(val.value):up():up(); |
e34fdca432a9
util.dataforms: Only add value to rendered form if supplied in the data
Florian Zeitz
parents:
1958
diff
changeset
|
73 else |
e34fdca432a9
util.dataforms: Only add value to rendered form if supplied in the data
Florian Zeitz
parents:
1958
diff
changeset
|
74 form:tag("option", { label= val }):tag("value"):text(tostring(val)):up():up(); |
e34fdca432a9
util.dataforms: Only add value to rendered form if supplied in the data
Florian Zeitz
parents:
1958
diff
changeset
|
75 end |
1958
e2b0026143c4
util.dataforms: Incorporate slightly modified patch for list-single type from Florob
Matthew Wild <mwild1@gmail.com>
parents:
1945
diff
changeset
|
76 end |
e2b0026143c4
util.dataforms: Incorporate slightly modified patch for list-single type from Florob
Matthew Wild <mwild1@gmail.com>
parents:
1945
diff
changeset
|
77 end |
845
fc3dced9801e
util.dataforms: First commit, incomplete
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
78 end |
fc3dced9801e
util.dataforms: First commit, incomplete
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
79 |
952
ef648f49e734
util.dataforms: Add support for <required/> fields
Matthew Wild <mwild1@gmail.com>
parents:
951
diff
changeset
|
80 if field.required then |
ef648f49e734
util.dataforms: Add support for <required/> fields
Matthew Wild <mwild1@gmail.com>
parents:
951
diff
changeset
|
81 form:tag("required"):up(); |
ef648f49e734
util.dataforms: Add support for <required/> fields
Matthew Wild <mwild1@gmail.com>
parents:
951
diff
changeset
|
82 end |
ef648f49e734
util.dataforms: Add support for <required/> fields
Matthew Wild <mwild1@gmail.com>
parents:
951
diff
changeset
|
83 |
845
fc3dced9801e
util.dataforms: First commit, incomplete
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
84 -- Jump back up to list of fields |
fc3dced9801e
util.dataforms: First commit, incomplete
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
85 form:up(); |
fc3dced9801e
util.dataforms: First commit, incomplete
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
86 end |
851
b48c7ed3f7f8
util.dataforms: Return the form
Matthew Wild <mwild1@gmail.com>
parents:
845
diff
changeset
|
87 return form; |
845
fc3dced9801e
util.dataforms: First commit, incomplete
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
88 end |
fc3dced9801e
util.dataforms: First commit, incomplete
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
89 |
955
98ca5a753fee
util.dataforms: Support for retriving the field value data from forms
Matthew Wild <mwild1@gmail.com>
parents:
954
diff
changeset
|
90 local field_readers = {}; |
98ca5a753fee
util.dataforms: Support for retriving the field value data from forms
Matthew Wild <mwild1@gmail.com>
parents:
954
diff
changeset
|
91 |
845
fc3dced9801e
util.dataforms: First commit, incomplete
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
92 function form_t.data(layout, stanza) |
955
98ca5a753fee
util.dataforms: Support for retriving the field value data from forms
Matthew Wild <mwild1@gmail.com>
parents:
954
diff
changeset
|
93 local data = {}; |
845
fc3dced9801e
util.dataforms: First commit, incomplete
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
94 |
955
98ca5a753fee
util.dataforms: Support for retriving the field value data from forms
Matthew Wild <mwild1@gmail.com>
parents:
954
diff
changeset
|
95 for field_tag in stanza:childtags() do |
2219
9e1c6b6a2ee4
util.dataforms: Don't require type when parsing form XML
Florian Zeitz
parents:
2070
diff
changeset
|
96 local field_type; |
9e1c6b6a2ee4
util.dataforms: Don't require type when parsing form XML
Florian Zeitz
parents:
2070
diff
changeset
|
97 for n, field in ipairs(layout) do |
9e1c6b6a2ee4
util.dataforms: Don't require type when parsing form XML
Florian Zeitz
parents:
2070
diff
changeset
|
98 if field.name == field_tag.attr.var then |
9e1c6b6a2ee4
util.dataforms: Don't require type when parsing form XML
Florian Zeitz
parents:
2070
diff
changeset
|
99 field_type = field.type; |
9e1c6b6a2ee4
util.dataforms: Don't require type when parsing form XML
Florian Zeitz
parents:
2070
diff
changeset
|
100 break; |
9e1c6b6a2ee4
util.dataforms: Don't require type when parsing form XML
Florian Zeitz
parents:
2070
diff
changeset
|
101 end |
9e1c6b6a2ee4
util.dataforms: Don't require type when parsing form XML
Florian Zeitz
parents:
2070
diff
changeset
|
102 end |
955
98ca5a753fee
util.dataforms: Support for retriving the field value data from forms
Matthew Wild <mwild1@gmail.com>
parents:
954
diff
changeset
|
103 |
98ca5a753fee
util.dataforms: Support for retriving the field value data from forms
Matthew Wild <mwild1@gmail.com>
parents:
954
diff
changeset
|
104 local reader = field_readers[field_type]; |
98ca5a753fee
util.dataforms: Support for retriving the field value data from forms
Matthew Wild <mwild1@gmail.com>
parents:
954
diff
changeset
|
105 if reader then |
98ca5a753fee
util.dataforms: Support for retriving the field value data from forms
Matthew Wild <mwild1@gmail.com>
parents:
954
diff
changeset
|
106 data[field_tag.attr.var] = reader(field_tag); |
98ca5a753fee
util.dataforms: Support for retriving the field value data from forms
Matthew Wild <mwild1@gmail.com>
parents:
954
diff
changeset
|
107 end |
98ca5a753fee
util.dataforms: Support for retriving the field value data from forms
Matthew Wild <mwild1@gmail.com>
parents:
954
diff
changeset
|
108 |
98ca5a753fee
util.dataforms: Support for retriving the field value data from forms
Matthew Wild <mwild1@gmail.com>
parents:
954
diff
changeset
|
109 end |
98ca5a753fee
util.dataforms: Support for retriving the field value data from forms
Matthew Wild <mwild1@gmail.com>
parents:
954
diff
changeset
|
110 return data; |
845
fc3dced9801e
util.dataforms: First commit, incomplete
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
111 end |
fc3dced9801e
util.dataforms: First commit, incomplete
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
112 |
955
98ca5a753fee
util.dataforms: Support for retriving the field value data from forms
Matthew Wild <mwild1@gmail.com>
parents:
954
diff
changeset
|
113 field_readers["text-single"] = |
98ca5a753fee
util.dataforms: Support for retriving the field value data from forms
Matthew Wild <mwild1@gmail.com>
parents:
954
diff
changeset
|
114 function (field_tag) |
98ca5a753fee
util.dataforms: Support for retriving the field value data from forms
Matthew Wild <mwild1@gmail.com>
parents:
954
diff
changeset
|
115 local value = field_tag:child_with_name("value"); |
98ca5a753fee
util.dataforms: Support for retriving the field value data from forms
Matthew Wild <mwild1@gmail.com>
parents:
954
diff
changeset
|
116 if value then |
98ca5a753fee
util.dataforms: Support for retriving the field value data from forms
Matthew Wild <mwild1@gmail.com>
parents:
954
diff
changeset
|
117 return value[1]; |
98ca5a753fee
util.dataforms: Support for retriving the field value data from forms
Matthew Wild <mwild1@gmail.com>
parents:
954
diff
changeset
|
118 end |
98ca5a753fee
util.dataforms: Support for retriving the field value data from forms
Matthew Wild <mwild1@gmail.com>
parents:
954
diff
changeset
|
119 end |
98ca5a753fee
util.dataforms: Support for retriving the field value data from forms
Matthew Wild <mwild1@gmail.com>
parents:
954
diff
changeset
|
120 |
98ca5a753fee
util.dataforms: Support for retriving the field value data from forms
Matthew Wild <mwild1@gmail.com>
parents:
954
diff
changeset
|
121 field_readers["text-private"] = |
98ca5a753fee
util.dataforms: Support for retriving the field value data from forms
Matthew Wild <mwild1@gmail.com>
parents:
954
diff
changeset
|
122 field_readers["text-single"]; |
98ca5a753fee
util.dataforms: Support for retriving the field value data from forms
Matthew Wild <mwild1@gmail.com>
parents:
954
diff
changeset
|
123 |
1944
754eebd31538
util.dataforms: Support for jid-single field type especially for Florob :)
Matthew Wild <mwild1@gmail.com>
parents:
1522
diff
changeset
|
124 field_readers["jid-single"] = |
754eebd31538
util.dataforms: Support for jid-single field type especially for Florob :)
Matthew Wild <mwild1@gmail.com>
parents:
1522
diff
changeset
|
125 field_readers["text-single"]; |
754eebd31538
util.dataforms: Support for jid-single field type especially for Florob :)
Matthew Wild <mwild1@gmail.com>
parents:
1522
diff
changeset
|
126 |
2070
25dc4b9d06b1
util.dataforms: Support for jid-multi field type
Florian Zeitz
parents:
2061
diff
changeset
|
127 field_readers["jid-multi"] = |
25dc4b9d06b1
util.dataforms: Support for jid-multi field type
Florian Zeitz
parents:
2061
diff
changeset
|
128 function (field_tag) |
25dc4b9d06b1
util.dataforms: Support for jid-multi field type
Florian Zeitz
parents:
2061
diff
changeset
|
129 local result = {}; |
25dc4b9d06b1
util.dataforms: Support for jid-multi field type
Florian Zeitz
parents:
2061
diff
changeset
|
130 for value_tag in field_tag:childtags() do |
25dc4b9d06b1
util.dataforms: Support for jid-multi field type
Florian Zeitz
parents:
2061
diff
changeset
|
131 if value_tag.name == "value" then |
25dc4b9d06b1
util.dataforms: Support for jid-multi field type
Florian Zeitz
parents:
2061
diff
changeset
|
132 result[#result+1] = value_tag[1]; |
25dc4b9d06b1
util.dataforms: Support for jid-multi field type
Florian Zeitz
parents:
2061
diff
changeset
|
133 end |
25dc4b9d06b1
util.dataforms: Support for jid-multi field type
Florian Zeitz
parents:
2061
diff
changeset
|
134 end |
25dc4b9d06b1
util.dataforms: Support for jid-multi field type
Florian Zeitz
parents:
2061
diff
changeset
|
135 return result; |
25dc4b9d06b1
util.dataforms: Support for jid-multi field type
Florian Zeitz
parents:
2061
diff
changeset
|
136 end |
25dc4b9d06b1
util.dataforms: Support for jid-multi field type
Florian Zeitz
parents:
2061
diff
changeset
|
137 |
955
98ca5a753fee
util.dataforms: Support for retriving the field value data from forms
Matthew Wild <mwild1@gmail.com>
parents:
954
diff
changeset
|
138 field_readers["text-multi"] = |
98ca5a753fee
util.dataforms: Support for retriving the field value data from forms
Matthew Wild <mwild1@gmail.com>
parents:
954
diff
changeset
|
139 function (field_tag) |
98ca5a753fee
util.dataforms: Support for retriving the field value data from forms
Matthew Wild <mwild1@gmail.com>
parents:
954
diff
changeset
|
140 local result = {}; |
98ca5a753fee
util.dataforms: Support for retriving the field value data from forms
Matthew Wild <mwild1@gmail.com>
parents:
954
diff
changeset
|
141 for value_tag in field_tag:childtags() do |
98ca5a753fee
util.dataforms: Support for retriving the field value data from forms
Matthew Wild <mwild1@gmail.com>
parents:
954
diff
changeset
|
142 if value_tag.name == "value" then |
98ca5a753fee
util.dataforms: Support for retriving the field value data from forms
Matthew Wild <mwild1@gmail.com>
parents:
954
diff
changeset
|
143 result[#result+1] = value_tag[1]; |
98ca5a753fee
util.dataforms: Support for retriving the field value data from forms
Matthew Wild <mwild1@gmail.com>
parents:
954
diff
changeset
|
144 end |
98ca5a753fee
util.dataforms: Support for retriving the field value data from forms
Matthew Wild <mwild1@gmail.com>
parents:
954
diff
changeset
|
145 end |
98ca5a753fee
util.dataforms: Support for retriving the field value data from forms
Matthew Wild <mwild1@gmail.com>
parents:
954
diff
changeset
|
146 return t_concat(result, "\n"); |
98ca5a753fee
util.dataforms: Support for retriving the field value data from forms
Matthew Wild <mwild1@gmail.com>
parents:
954
diff
changeset
|
147 end |
98ca5a753fee
util.dataforms: Support for retriving the field value data from forms
Matthew Wild <mwild1@gmail.com>
parents:
954
diff
changeset
|
148 |
1958
e2b0026143c4
util.dataforms: Incorporate slightly modified patch for list-single type from Florob
Matthew Wild <mwild1@gmail.com>
parents:
1945
diff
changeset
|
149 field_readers["list-single"] = |
e2b0026143c4
util.dataforms: Incorporate slightly modified patch for list-single type from Florob
Matthew Wild <mwild1@gmail.com>
parents:
1945
diff
changeset
|
150 field_readers["text-single"]; |
e2b0026143c4
util.dataforms: Incorporate slightly modified patch for list-single type from Florob
Matthew Wild <mwild1@gmail.com>
parents:
1945
diff
changeset
|
151 |
955
98ca5a753fee
util.dataforms: Support for retriving the field value data from forms
Matthew Wild <mwild1@gmail.com>
parents:
954
diff
changeset
|
152 field_readers["boolean"] = |
98ca5a753fee
util.dataforms: Support for retriving the field value data from forms
Matthew Wild <mwild1@gmail.com>
parents:
954
diff
changeset
|
153 function (field_tag) |
98ca5a753fee
util.dataforms: Support for retriving the field value data from forms
Matthew Wild <mwild1@gmail.com>
parents:
954
diff
changeset
|
154 local value = field_tag:child_with_name("value"); |
98ca5a753fee
util.dataforms: Support for retriving the field value data from forms
Matthew Wild <mwild1@gmail.com>
parents:
954
diff
changeset
|
155 if value then |
98ca5a753fee
util.dataforms: Support for retriving the field value data from forms
Matthew Wild <mwild1@gmail.com>
parents:
954
diff
changeset
|
156 if value[1] == "1" or value[1] == "true" then |
98ca5a753fee
util.dataforms: Support for retriving the field value data from forms
Matthew Wild <mwild1@gmail.com>
parents:
954
diff
changeset
|
157 return true; |
98ca5a753fee
util.dataforms: Support for retriving the field value data from forms
Matthew Wild <mwild1@gmail.com>
parents:
954
diff
changeset
|
158 else |
98ca5a753fee
util.dataforms: Support for retriving the field value data from forms
Matthew Wild <mwild1@gmail.com>
parents:
954
diff
changeset
|
159 return false; |
98ca5a753fee
util.dataforms: Support for retriving the field value data from forms
Matthew Wild <mwild1@gmail.com>
parents:
954
diff
changeset
|
160 end |
98ca5a753fee
util.dataforms: Support for retriving the field value data from forms
Matthew Wild <mwild1@gmail.com>
parents:
954
diff
changeset
|
161 end |
98ca5a753fee
util.dataforms: Support for retriving the field value data from forms
Matthew Wild <mwild1@gmail.com>
parents:
954
diff
changeset
|
162 end |
98ca5a753fee
util.dataforms: Support for retriving the field value data from forms
Matthew Wild <mwild1@gmail.com>
parents:
954
diff
changeset
|
163 |
98ca5a753fee
util.dataforms: Support for retriving the field value data from forms
Matthew Wild <mwild1@gmail.com>
parents:
954
diff
changeset
|
164 field_readers["hidden"] = |
98ca5a753fee
util.dataforms: Support for retriving the field value data from forms
Matthew Wild <mwild1@gmail.com>
parents:
954
diff
changeset
|
165 function (field_tag) |
98ca5a753fee
util.dataforms: Support for retriving the field value data from forms
Matthew Wild <mwild1@gmail.com>
parents:
954
diff
changeset
|
166 local value = field_tag:child_with_name("value"); |
98ca5a753fee
util.dataforms: Support for retriving the field value data from forms
Matthew Wild <mwild1@gmail.com>
parents:
954
diff
changeset
|
167 if value then |
98ca5a753fee
util.dataforms: Support for retriving the field value data from forms
Matthew Wild <mwild1@gmail.com>
parents:
954
diff
changeset
|
168 return value[1]; |
98ca5a753fee
util.dataforms: Support for retriving the field value data from forms
Matthew Wild <mwild1@gmail.com>
parents:
954
diff
changeset
|
169 end |
98ca5a753fee
util.dataforms: Support for retriving the field value data from forms
Matthew Wild <mwild1@gmail.com>
parents:
954
diff
changeset
|
170 end |
98ca5a753fee
util.dataforms: Support for retriving the field value data from forms
Matthew Wild <mwild1@gmail.com>
parents:
954
diff
changeset
|
171 |
951
4b9207949735
util.dataforms: Fixed to actually work, mostly
Matthew Wild <mwild1@gmail.com>
parents:
851
diff
changeset
|
172 return _M; |
845
fc3dced9801e
util.dataforms: First commit, incomplete
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
173 |
fc3dced9801e
util.dataforms: First commit, incomplete
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
174 |
951
4b9207949735
util.dataforms: Fixed to actually work, mostly
Matthew Wild <mwild1@gmail.com>
parents:
851
diff
changeset
|
175 --[=[ |
845
fc3dced9801e
util.dataforms: First commit, incomplete
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
176 |
fc3dced9801e
util.dataforms: First commit, incomplete
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
177 Layout: |
fc3dced9801e
util.dataforms: First commit, incomplete
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
178 { |
fc3dced9801e
util.dataforms: First commit, incomplete
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
179 |
fc3dced9801e
util.dataforms: First commit, incomplete
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
180 title = "MUC Configuration", |
fc3dced9801e
util.dataforms: First commit, incomplete
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
181 instructions = [[Use this form to configure options for this MUC room.]], |
fc3dced9801e
util.dataforms: First commit, incomplete
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
182 |
fc3dced9801e
util.dataforms: First commit, incomplete
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
183 { name = "FORM_TYPE", type = "hidden", required = true }; |
fc3dced9801e
util.dataforms: First commit, incomplete
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
184 { name = "field-name", type = "field-type", required = false }; |
fc3dced9801e
util.dataforms: First commit, incomplete
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
185 } |
fc3dced9801e
util.dataforms: First commit, incomplete
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
186 |
fc3dced9801e
util.dataforms: First commit, incomplete
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
187 |
951
4b9207949735
util.dataforms: Fixed to actually work, mostly
Matthew Wild <mwild1@gmail.com>
parents:
851
diff
changeset
|
188 --]=] |