Mercurial > prosody-modules
annotate mod_adhoc_dataforms_demo/mod_adhoc_dataforms_demo.lua @ 3895:25a3ad36ef3e
mod_rest: Rename loop variable for improved clarity
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Sat, 22 Feb 2020 13:51:59 +0100 |
parents | 22587eb2d87c |
children | f5caacd475c4 |
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", |
3557
54b4b020de4c
mod_adhoc_dataforms_demo: Rename command node to reflect current module name
Kim Alvefur <zash@zash.se>
parents:
3556
diff
changeset
|
122 "xmpp:zash.se/mod_adhoc_dataforms_demo#form", |
3211
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))); |
3558
22587eb2d87c
mod_adhoc_dataforms_demo: Add a multi-step command demo
Kim Alvefur <zash@zash.se>
parents:
3557
diff
changeset
|
124 |
22587eb2d87c
mod_adhoc_dataforms_demo: Add a multi-step command demo
Kim Alvefur <zash@zash.se>
parents:
3557
diff
changeset
|
125 |
22587eb2d87c
mod_adhoc_dataforms_demo: Add a multi-step command demo
Kim Alvefur <zash@zash.se>
parents:
3557
diff
changeset
|
126 local function multi_step_command(_, data, state) |
22587eb2d87c
mod_adhoc_dataforms_demo: Add a multi-step command demo
Kim Alvefur <zash@zash.se>
parents:
3557
diff
changeset
|
127 |
22587eb2d87c
mod_adhoc_dataforms_demo: Add a multi-step command demo
Kim Alvefur <zash@zash.se>
parents:
3557
diff
changeset
|
128 if data.action == "cancel" then |
22587eb2d87c
mod_adhoc_dataforms_demo: Add a multi-step command demo
Kim Alvefur <zash@zash.se>
parents:
3557
diff
changeset
|
129 return { status = "canceled" }; |
22587eb2d87c
mod_adhoc_dataforms_demo: Add a multi-step command demo
Kim Alvefur <zash@zash.se>
parents:
3557
diff
changeset
|
130 elseif data.action == "complete" then |
22587eb2d87c
mod_adhoc_dataforms_demo: Add a multi-step command demo
Kim Alvefur <zash@zash.se>
parents:
3557
diff
changeset
|
131 return { |
22587eb2d87c
mod_adhoc_dataforms_demo: Add a multi-step command demo
Kim Alvefur <zash@zash.se>
parents:
3557
diff
changeset
|
132 status = "completed", |
22587eb2d87c
mod_adhoc_dataforms_demo: Add a multi-step command demo
Kim Alvefur <zash@zash.se>
parents:
3557
diff
changeset
|
133 info = "State was:\n" |
22587eb2d87c
mod_adhoc_dataforms_demo: Add a multi-step command demo
Kim Alvefur <zash@zash.se>
parents:
3557
diff
changeset
|
134 .. serialization.serialize(state, { fatal = false }), |
22587eb2d87c
mod_adhoc_dataforms_demo: Add a multi-step command demo
Kim Alvefur <zash@zash.se>
parents:
3557
diff
changeset
|
135 }; |
22587eb2d87c
mod_adhoc_dataforms_demo: Add a multi-step command demo
Kim Alvefur <zash@zash.se>
parents:
3557
diff
changeset
|
136 end |
22587eb2d87c
mod_adhoc_dataforms_demo: Add a multi-step command demo
Kim Alvefur <zash@zash.se>
parents:
3557
diff
changeset
|
137 state = state or { step = 1, forms = { } }; |
22587eb2d87c
mod_adhoc_dataforms_demo: Add a multi-step command demo
Kim Alvefur <zash@zash.se>
parents:
3557
diff
changeset
|
138 |
22587eb2d87c
mod_adhoc_dataforms_demo: Add a multi-step command demo
Kim Alvefur <zash@zash.se>
parents:
3557
diff
changeset
|
139 if data.action == "next" then |
22587eb2d87c
mod_adhoc_dataforms_demo: Add a multi-step command demo
Kim Alvefur <zash@zash.se>
parents:
3557
diff
changeset
|
140 state.step = state.step + 1; |
22587eb2d87c
mod_adhoc_dataforms_demo: Add a multi-step command demo
Kim Alvefur <zash@zash.se>
parents:
3557
diff
changeset
|
141 elseif data.action == "prev" then |
22587eb2d87c
mod_adhoc_dataforms_demo: Add a multi-step command demo
Kim Alvefur <zash@zash.se>
parents:
3557
diff
changeset
|
142 state.step = math.max(state.step - 1, 1); |
22587eb2d87c
mod_adhoc_dataforms_demo: Add a multi-step command demo
Kim Alvefur <zash@zash.se>
parents:
3557
diff
changeset
|
143 end |
22587eb2d87c
mod_adhoc_dataforms_demo: Add a multi-step command demo
Kim Alvefur <zash@zash.se>
parents:
3557
diff
changeset
|
144 |
22587eb2d87c
mod_adhoc_dataforms_demo: Add a multi-step command demo
Kim Alvefur <zash@zash.se>
parents:
3557
diff
changeset
|
145 local current_form = state.forms[state.step] |
22587eb2d87c
mod_adhoc_dataforms_demo: Add a multi-step command demo
Kim Alvefur <zash@zash.se>
parents:
3557
diff
changeset
|
146 if not current_form then |
22587eb2d87c
mod_adhoc_dataforms_demo: Add a multi-step command demo
Kim Alvefur <zash@zash.se>
parents:
3557
diff
changeset
|
147 current_form = { |
22587eb2d87c
mod_adhoc_dataforms_demo: Add a multi-step command demo
Kim Alvefur <zash@zash.se>
parents:
3557
diff
changeset
|
148 title = string.format("Step %d", state.step); |
22587eb2d87c
mod_adhoc_dataforms_demo: Add a multi-step command demo
Kim Alvefur <zash@zash.se>
parents:
3557
diff
changeset
|
149 instructions = state.step == 1 and "Here's a form." or "Here's another form."; |
22587eb2d87c
mod_adhoc_dataforms_demo: Add a multi-step command demo
Kim Alvefur <zash@zash.se>
parents:
3557
diff
changeset
|
150 }; |
22587eb2d87c
mod_adhoc_dataforms_demo: Add a multi-step command demo
Kim Alvefur <zash@zash.se>
parents:
3557
diff
changeset
|
151 local already_selected = {}; |
22587eb2d87c
mod_adhoc_dataforms_demo: Add a multi-step command demo
Kim Alvefur <zash@zash.se>
parents:
3557
diff
changeset
|
152 for _ = 1, math.random(1, 5) do |
22587eb2d87c
mod_adhoc_dataforms_demo: Add a multi-step command demo
Kim Alvefur <zash@zash.se>
parents:
3557
diff
changeset
|
153 local random |
22587eb2d87c
mod_adhoc_dataforms_demo: Add a multi-step command demo
Kim Alvefur <zash@zash.se>
parents:
3557
diff
changeset
|
154 repeat |
22587eb2d87c
mod_adhoc_dataforms_demo: Add a multi-step command demo
Kim Alvefur <zash@zash.se>
parents:
3557
diff
changeset
|
155 random = math.random(2, #form); |
22587eb2d87c
mod_adhoc_dataforms_demo: Add a multi-step command demo
Kim Alvefur <zash@zash.se>
parents:
3557
diff
changeset
|
156 until not already_selected[random] |
22587eb2d87c
mod_adhoc_dataforms_demo: Add a multi-step command demo
Kim Alvefur <zash@zash.se>
parents:
3557
diff
changeset
|
157 table.insert(current_form, form[random]); |
22587eb2d87c
mod_adhoc_dataforms_demo: Add a multi-step command demo
Kim Alvefur <zash@zash.se>
parents:
3557
diff
changeset
|
158 end |
22587eb2d87c
mod_adhoc_dataforms_demo: Add a multi-step command demo
Kim Alvefur <zash@zash.se>
parents:
3557
diff
changeset
|
159 state.forms[state.step] = dataforms.new(current_form); |
22587eb2d87c
mod_adhoc_dataforms_demo: Add a multi-step command demo
Kim Alvefur <zash@zash.se>
parents:
3557
diff
changeset
|
160 end |
22587eb2d87c
mod_adhoc_dataforms_demo: Add a multi-step command demo
Kim Alvefur <zash@zash.se>
parents:
3557
diff
changeset
|
161 |
22587eb2d87c
mod_adhoc_dataforms_demo: Add a multi-step command demo
Kim Alvefur <zash@zash.se>
parents:
3557
diff
changeset
|
162 local next_step = { |
22587eb2d87c
mod_adhoc_dataforms_demo: Add a multi-step command demo
Kim Alvefur <zash@zash.se>
parents:
3557
diff
changeset
|
163 status = "executing", |
22587eb2d87c
mod_adhoc_dataforms_demo: Add a multi-step command demo
Kim Alvefur <zash@zash.se>
parents:
3557
diff
changeset
|
164 form = current_form, |
22587eb2d87c
mod_adhoc_dataforms_demo: Add a multi-step command demo
Kim Alvefur <zash@zash.se>
parents:
3557
diff
changeset
|
165 actions = { |
22587eb2d87c
mod_adhoc_dataforms_demo: Add a multi-step command demo
Kim Alvefur <zash@zash.se>
parents:
3557
diff
changeset
|
166 "next", "complete" |
22587eb2d87c
mod_adhoc_dataforms_demo: Add a multi-step command demo
Kim Alvefur <zash@zash.se>
parents:
3557
diff
changeset
|
167 }, |
22587eb2d87c
mod_adhoc_dataforms_demo: Add a multi-step command demo
Kim Alvefur <zash@zash.se>
parents:
3557
diff
changeset
|
168 }; |
22587eb2d87c
mod_adhoc_dataforms_demo: Add a multi-step command demo
Kim Alvefur <zash@zash.se>
parents:
3557
diff
changeset
|
169 if state.step > 1 then |
22587eb2d87c
mod_adhoc_dataforms_demo: Add a multi-step command demo
Kim Alvefur <zash@zash.se>
parents:
3557
diff
changeset
|
170 table.insert(next_step.actions, 1, "prev"); |
22587eb2d87c
mod_adhoc_dataforms_demo: Add a multi-step command demo
Kim Alvefur <zash@zash.se>
parents:
3557
diff
changeset
|
171 end |
22587eb2d87c
mod_adhoc_dataforms_demo: Add a multi-step command demo
Kim Alvefur <zash@zash.se>
parents:
3557
diff
changeset
|
172 return next_step, state; |
22587eb2d87c
mod_adhoc_dataforms_demo: Add a multi-step command demo
Kim Alvefur <zash@zash.se>
parents:
3557
diff
changeset
|
173 end |
22587eb2d87c
mod_adhoc_dataforms_demo: Add a multi-step command demo
Kim Alvefur <zash@zash.se>
parents:
3557
diff
changeset
|
174 |
22587eb2d87c
mod_adhoc_dataforms_demo: Add a multi-step command demo
Kim Alvefur <zash@zash.se>
parents:
3557
diff
changeset
|
175 module:provides("adhoc", |
22587eb2d87c
mod_adhoc_dataforms_demo: Add a multi-step command demo
Kim Alvefur <zash@zash.se>
parents:
3557
diff
changeset
|
176 adhoc_new("Multi-step command demo", |
22587eb2d87c
mod_adhoc_dataforms_demo: Add a multi-step command demo
Kim Alvefur <zash@zash.se>
parents:
3557
diff
changeset
|
177 "xmpp:zash.se/mod_adhoc_dataforms_demo#multi", |
22587eb2d87c
mod_adhoc_dataforms_demo: Add a multi-step command demo
Kim Alvefur <zash@zash.se>
parents:
3557
diff
changeset
|
178 multi_step_command)); |
22587eb2d87c
mod_adhoc_dataforms_demo: Add a multi-step command demo
Kim Alvefur <zash@zash.se>
parents:
3557
diff
changeset
|
179 |