libs/cbi: Fixed UVL integration

This commit is contained in:
Steven Barth 2008-08-24 20:44:47 +00:00
parent d68d03085a
commit d97d6329c3

View file

@ -40,6 +40,8 @@ FORM_NODATA = 0
FORM_VALID = 1 FORM_VALID = 1
FORM_INVALID = -1 FORM_INVALID = -1
AUTO = true
CREATE_PREFIX = "cbi.cts." CREATE_PREFIX = "cbi.cts."
REMOVE_PREFIX = "cbi.rts." REMOVE_PREFIX = "cbi.rts."
@ -83,7 +85,7 @@ function _uvl_strip_remote_dependencies(deps)
for k, v in pairs(deps) do for k, v in pairs(deps) do
k = k:gsub("%$config%.%$section%.", "") k = k:gsub("%$config%.%$section%.", "")
if k:match("^[%w_]+$") then if k:match("^[%w_]+$") and type(v) == "string" then
clean[k] = v clean[k] = v
end end
end end
@ -403,18 +405,17 @@ end
-- Appends a new option -- Appends a new option
function AbstractSection.option(self, class, option, ...) function AbstractSection.option(self, class, option, ...)
-- Autodetect form UVL -- Autodetect from UVL
if not class or type(class) == "boolean" if class == true and self.map:get_scheme(self.sectiontype, option) then
and self.map:get_scheme(self.sectiontype, option) then
local vs = self.map:get_scheme(self.sectiontype, option) local vs = self.map:get_scheme(self.sectiontype, option)
if vs.type == "boolean" then if vs.type == "boolean" then
class = "Flag" class = Flag
elseif vs.type == "list" then elseif vs.type == "list" then
class = "DynamicList" class = DynamicList
elseif vs.type == "enum" or vs.type == "reference" then elseif vs.type == "enum" or vs.type == "reference" then
class = "ListValue" class = ListValue
else else
class = "Value" class = Value
end end
end end
@ -425,7 +426,7 @@ function AbstractSection.option(self, class, option, ...)
self:append(obj) self:append(obj)
return obj return obj
elseif not class or type(class) == "boolean" then elseif class == true then
error("No valid class was given and autodetection failed.") error("No valid class was given and autodetection failed.")
else else
error("class must be a descendant of AbstractValue") error("class must be a descendant of AbstractValue")
@ -803,12 +804,6 @@ function AbstractValue.__init__(self, map, section, option, ...)
end end
end end
end end
if self.value and vs.values and not self.override_values then
for k, v in pairs(vs.values) do
self:value(k, v)
end
end
end end
end end
@ -1012,11 +1007,24 @@ ListValue = class(AbstractValue)
function ListValue.__init__(self, ...) function ListValue.__init__(self, ...)
AbstractValue.__init__(self, ...) AbstractValue.__init__(self, ...)
self.template = "cbi/lvalue" self.template = "cbi/lvalue"
self.keylist = {} self.keylist = {}
self.vallist = {} self.vallist = {}
self.size = 1 self.size = 1
self.widget = "select" self.widget = "select"
if not self.override_scheme
and self.map:get_scheme(self.section.sectiontype, self.option) then
local vs = self.map:get_scheme(self.section.sectiontype, self.option)
if self.value and vs.values and not self.override_values then
if self.rmempty or self.optional then
self:value("")
end
for k, v in pairs(vs.values) do
self:value(k, v)
end
end
end
end end
function ListValue.value(self, key, val, ...) function ListValue.value(self, key, val, ...)
@ -1049,6 +1057,7 @@ MultiValue = class(AbstractValue)
function MultiValue.__init__(self, ...) function MultiValue.__init__(self, ...)
AbstractValue.__init__(self, ...) AbstractValue.__init__(self, ...)
self.template = "cbi/mvalue" self.template = "cbi/mvalue"
self.keylist = {} self.keylist = {}
self.vallist = {} self.vallist = {}
@ -1101,6 +1110,16 @@ function StaticList.__init__(self, ...)
MultiValue.__init__(self, ...) MultiValue.__init__(self, ...)
self.cast = "table" self.cast = "table"
self.valuelist = self.cfgvalue self.valuelist = self.cfgvalue
if not self.override_scheme
and self.map:get_scheme(self.section.sectiontype, self.option) then
local vs = self.map:get_scheme(self.section.sectiontype, self.option)
if self.value and vs.values and not self.override_values then
for k, v in pairs(vs.values) do
self:value(k, v)
end
end
end
end end
function StaticList.validate(self, value) function StaticList.validate(self, value)
@ -1122,7 +1141,6 @@ function DynamicList.__init__(self, ...)
AbstractValue.__init__(self, ...) AbstractValue.__init__(self, ...)
self.template = "cbi/dynlist" self.template = "cbi/dynlist"
self.cast = "table" self.cast = "table"
self.keylist = {} self.keylist = {}
self.vallist = {} self.vallist = {}
end end