lib/cbi: Added support for multiple CBI maps per model

This commit is contained in:
Steven Barth 2008-07-15 13:17:28 +00:00
parent 97ff4a156f
commit d0a622dce8
3 changed files with 18 additions and 12 deletions

View file

@ -57,14 +57,16 @@ function load(cbimap)
luci.util.extfenv(func, "translate", luci.i18n.translate) luci.util.extfenv(func, "translate", luci.i18n.translate)
luci.util.extfenv(func, "translatef", luci.i18n.translatef) luci.util.extfenv(func, "translatef", luci.i18n.translatef)
local map = func() local maps = {func()}
for i, map in ipairs(maps) do
if not instanceof(map, Map) then if not instanceof(map, Map) then
error("CBI map returns no valid map object!") error("CBI map returns no valid map object!")
return nil return nil
end end
end
return map return maps
end end
-- Node pseudo abstract class -- Node pseudo abstract class

View file

@ -381,20 +381,24 @@ function cbi(model)
require("luci.template") require("luci.template")
return function() return function()
local stat, res = luci.util.copcall(luci.cbi.load, model) local stat, maps = luci.util.copcall(luci.cbi.load, model)
if not stat then if not stat then
error500(res) error500(maps)
return true return true
end end
for i, res in ipairs(maps) do
local stat, err = luci.util.copcall(res.parse, res) local stat, err = luci.util.copcall(res.parse, res)
if not stat then if not stat then
error500(err) error500(err)
return true return true
end end
end
luci.template.render("cbi/header") luci.template.render("cbi/header")
for i, res in ipairs(maps) do
res:render() res:render()
end
luci.template.render("cbi/footer") luci.template.render("cbi/footer")
end end
end end