File

util/adhoc.lua @ 10655:ee6c12264420 0.11

mod_storage_sql: Move update limit check back one step, fixes traceback 0c00274528a4 moved it one step too far, so the check was performed before connecting to the database instead of after.
author Kim Alvefur <zash@zash.se>
date Sat, 22 Feb 2020 16:23:43 +0100
parent 8382:e5d00bf4a4d5
child 10667:49312378ba1d
line wrap: on
line source

-- luacheck: ignore 212/self

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(data) } }, "executing";
		end
	end
end

return { new_simple_form = new_simple_form,
	 new_initial_data_form = new_initial_data_form };