summaryrefslogtreecommitdiffstats
path: root/app/acf_cli-controller.lua
blob: ebc2f2924ac4fed71ca9baea2383fc0a2958f25c (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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
module(..., package.seeall)

require("posix")

local parent_exception_handler

mvc = {}
mvc.on_load = function (self, parent)
	-- Make sure we have some kind of sane defaults for libdir
	self.conf.libdir = self.conf.libdir or ( string.match(self.conf.appdir, "[^,]+/") .. "/lib/" )
	self.conf.script = ""
	self.conf.default_prefix = "/acf-util/"	
	self.conf.default_controller = "welcome"
	self.conf.viewtype = "serialized"

	parent_exception_handler = parent.exception_handler

	-- this sets the package path for us and our children
	for p in string.gmatch(self.conf.libdir, "[^,]+") do
		package.path=  p .. "?.lua;" .. package.path
	end

	self.session = {}
	local x=require("session")
end

exception_handler = function (self, message )
	print(session.serialize("exception", message))
	parent_exception_handler(self, message)
end

handle_clientdata = function(form, clientdata, group)
	form.errtxt = nil
	for n,value in pairs(form.value) do
		value.errtxt = nil
		local name = n
		if group then name = group.."."..name end
		if value.type == "group" then
			handle_clientdata(value, clientdata, name)
		-- Don't update from the default unless a value exists
		elseif value.type == "boolean" and clientdata[name] then
			value.value = (clientdata[name] == "true")
		elseif value.type == "multi" or value.type == "list" then
			-- for cli we use name[num] as the name
			local temp = {} 
			for n,val in pairs(clientdata) do
				if string.find(n, "^"..name.."%[%d+%]$") then
					temp[tonumber(string.match(n, "%[(%d+)%]$"))] = val
				end
			end
			-- Use clientdata[name] to specify empty list
			if #temp > 0 or clientdata[name] then
				value.value = temp
			end
		else
			value.value = clientdata[name] or value.value
		end
	end
end