Mercurial > prosody-modules
annotate mod_adhoc_dataforms_demo/mod_adhoc_dataforms_demo.lua @ 5405:c7a5caad28ef
mod_http_oauth2: Enforce response type encoded in client_id
The client promises to only use this response type, so we should hold
them to that.
This makes it fail earlier if the response type is disabled or the
client is trying to use one that it promised not to use. Better than
failing after login and consent.
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Tue, 02 May 2023 16:31:25 +0200 |
parents | 3e2e708fd18b |
children |
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", |
3914
f5caacd475c4
mod_adhoc_dataforms_demo: Add the now required permission mode (#1482)
Kim Alvefur <zash@zash.se>
parents:
3558
diff
changeset
|
123 adhoc_util.new_simple_form(form, handler), "any")); |
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 |
4050
1eb2b9483081
mod_adhoc_dataforms_demo: Treat 'execute' action as 'next' except in first step
Kim Alvefur <zash@zash.se>
parents:
4049
diff
changeset
|
137 if state and data.action == "execute" then |
1eb2b9483081
mod_adhoc_dataforms_demo: Treat 'execute' action as 'next' except in first step
Kim Alvefur <zash@zash.se>
parents:
4049
diff
changeset
|
138 data.action = "next"; |
1eb2b9483081
mod_adhoc_dataforms_demo: Treat 'execute' action as 'next' except in first step
Kim Alvefur <zash@zash.se>
parents:
4049
diff
changeset
|
139 elseif not state and data.action == "next" then |
1eb2b9483081
mod_adhoc_dataforms_demo: Treat 'execute' action as 'next' except in first step
Kim Alvefur <zash@zash.se>
parents:
4049
diff
changeset
|
140 -- Prevent jumping directly to step 2 |
1eb2b9483081
mod_adhoc_dataforms_demo: Treat 'execute' action as 'next' except in first step
Kim Alvefur <zash@zash.se>
parents:
4049
diff
changeset
|
141 return { status = "canceled", error = "Invalid action" }; |
1eb2b9483081
mod_adhoc_dataforms_demo: Treat 'execute' action as 'next' except in first step
Kim Alvefur <zash@zash.se>
parents:
4049
diff
changeset
|
142 end |
3558
22587eb2d87c
mod_adhoc_dataforms_demo: Add a multi-step command demo
Kim Alvefur <zash@zash.se>
parents:
3557
diff
changeset
|
143 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
|
144 |
22587eb2d87c
mod_adhoc_dataforms_demo: Add a multi-step command demo
Kim Alvefur <zash@zash.se>
parents:
3557
diff
changeset
|
145 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
|
146 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
|
147 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
|
148 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
|
149 end |
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 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
|
152 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
|
153 current_form = { |
22587eb2d87c
mod_adhoc_dataforms_demo: Add a multi-step command demo
Kim Alvefur <zash@zash.se>
parents:
3557
diff
changeset
|
154 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
|
155 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
|
156 }; |
22587eb2d87c
mod_adhoc_dataforms_demo: Add a multi-step command demo
Kim Alvefur <zash@zash.se>
parents:
3557
diff
changeset
|
157 local already_selected = {}; |
22587eb2d87c
mod_adhoc_dataforms_demo: Add a multi-step command demo
Kim Alvefur <zash@zash.se>
parents:
3557
diff
changeset
|
158 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
|
159 local random |
22587eb2d87c
mod_adhoc_dataforms_demo: Add a multi-step command demo
Kim Alvefur <zash@zash.se>
parents:
3557
diff
changeset
|
160 repeat |
22587eb2d87c
mod_adhoc_dataforms_demo: Add a multi-step command demo
Kim Alvefur <zash@zash.se>
parents:
3557
diff
changeset
|
161 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
|
162 until not already_selected[random] |
4049
78f1de5301fc
mod_adhoc_dataforms_demo: Fix duplicate field prevention
Kim Alvefur <zash@zash.se>
parents:
4045
diff
changeset
|
163 already_selected[random] = true; |
3558
22587eb2d87c
mod_adhoc_dataforms_demo: Add a multi-step command demo
Kim Alvefur <zash@zash.se>
parents:
3557
diff
changeset
|
164 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
|
165 end |
22587eb2d87c
mod_adhoc_dataforms_demo: Add a multi-step command demo
Kim Alvefur <zash@zash.se>
parents:
3557
diff
changeset
|
166 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
|
167 end |
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 local next_step = { |
22587eb2d87c
mod_adhoc_dataforms_demo: Add a multi-step command demo
Kim Alvefur <zash@zash.se>
parents:
3557
diff
changeset
|
170 status = "executing", |
22587eb2d87c
mod_adhoc_dataforms_demo: Add a multi-step command demo
Kim Alvefur <zash@zash.se>
parents:
3557
diff
changeset
|
171 form = current_form, |
4050
1eb2b9483081
mod_adhoc_dataforms_demo: Treat 'execute' action as 'next' except in first step
Kim Alvefur <zash@zash.se>
parents:
4049
diff
changeset
|
172 default = "next", |
3558
22587eb2d87c
mod_adhoc_dataforms_demo: Add a multi-step command demo
Kim Alvefur <zash@zash.se>
parents:
3557
diff
changeset
|
173 actions = { |
22587eb2d87c
mod_adhoc_dataforms_demo: Add a multi-step command demo
Kim Alvefur <zash@zash.se>
parents:
3557
diff
changeset
|
174 "next", "complete" |
22587eb2d87c
mod_adhoc_dataforms_demo: Add a multi-step command demo
Kim Alvefur <zash@zash.se>
parents:
3557
diff
changeset
|
175 }, |
22587eb2d87c
mod_adhoc_dataforms_demo: Add a multi-step command demo
Kim Alvefur <zash@zash.se>
parents:
3557
diff
changeset
|
176 }; |
22587eb2d87c
mod_adhoc_dataforms_demo: Add a multi-step command demo
Kim Alvefur <zash@zash.se>
parents:
3557
diff
changeset
|
177 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
|
178 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
|
179 end |
22587eb2d87c
mod_adhoc_dataforms_demo: Add a multi-step command demo
Kim Alvefur <zash@zash.se>
parents:
3557
diff
changeset
|
180 return next_step, state; |
22587eb2d87c
mod_adhoc_dataforms_demo: Add a multi-step command demo
Kim Alvefur <zash@zash.se>
parents:
3557
diff
changeset
|
181 end |
22587eb2d87c
mod_adhoc_dataforms_demo: Add a multi-step command demo
Kim Alvefur <zash@zash.se>
parents:
3557
diff
changeset
|
182 |
4581
3e2e708fd18b
mod_adhoc_dataforms_demo: Add compat with 0.11 (vs trunk api change)
Kim Alvefur <zash@zash.se>
parents:
4050
diff
changeset
|
183 local permission = "any"; |
3e2e708fd18b
mod_adhoc_dataforms_demo: Add compat with 0.11 (vs trunk api change)
Kim Alvefur <zash@zash.se>
parents:
4050
diff
changeset
|
184 if not module.send_iq then -- hacky attempt at detecting 0.11 or earlier |
3e2e708fd18b
mod_adhoc_dataforms_demo: Add compat with 0.11 (vs trunk api change)
Kim Alvefur <zash@zash.se>
parents:
4050
diff
changeset
|
185 permission = "user"; |
3e2e708fd18b
mod_adhoc_dataforms_demo: Add compat with 0.11 (vs trunk api change)
Kim Alvefur <zash@zash.se>
parents:
4050
diff
changeset
|
186 end |
3e2e708fd18b
mod_adhoc_dataforms_demo: Add compat with 0.11 (vs trunk api change)
Kim Alvefur <zash@zash.se>
parents:
4050
diff
changeset
|
187 |
4045
4fc6cf528a9a
mod_adhoc_dataforms_demo: Ensure mod_adhoc is loaded
Kim Alvefur <zash@zash.se>
parents:
3914
diff
changeset
|
188 module:depends("adhoc"); |
3558
22587eb2d87c
mod_adhoc_dataforms_demo: Add a multi-step command demo
Kim Alvefur <zash@zash.se>
parents:
3557
diff
changeset
|
189 module:provides("adhoc", |
22587eb2d87c
mod_adhoc_dataforms_demo: Add a multi-step command demo
Kim Alvefur <zash@zash.se>
parents:
3557
diff
changeset
|
190 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
|
191 "xmpp:zash.se/mod_adhoc_dataforms_demo#multi", |
4581
3e2e708fd18b
mod_adhoc_dataforms_demo: Add compat with 0.11 (vs trunk api change)
Kim Alvefur <zash@zash.se>
parents:
4050
diff
changeset
|
192 multi_step_command, permission)); |
3558
22587eb2d87c
mod_adhoc_dataforms_demo: Add a multi-step command demo
Kim Alvefur <zash@zash.se>
parents:
3557
diff
changeset
|
193 |