aboutsummaryrefslogtreecommitdiffstats
path: root/util
diff options
context:
space:
mode:
authorMatthew Wild <mwild1@gmail.com>2013-04-23 15:38:38 +0100
committerMatthew Wild <mwild1@gmail.com>2013-04-23 15:38:38 +0100
commita54b454be17169b6d377a602d284e654c3e3c6be (patch)
tree6c5314d0829139cb9ef4d305679085eb744b1577 /util
parentbac9625f119e516dd5ce7a9a503dd40cba751216 (diff)
parente41bbc20cddbce8bc9b147a1f8b822c165e10f96 (diff)
downloadprosody-a54b454be17169b6d377a602d284e654c3e3c6be.tar.gz
prosody-a54b454be17169b6d377a602d284e654c3e3c6be.zip
Merge 0.9->trunk
Diffstat (limited to 'util')
-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 };