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