Software /
code /
prosody
Annotate
util/adhoc.lua @ 7245:210d8329dc70
Merge trunk->0.10
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Sun, 06 Mar 2016 18:52:22 +0100 |
parent | 5513:755f705f126a |
child | 7912:2c204ba8e52e |
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"}, |
755f705f126a
util.adhoc: New util for generating common adhoc handler patterns
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff
changeset
|
25 form = { layout = form, values = initial_data() } }, "executing"; |
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 }; |