Software /
code /
prosody-modules
Annotate
mod_adhoc_dataforms_demo/mod_adhoc_dataforms_demo.lua @ 3556:0d97cde1c7b0
mod_adhoc_dataforms_demo: Reorder form fields
Group similar fields and order by complexity
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Sat, 06 Apr 2019 18:07:02 +0200 |
parent | 3555:78d4e631bc5f |
child | 3557:54b4b020de4c |
rev | line source |
---|---|
3211
2969ed764fe8
mod_adhoc_test: A module to test dataforms generation and rendering
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
1 local dataforms = require "util.dataforms"; |
2969ed764fe8
mod_adhoc_test: A module to test dataforms generation and rendering
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
2 local adhoc_util = require "util.adhoc"; |
2969ed764fe8
mod_adhoc_test: A module to test dataforms generation and rendering
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
3 local serialization = require "util.serialization"; |
2969ed764fe8
mod_adhoc_test: A module to test dataforms generation and rendering
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
4 |
2969ed764fe8
mod_adhoc_test: A module to test dataforms generation and rendering
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
5 local adhoc_new = module:require "adhoc".new; |
2969ed764fe8
mod_adhoc_test: A module to test dataforms generation and rendering
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
6 |
2969ed764fe8
mod_adhoc_test: A module to test dataforms generation and rendering
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
7 -- Dataform borrowed from Prosodys busted test for util.dataforms |
2969ed764fe8
mod_adhoc_test: A module to test dataforms generation and rendering
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
8 local form = dataforms.new({ |
2969ed764fe8
mod_adhoc_test: A module to test dataforms generation and rendering
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
9 title = "form-title", |
2969ed764fe8
mod_adhoc_test: A module to test dataforms generation and rendering
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
10 instructions = "form-instructions", |
2969ed764fe8
mod_adhoc_test: A module to test dataforms generation and rendering
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
11 { |
2969ed764fe8
mod_adhoc_test: A module to test dataforms generation and rendering
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
12 type = "hidden", |
2969ed764fe8
mod_adhoc_test: A module to test dataforms generation and rendering
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
13 name = "FORM_TYPE", |
2969ed764fe8
mod_adhoc_test: A module to test dataforms generation and rendering
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
14 value = "xmpp:prosody.im/spec/util.dataforms#1", |
2969ed764fe8
mod_adhoc_test: A module to test dataforms generation and rendering
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
15 }; |
2969ed764fe8
mod_adhoc_test: A module to test dataforms generation and rendering
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
16 { |
2969ed764fe8
mod_adhoc_test: A module to test dataforms generation and rendering
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
17 type = "fixed", |
2969ed764fe8
mod_adhoc_test: A module to test dataforms generation and rendering
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
18 label = "fixed-label", |
3556
0d97cde1c7b0
mod_adhoc_dataforms_demo: Reorder form fields
Kim Alvefur <zash@zash.se>
parents:
3555
diff
changeset
|
19 name = "fixed-field#1", |
3211
2969ed764fe8
mod_adhoc_test: A module to test dataforms generation and rendering
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
20 value = "fixed-value", |
2969ed764fe8
mod_adhoc_test: A module to test dataforms generation and rendering
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
21 }, |
2969ed764fe8
mod_adhoc_test: A module to test dataforms generation and rendering
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
22 { |
2969ed764fe8
mod_adhoc_test: A module to test dataforms generation and rendering
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
23 type = "hidden", |
2969ed764fe8
mod_adhoc_test: A module to test dataforms generation and rendering
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
24 label = "hidden-label", |
2969ed764fe8
mod_adhoc_test: A module to test dataforms generation and rendering
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
25 name = "hidden-field", |
2969ed764fe8
mod_adhoc_test: A module to test dataforms generation and rendering
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
26 value = "hidden-value", |
2969ed764fe8
mod_adhoc_test: A module to test dataforms generation and rendering
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
27 }, |
2969ed764fe8
mod_adhoc_test: A module to test dataforms generation and rendering
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
28 { |
3556
0d97cde1c7b0
mod_adhoc_dataforms_demo: Reorder form fields
Kim Alvefur <zash@zash.se>
parents:
3555
diff
changeset
|
29 type = "text-single", |
0d97cde1c7b0
mod_adhoc_dataforms_demo: Reorder form fields
Kim Alvefur <zash@zash.se>
parents:
3555
diff
changeset
|
30 label = "text-single-label", |
0d97cde1c7b0
mod_adhoc_dataforms_demo: Reorder form fields
Kim Alvefur <zash@zash.se>
parents:
3555
diff
changeset
|
31 name = "text-single-field", |
0d97cde1c7b0
mod_adhoc_dataforms_demo: Reorder form fields
Kim Alvefur <zash@zash.se>
parents:
3555
diff
changeset
|
32 value = "text-single-value", |
0d97cde1c7b0
mod_adhoc_dataforms_demo: Reorder form fields
Kim Alvefur <zash@zash.se>
parents:
3555
diff
changeset
|
33 }, |
0d97cde1c7b0
mod_adhoc_dataforms_demo: Reorder form fields
Kim Alvefur <zash@zash.se>
parents:
3555
diff
changeset
|
34 { |
0d97cde1c7b0
mod_adhoc_dataforms_demo: Reorder form fields
Kim Alvefur <zash@zash.se>
parents:
3555
diff
changeset
|
35 type = "text-multi", |
0d97cde1c7b0
mod_adhoc_dataforms_demo: Reorder form fields
Kim Alvefur <zash@zash.se>
parents:
3555
diff
changeset
|
36 label = "text-multi-label", |
0d97cde1c7b0
mod_adhoc_dataforms_demo: Reorder form fields
Kim Alvefur <zash@zash.se>
parents:
3555
diff
changeset
|
37 name = "text-multi-field", |
0d97cde1c7b0
mod_adhoc_dataforms_demo: Reorder form fields
Kim Alvefur <zash@zash.se>
parents:
3555
diff
changeset
|
38 value = "text\nmulti\nvalue", |
3211
2969ed764fe8
mod_adhoc_test: A module to test dataforms generation and rendering
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
39 }, |
2969ed764fe8
mod_adhoc_test: A module to test dataforms generation and rendering
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
40 { |
3556
0d97cde1c7b0
mod_adhoc_dataforms_demo: Reorder form fields
Kim Alvefur <zash@zash.se>
parents:
3555
diff
changeset
|
41 type = "text-private", |
0d97cde1c7b0
mod_adhoc_dataforms_demo: Reorder form fields
Kim Alvefur <zash@zash.se>
parents:
3555
diff
changeset
|
42 label = "text-private-label", |
0d97cde1c7b0
mod_adhoc_dataforms_demo: Reorder form fields
Kim Alvefur <zash@zash.se>
parents:
3555
diff
changeset
|
43 name = "text-private-field", |
0d97cde1c7b0
mod_adhoc_dataforms_demo: Reorder form fields
Kim Alvefur <zash@zash.se>
parents:
3555
diff
changeset
|
44 value = "text-private-value", |
0d97cde1c7b0
mod_adhoc_dataforms_demo: Reorder form fields
Kim Alvefur <zash@zash.se>
parents:
3555
diff
changeset
|
45 }, |
0d97cde1c7b0
mod_adhoc_dataforms_demo: Reorder form fields
Kim Alvefur <zash@zash.se>
parents:
3555
diff
changeset
|
46 { |
0d97cde1c7b0
mod_adhoc_dataforms_demo: Reorder form fields
Kim Alvefur <zash@zash.se>
parents:
3555
diff
changeset
|
47 type = "boolean", |
0d97cde1c7b0
mod_adhoc_dataforms_demo: Reorder form fields
Kim Alvefur <zash@zash.se>
parents:
3555
diff
changeset
|
48 label = "boolean-label", |
0d97cde1c7b0
mod_adhoc_dataforms_demo: Reorder form fields
Kim Alvefur <zash@zash.se>
parents:
3555
diff
changeset
|
49 name = "boolean-field", |
0d97cde1c7b0
mod_adhoc_dataforms_demo: Reorder form fields
Kim Alvefur <zash@zash.se>
parents:
3555
diff
changeset
|
50 value = true, |
0d97cde1c7b0
mod_adhoc_dataforms_demo: Reorder form fields
Kim Alvefur <zash@zash.se>
parents:
3555
diff
changeset
|
51 }, |
0d97cde1c7b0
mod_adhoc_dataforms_demo: Reorder form fields
Kim Alvefur <zash@zash.se>
parents:
3555
diff
changeset
|
52 { |
0d97cde1c7b0
mod_adhoc_dataforms_demo: Reorder form fields
Kim Alvefur <zash@zash.se>
parents:
3555
diff
changeset
|
53 type = "fixed", |
0d97cde1c7b0
mod_adhoc_dataforms_demo: Reorder form fields
Kim Alvefur <zash@zash.se>
parents:
3555
diff
changeset
|
54 label = "fixed-label", |
0d97cde1c7b0
mod_adhoc_dataforms_demo: Reorder form fields
Kim Alvefur <zash@zash.se>
parents:
3555
diff
changeset
|
55 name = "fixed-field#2", |
0d97cde1c7b0
mod_adhoc_dataforms_demo: Reorder form fields
Kim Alvefur <zash@zash.se>
parents:
3555
diff
changeset
|
56 value = "fixed-value", |
3211
2969ed764fe8
mod_adhoc_test: A module to test dataforms generation and rendering
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
57 }, |
2969ed764fe8
mod_adhoc_test: A module to test dataforms generation and rendering
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
58 { |
2969ed764fe8
mod_adhoc_test: A module to test dataforms generation and rendering
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
59 type = "list-multi", |
2969ed764fe8
mod_adhoc_test: A module to test dataforms generation and rendering
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
60 label = "list-multi-label", |
2969ed764fe8
mod_adhoc_test: A module to test dataforms generation and rendering
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
61 name = "list-multi-field", |
2969ed764fe8
mod_adhoc_test: A module to test dataforms generation and rendering
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
62 value = { |
2969ed764fe8
mod_adhoc_test: A module to test dataforms generation and rendering
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
63 "list-multi-option-value#1", |
2969ed764fe8
mod_adhoc_test: A module to test dataforms generation and rendering
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
64 "list-multi-option-value#3", |
2969ed764fe8
mod_adhoc_test: A module to test dataforms generation and rendering
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
65 }, |
2969ed764fe8
mod_adhoc_test: A module to test dataforms generation and rendering
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
66 options = { |
2969ed764fe8
mod_adhoc_test: A module to test dataforms generation and rendering
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
67 { |
2969ed764fe8
mod_adhoc_test: A module to test dataforms generation and rendering
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
68 label = "list-multi-option-label#1", |
2969ed764fe8
mod_adhoc_test: A module to test dataforms generation and rendering
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
69 value = "list-multi-option-value#1", |
2969ed764fe8
mod_adhoc_test: A module to test dataforms generation and rendering
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
70 default = true, |
2969ed764fe8
mod_adhoc_test: A module to test dataforms generation and rendering
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
71 }, |
2969ed764fe8
mod_adhoc_test: A module to test dataforms generation and rendering
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
72 { |
2969ed764fe8
mod_adhoc_test: A module to test dataforms generation and rendering
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
73 label = "list-multi-option-label#2", |
2969ed764fe8
mod_adhoc_test: A module to test dataforms generation and rendering
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
74 value = "list-multi-option-value#2", |
2969ed764fe8
mod_adhoc_test: A module to test dataforms generation and rendering
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
75 default = false, |
2969ed764fe8
mod_adhoc_test: A module to test dataforms generation and rendering
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
76 }, |
2969ed764fe8
mod_adhoc_test: A module to test dataforms generation and rendering
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
77 { |
2969ed764fe8
mod_adhoc_test: A module to test dataforms generation and rendering
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
78 label = "list-multi-option-label#3", |
2969ed764fe8
mod_adhoc_test: A module to test dataforms generation and rendering
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
79 value = "list-multi-option-value#3", |
2969ed764fe8
mod_adhoc_test: A module to test dataforms generation and rendering
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
80 default = true, |
2969ed764fe8
mod_adhoc_test: A module to test dataforms generation and rendering
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
81 }, |
2969ed764fe8
mod_adhoc_test: A module to test dataforms generation and rendering
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
82 } |
2969ed764fe8
mod_adhoc_test: A module to test dataforms generation and rendering
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
83 }, |
2969ed764fe8
mod_adhoc_test: A module to test dataforms generation and rendering
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
84 { |
3556
0d97cde1c7b0
mod_adhoc_dataforms_demo: Reorder form fields
Kim Alvefur <zash@zash.se>
parents:
3555
diff
changeset
|
85 type = "jid-single", |
0d97cde1c7b0
mod_adhoc_dataforms_demo: Reorder form fields
Kim Alvefur <zash@zash.se>
parents:
3555
diff
changeset
|
86 label = "jid-single-label", |
0d97cde1c7b0
mod_adhoc_dataforms_demo: Reorder form fields
Kim Alvefur <zash@zash.se>
parents:
3555
diff
changeset
|
87 name = "jid-single-field", |
0d97cde1c7b0
mod_adhoc_dataforms_demo: Reorder form fields
Kim Alvefur <zash@zash.se>
parents:
3555
diff
changeset
|
88 value = "jid@single/value", |
0d97cde1c7b0
mod_adhoc_dataforms_demo: Reorder form fields
Kim Alvefur <zash@zash.se>
parents:
3555
diff
changeset
|
89 }, |
0d97cde1c7b0
mod_adhoc_dataforms_demo: Reorder form fields
Kim Alvefur <zash@zash.se>
parents:
3555
diff
changeset
|
90 { |
0d97cde1c7b0
mod_adhoc_dataforms_demo: Reorder form fields
Kim Alvefur <zash@zash.se>
parents:
3555
diff
changeset
|
91 type = "jid-multi", |
0d97cde1c7b0
mod_adhoc_dataforms_demo: Reorder form fields
Kim Alvefur <zash@zash.se>
parents:
3555
diff
changeset
|
92 label = "jid-multi-label", |
0d97cde1c7b0
mod_adhoc_dataforms_demo: Reorder form fields
Kim Alvefur <zash@zash.se>
parents:
3555
diff
changeset
|
93 name = "jid-multi-field", |
0d97cde1c7b0
mod_adhoc_dataforms_demo: Reorder form fields
Kim Alvefur <zash@zash.se>
parents:
3555
diff
changeset
|
94 value = { |
0d97cde1c7b0
mod_adhoc_dataforms_demo: Reorder form fields
Kim Alvefur <zash@zash.se>
parents:
3555
diff
changeset
|
95 "jid@multi/value#1", |
0d97cde1c7b0
mod_adhoc_dataforms_demo: Reorder form fields
Kim Alvefur <zash@zash.se>
parents:
3555
diff
changeset
|
96 "jid@multi/value#2", |
0d97cde1c7b0
mod_adhoc_dataforms_demo: Reorder form fields
Kim Alvefur <zash@zash.se>
parents:
3555
diff
changeset
|
97 }, |
0d97cde1c7b0
mod_adhoc_dataforms_demo: Reorder form fields
Kim Alvefur <zash@zash.se>
parents:
3555
diff
changeset
|
98 }, |
0d97cde1c7b0
mod_adhoc_dataforms_demo: Reorder form fields
Kim Alvefur <zash@zash.se>
parents:
3555
diff
changeset
|
99 { |
3211
2969ed764fe8
mod_adhoc_test: A module to test dataforms generation and rendering
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
100 type = "list-single", |
2969ed764fe8
mod_adhoc_test: A module to test dataforms generation and rendering
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
101 label = "list-single-label", |
2969ed764fe8
mod_adhoc_test: A module to test dataforms generation and rendering
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
102 name = "list-single-field", |
2969ed764fe8
mod_adhoc_test: A module to test dataforms generation and rendering
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
103 value = "list-single-value", |
2969ed764fe8
mod_adhoc_test: A module to test dataforms generation and rendering
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
104 options = { |
2969ed764fe8
mod_adhoc_test: A module to test dataforms generation and rendering
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
105 "list-single-value", |
2969ed764fe8
mod_adhoc_test: A module to test dataforms generation and rendering
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
106 "list-single-value#2", |
2969ed764fe8
mod_adhoc_test: A module to test dataforms generation and rendering
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
107 "list-single-value#3", |
2969ed764fe8
mod_adhoc_test: A module to test dataforms generation and rendering
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
108 } |
2969ed764fe8
mod_adhoc_test: A module to test dataforms generation and rendering
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
109 }, |
2969ed764fe8
mod_adhoc_test: A module to test dataforms generation and rendering
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
110 }) |
2969ed764fe8
mod_adhoc_test: A module to test dataforms generation and rendering
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
111 |
3213
85c8a8c33028
mod_adhoc_dataforms_demo: Silence warning about unused argument [luacheck]
Kim Alvefur <zash@zash.se>
parents:
3212
diff
changeset
|
112 local function handler(fields, err, data) -- luacheck: ignore 212/data |
3211
2969ed764fe8
mod_adhoc_test: A module to test dataforms generation and rendering
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
113 return { |
2969ed764fe8
mod_adhoc_test: A module to test dataforms generation and rendering
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
114 status = "completed", |
2969ed764fe8
mod_adhoc_test: A module to test dataforms generation and rendering
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
115 info = "Data was:\n" |
2969ed764fe8
mod_adhoc_test: A module to test dataforms generation and rendering
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
116 .. serialization.serialize(err or fields), |
2969ed764fe8
mod_adhoc_test: A module to test dataforms generation and rendering
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
117 }; |
2969ed764fe8
mod_adhoc_test: A module to test dataforms generation and rendering
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
118 end |
2969ed764fe8
mod_adhoc_test: A module to test dataforms generation and rendering
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
119 |
2969ed764fe8
mod_adhoc_test: A module to test dataforms generation and rendering
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
120 module:provides("adhoc", |
2969ed764fe8
mod_adhoc_test: A module to test dataforms generation and rendering
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
121 adhoc_new("Dataforms Demo", |
2969ed764fe8
mod_adhoc_test: A module to test dataforms generation and rendering
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
122 "xmpp:zash.se/mod_adhoc_test", |
2969ed764fe8
mod_adhoc_test: A module to test dataforms generation and rendering
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
123 adhoc_util.new_simple_form(form, handler))); |