aboutsummaryrefslogtreecommitdiffstats
path: root/util/adhoc.lua
blob: 671e85cf8efe9103f3fe708125a81dec79573bf2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
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 };