aboutsummaryrefslogtreecommitdiffstats
path: root/util/adhoc.lua
diff options
context:
space:
mode:
authorFlorian Zeitz <florob@babelmonkeys.de>2013-04-23 14:49:31 +0200
committerFlorian Zeitz <florob@babelmonkeys.de>2013-04-23 14:49:31 +0200
commita5dff746baa6785f0c01957ad7c2bbf83ad84621 (patch)
tree28087884399c27191ac8d1213c28ab4fe5870947 /util/adhoc.lua
parent82e3c118ef92c11e5346d4a8b4d02025fc2569c1 (diff)
downloadprosody-a5dff746baa6785f0c01957ad7c2bbf83ad84621.tar.gz
prosody-a5dff746baa6785f0c01957ad7c2bbf83ad84621.zip
util.adhoc: New util for generating common adhoc handler patterns
Diffstat (limited to 'util/adhoc.lua')
-rw-r--r--util/adhoc.lua31
1 files changed, 31 insertions, 0 deletions
diff --git a/util/adhoc.lua b/util/adhoc.lua
new file mode 100644
index 00000000..671e85cf
--- /dev/null
+++ b/util/adhoc.lua
@@ -0,0 +1,31 @@
+local function new_simple_form(form, result_handler)
+ return function(self, data, state)
+ if state then
+ if data.action == "cancel" then
+ return { status = "canceled" };
+ end
+ local fields, err = form:data(data.form);
+ return result_handler(fields, err, data);
+ else
+ return { status = "executing", actions = {"next", "complete", default = "complete"}, form = form }, "executing";
+ end
+ end
+end
+
+local function new_initial_data_form(form, initial_data, result_handler)
+ return function(self, data, state)
+ if state then
+ if data.action == "cancel" then
+ return { status = "canceled" };
+ end
+ local fields, err = form:data(data.form);
+ return result_handler(fields, err, data);
+ else
+ return { status = "executing", actions = {"next", "complete", default = "complete"},
+ form = { layout = form, values = initial_data() } }, "executing";
+ end
+ end
+end
+
+return { new_simple_form = new_simple_form,
+ new_initial_data_form = new_initial_data_form };