From 02082d03de31af25beed17cf3d61ca513ea6f885 Mon Sep 17 00:00:00 2001 From: Ted Trask Date: Sat, 12 Jul 2008 15:57:36 +0000 Subject: Fixed redirect_to_referrer with GET data. Moved handling of multi select from acf_www-controller to controllerfunctions. Fixed form ids containing '.'. Added new handle_clientdata function to controllerfunctions. Modified password-controller to use handle_clientdata for multi select to work.k git-svn-id: svn://svn.alpinelinux.org/acf/core/trunk@1299 ab2d0c66-481e-0410-8bed-d214d4d58bed --- lib/controllerfunctions.lua | 61 +++++++++++++++++++++++++++++++++------------ 1 file changed, 45 insertions(+), 16 deletions(-) (limited to 'lib/controllerfunctions.lua') diff --git a/lib/controllerfunctions.lua b/lib/controllerfunctions.lua index ec62fee..5c3e559 100644 --- a/lib/controllerfunctions.lua +++ b/lib/controllerfunctions.lua @@ -1,25 +1,54 @@ module(..., package.seeall) +function handle_clientdata(form, clientdata) + form.errtxt = nil + for name,value in pairs(form.value) do + value.errtxt = nil + if name:find("%.") then + -- If the name has a '.' in it, haserl will interpret it as a table + local actualval = clientdata + for entry in name:gmatch("[^%.]+") do + if tonumber(entry) then + actualval = actualval[tonumber(entry)] + else + actualval = actualval[entry] + end + if not actualval then break end + end + clientdata[name] = actualval + end + if value.type == "boolean" then + value.value = (clientdata[name] ~= nil) + elseif value.type == "multi" then + -- FIXME this is because multi selects don't work in haserl + local oldtable = clientdata[name] or {} + -- Assume it's a sparse array, and remove blanks + local newtable={} + for x=1,table.maxn(oldtable) do + if oldtable[x] then + newtable[#newtable + 1] = oldtable[x] + end + end + value.value = newtable + elseif value.type == "list" then + value.value = {} + if clientdata[name] and clientdata[name] ~= "" then + for ip in string.gmatch(clientdata[name].."\n", "%s*(%S[^\n]*%S)%s*\n") do + table.insert(value.value, ip) + end + end + else + value.value = clientdata[name] or value.value + end + end +end + function handle_form(self, getFunction, setFunction, clientdata, option, label, descr, redirectOnSuccess) local form = getFunction() if clientdata[option] then - form.errtxt = nil - for name,value in pairs(form.value) do - value.errtxt = nil - if value.type == "boolean" then - value.value = (clientdata[name] ~= nil) - elseif value.type == "list" then - value.value = {} - if clientdata[name] and clientdata[name] ~= "" then - for ip in string.gmatch(clientdata[name].."\n", "%s*(%S[^\n]*%S)%s*\n") do - table.insert(value.value, ip) - end - end - else - value.value = clientdata[name] or value.value - end - end + handle_clientdata(form, clientdata) + form = setFunction(form) if not form.errtxt and descr then form.descr = descr -- cgit v1.2.3