mirror of
https://github.com/bjc/prosody.git
synced 2025-04-03 21:27:38 +03:00
util.adhoc: New util for generating common adhoc handler patterns
This commit is contained in:
parent
3b59eb2735
commit
9ed5894b79
1 changed files with 31 additions and 0 deletions
31
util/adhoc.lua
Normal file
31
util/adhoc.lua
Normal 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 };
|
Loading…
Add table
Add a link
Reference in a new issue