Software /
code /
prosody
Comparison
util/dataforms.lua @ 955:98ca5a753fee
util.dataforms: Support for retriving the field value data from forms
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Sat, 04 Apr 2009 18:08:35 +0100 |
parent | 954:72e4639c9310 |
child | 956:4c3f3d60a2f4 |
comparison
equal
deleted
inserted
replaced
954:72e4639c9310 | 955:98ca5a753fee |
---|---|
70 form:up(); | 70 form:up(); |
71 end | 71 end |
72 return form; | 72 return form; |
73 end | 73 end |
74 | 74 |
75 local field_readers = {}; | |
76 | |
75 function form_t.data(layout, stanza) | 77 function form_t.data(layout, stanza) |
78 local data = {}; | |
76 | 79 |
80 for field_tag in stanza:childtags() do | |
81 local field_type = field_tag.attr.type; | |
82 | |
83 local reader = field_readers[field_type]; | |
84 if reader then | |
85 data[field_tag.attr.var] = reader(field_tag); | |
86 end | |
87 | |
88 end | |
89 return data; | |
77 end | 90 end |
78 | 91 |
92 field_readers["text-single"] = | |
93 function (field_tag) | |
94 local value = field_tag:child_with_name("value"); | |
95 if value then | |
96 return value[1]; | |
97 end | |
98 end | |
99 | |
100 field_readers["text-private"] = | |
101 field_readers["text-single"]; | |
102 | |
103 field_readers["text-multi"] = | |
104 function (field_tag) | |
105 local result = {}; | |
106 for value_tag in field_tag:childtags() do | |
107 if value_tag.name == "value" then | |
108 result[#result+1] = value_tag[1]; | |
109 end | |
110 end | |
111 return t_concat(result, "\n"); | |
112 end | |
113 | |
114 field_readers["boolean"] = | |
115 function (field_tag) | |
116 local value = field_tag:child_with_name("value"); | |
117 if value then | |
118 if value[1] == "1" or value[1] == "true" then | |
119 return true; | |
120 else | |
121 return false; | |
122 end | |
123 end | |
124 end | |
125 | |
126 field_readers["hidden"] = | |
127 function (field_tag) | |
128 local value = field_tag:child_with_name("value"); | |
129 if value then | |
130 return value[1]; | |
131 end | |
132 end | |
133 | |
79 return _M; | 134 return _M; |
80 | 135 |
81 | 136 |
82 --[=[ | 137 --[=[ |
83 | 138 |