Software /
code /
prosody
Comparison
util/adhoc.lua @ 5513:755f705f126a
util.adhoc: New util for generating common adhoc handler patterns
author | Florian Zeitz <florob@babelmonkeys.de> |
---|---|
date | Tue, 23 Apr 2013 14:49:31 +0200 |
child | 7912:2c204ba8e52e |
comparison
equal
deleted
inserted
replaced
5510:3758898cefdd | 5513:755f705f126a |
---|---|
1 local function new_simple_form(form, result_handler) | |
2 return function(self, data, state) | |
3 if state then | |
4 if data.action == "cancel" then | |
5 return { status = "canceled" }; | |
6 end | |
7 local fields, err = form:data(data.form); | |
8 return result_handler(fields, err, data); | |
9 else | |
10 return { status = "executing", actions = {"next", "complete", default = "complete"}, form = form }, "executing"; | |
11 end | |
12 end | |
13 end | |
14 | |
15 local function new_initial_data_form(form, initial_data, result_handler) | |
16 return function(self, data, state) | |
17 if state then | |
18 if data.action == "cancel" then | |
19 return { status = "canceled" }; | |
20 end | |
21 local fields, err = form:data(data.form); | |
22 return result_handler(fields, err, data); | |
23 else | |
24 return { status = "executing", actions = {"next", "complete", default = "complete"}, | |
25 form = { layout = form, values = initial_data() } }, "executing"; | |
26 end | |
27 end | |
28 end | |
29 | |
30 return { new_simple_form = new_simple_form, | |
31 new_initial_data_form = new_initial_data_form }; |