util.adhoc: New util for generating common adhoc handler patterns

This commit is contained in:
Florian Zeitz 2013-04-23 14:49:31 +02:00
parent 3b59eb2735
commit 9ed5894b79

31
util/adhoc.lua Normal file
View file

@ -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 };