Software /
code /
prosody
Annotate
util/adhoc.lua @ 8705:1d66f66a13c9
MUC: Don't reply to errors with more errors (fixes #1122)
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Wed, 28 Mar 2018 18:11:09 +0200 |
parent | 7912:2c204ba8e52e |
child | 8382:e5d00bf4a4d5 |
rev | line source |
---|---|
5513
755f705f126a
util.adhoc: New util for generating common adhoc handler patterns
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
1 local function new_simple_form(form, result_handler) |
755f705f126a
util.adhoc: New util for generating common adhoc handler patterns
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
2 return function(self, data, state) |
755f705f126a
util.adhoc: New util for generating common adhoc handler patterns
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
3 if state then |
755f705f126a
util.adhoc: New util for generating common adhoc handler patterns
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
4 if data.action == "cancel" then |
755f705f126a
util.adhoc: New util for generating common adhoc handler patterns
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
5 return { status = "canceled" }; |
755f705f126a
util.adhoc: New util for generating common adhoc handler patterns
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
6 end |
755f705f126a
util.adhoc: New util for generating common adhoc handler patterns
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
7 local fields, err = form:data(data.form); |
755f705f126a
util.adhoc: New util for generating common adhoc handler patterns
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
8 return result_handler(fields, err, data); |
755f705f126a
util.adhoc: New util for generating common adhoc handler patterns
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
9 else |
755f705f126a
util.adhoc: New util for generating common adhoc handler patterns
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
10 return { status = "executing", actions = {"next", "complete", default = "complete"}, form = form }, "executing"; |
755f705f126a
util.adhoc: New util for generating common adhoc handler patterns
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
11 end |
755f705f126a
util.adhoc: New util for generating common adhoc handler patterns
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
12 end |
755f705f126a
util.adhoc: New util for generating common adhoc handler patterns
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
13 end |
755f705f126a
util.adhoc: New util for generating common adhoc handler patterns
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
14 |
755f705f126a
util.adhoc: New util for generating common adhoc handler patterns
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
15 local function new_initial_data_form(form, initial_data, result_handler) |
755f705f126a
util.adhoc: New util for generating common adhoc handler patterns
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
16 return function(self, data, state) |
755f705f126a
util.adhoc: New util for generating common adhoc handler patterns
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
17 if state then |
755f705f126a
util.adhoc: New util for generating common adhoc handler patterns
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
18 if data.action == "cancel" then |
755f705f126a
util.adhoc: New util for generating common adhoc handler patterns
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
19 return { status = "canceled" }; |
755f705f126a
util.adhoc: New util for generating common adhoc handler patterns
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
20 end |
755f705f126a
util.adhoc: New util for generating common adhoc handler patterns
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
21 local fields, err = form:data(data.form); |
755f705f126a
util.adhoc: New util for generating common adhoc handler patterns
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
22 return result_handler(fields, err, data); |
755f705f126a
util.adhoc: New util for generating common adhoc handler patterns
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
23 else |
755f705f126a
util.adhoc: New util for generating common adhoc handler patterns
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
24 return { status = "executing", actions = {"next", "complete", default = "complete"}, |
7912
2c204ba8e52e
util.adhoc: Pass command data to initial_data callback in order to allow loading per-user settings
Kim Alvefur <zash@zash.se>
parents:
5513
diff
changeset
|
25 form = { layout = form, values = initial_data(data) } }, "executing"; |
5513
755f705f126a
util.adhoc: New util for generating common adhoc handler patterns
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
26 end |
755f705f126a
util.adhoc: New util for generating common adhoc handler patterns
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
27 end |
755f705f126a
util.adhoc: New util for generating common adhoc handler patterns
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
28 end |
755f705f126a
util.adhoc: New util for generating common adhoc handler patterns
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
29 |
755f705f126a
util.adhoc: New util for generating common adhoc handler patterns
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
30 return { new_simple_form = new_simple_form, |
755f705f126a
util.adhoc: New util for generating common adhoc handler patterns
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
31 new_initial_data_form = new_initial_data_form }; |