summaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
authorTed Trask <ttrask01@yahoo.com>2012-02-23 20:10:37 +0000
committerTed Trask <ttrask01@yahoo.com>2012-02-23 20:10:37 +0000
commit8cf97414dc56b77d65f6e53b45cb36dc1c605104 (patch)
treec5d39753ffa55260d1906dfcbcf7ca71b827c7f4 /app
parent94e98d227ef5e21485bafd859b23d5d709ba79a8 (diff)
downloadacf-core-8cf97414dc56b77d65f6e53b45cb36dc1c605104.tar.bz2
acf-core-8cf97414dc56b77d65f6e53b45cb36dc1c605104.tar.xz
Modify acf_www and acf_cli handle_clientdata to separate out functionality for the two apps
Diffstat (limited to 'app')
-rw-r--r--app/acf_cli-controller.lua65
-rw-r--r--app/acf_www-controller.lua38
2 files changed, 28 insertions, 75 deletions
diff --git a/app/acf_cli-controller.lua b/app/acf_cli-controller.lua
index beb83b3..d6026eb 100644
--- a/app/acf_cli-controller.lua
+++ b/app/acf_cli-controller.lua
@@ -48,63 +48,28 @@ logevent = function ( ... )
os.execute ( "logger \"" .. ... .. "\"" )
end
--- FIXME - remove the haserl specific stuff
-handle_clientdata = function(form, clientdata)
+handle_clientdata = function(form, clientdata, group)
form.errtxt = nil
for n,value in pairs(form.value) do
value.errtxt = nil
local name = n
- if name:find("%.") and not clientdata[name] 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 group then name = group.."."..name end
if value.type == "group" then
- handle_clientdata(value, clientdata[name])
- elseif value.type == "boolean" then
- value.value = (clientdata[name] ~= nil) and (clientdata[name] ~= "false")
- elseif value.type == "multi" then
- if clientdata[name] == nil then
- -- for cli we use name[num] as the name
- clientdata[name] = {}
- for n,val in pairs(clientdata) do
- if string.find(n, "^"..name.."%[%d+%]$") then
- clientdata[name][tonumber(string.match(n, "%[(%d+)%]$"))] = val
- end
+ 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
- -- 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 www we use \r separated list
- for ip in string.gmatch(clientdata[name].."\n", "%s*([^\n]*%S)%s*\n") do
- table.insert(value.value, ip)
- end
- else
- -- for cli we use name[num] as the name
- for n,val in pairs(clientdata) do
- if string.find(n, "^"..name.."%[%d+%]$") then
- value.value[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
diff --git a/app/acf_www-controller.lua b/app/acf_www-controller.lua
index 4aed5e0..44fc92a 100644
--- a/app/acf_www-controller.lua
+++ b/app/acf_www-controller.lua
@@ -558,9 +558,8 @@ end
handle_clientdata = function(form, clientdata)
form.errtxt = nil
- for n,value in pairs(form.value) do
+ for name,value in pairs(form.value) do
value.errtxt = nil
- local name = n
if name:find("%.") and not clientdata[name] then
-- If the name has a '.' in it, haserl will interpret it as a table
local actualval = clientdata
@@ -577,18 +576,11 @@ handle_clientdata = function(form, clientdata)
if value.type == "group" then
handle_clientdata(value, clientdata[name])
elseif value.type == "boolean" then
+ --- HTML forms simply don't include checkboxes unless they're checked
value.value = (clientdata[name] ~= nil) and (clientdata[name] ~= "false")
elseif value.type == "multi" then
- if clientdata[name] == nil then
- -- for cli we use name[num] as the name
- clientdata[name] = {}
- for n,val in pairs(clientdata) do
- if string.find(n, "^"..name.."%[%d+%]$") then
- clientdata[name][tonumber(string.match(n, "%[(%d+)%]$"))] = val
- end
- end
- end
-- FIXME this is because multi selects don't work in haserl
+ -- Multi-selects are implemented as checkboxes, so if none exists, it means nothing is selected
local oldtable = clientdata[name] or {}
-- Assume it's a sparse array, and remove blanks
local newtable={}
@@ -598,23 +590,19 @@ handle_clientdata = function(form, clientdata)
end
end
value.value = newtable
- elseif value.type == "list" then
- value.value = {}
- if clientdata[name] and clientdata[name] ~= "" then
- -- for www we use \r separated list
- for ip in string.gmatch(clientdata[name].."\n", "%s*([^\n]*%S)%s*\n") do
- table.insert(value.value, ip)
- end
- else
- -- for cli we use name[num] as the name
- for n,val in pairs(clientdata) do
- if string.find(n, "^"..name.."%[%d+%]$") then
- value.value[tonumber(string.match(n, "%[(%d+)%]$"))] = val
+ elseif clientdata[name] then
+ -- The other types will be returned in clientdata even if set to blank, so if no result, leave the default
+ if value.type == "list" then
+ value.value = {}
+ if clientdata[name] ~= "" then
+ -- for www we use \r separated list
+ for l in string.gmatch(clientdata[name].."\n", "%s*([^\n]*%S)%s*\n") do
+ table.insert(value.value, l)
end
end
+ else
+ value.value = clientdata[name]
end
- else
- value.value = clientdata[name] or value.value
end
end
end