libs/cbi: Moved typecasting to the appropriate place
This commit is contained in:
parent
7e61238f96
commit
dc638500b5
1 changed files with 15 additions and 12 deletions
|
@ -367,7 +367,6 @@ function AbstractSection.__init__(self, map, sectiontype, ...)
|
||||||
self.config = map.config
|
self.config = map.config
|
||||||
self.optionals = {}
|
self.optionals = {}
|
||||||
self.defaults = {}
|
self.defaults = {}
|
||||||
self.cast = "string"
|
|
||||||
|
|
||||||
self.optional = true
|
self.optional = true
|
||||||
self.addremove = false
|
self.addremove = false
|
||||||
|
@ -447,16 +446,7 @@ end
|
||||||
|
|
||||||
-- Returns the section's UCI table
|
-- Returns the section's UCI table
|
||||||
function AbstractSection.cfgvalue(self, section)
|
function AbstractSection.cfgvalue(self, section)
|
||||||
local value = self.map:get(section)
|
return self.map:get(section)
|
||||||
if not self.cast or self.cast == type(value) then
|
|
||||||
return value
|
|
||||||
elseif self.cast == "string" then
|
|
||||||
if type(value) == "table" then
|
|
||||||
return value[1]
|
|
||||||
end
|
|
||||||
elseif self.cast == "table" then
|
|
||||||
return {value}
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Removes the section
|
-- Removes the section
|
||||||
|
@ -651,6 +641,9 @@ function TypedSection.parse(self)
|
||||||
crval = REMOVE_PREFIX .. self.config
|
crval = REMOVE_PREFIX .. self.config
|
||||||
name = luci.http.formvaluetable(crval)
|
name = luci.http.formvaluetable(crval)
|
||||||
for k,v in pairs(name) do
|
for k,v in pairs(name) do
|
||||||
|
luci.util.perror(k)
|
||||||
|
luci.util.perror(self:cfgvalue(k))
|
||||||
|
luci.util.perror(self:checkscope(k))
|
||||||
if self:cfgvalue(k) and self:checkscope(k) then
|
if self:cfgvalue(k) and self:checkscope(k) then
|
||||||
self:remove(k)
|
self:remove(k)
|
||||||
end
|
end
|
||||||
|
@ -719,6 +712,7 @@ function AbstractValue.__init__(self, map, option, ...)
|
||||||
self.tag_missing = {}
|
self.tag_missing = {}
|
||||||
self.tag_error = {}
|
self.tag_error = {}
|
||||||
self.deps = {}
|
self.deps = {}
|
||||||
|
self.cast = "string"
|
||||||
|
|
||||||
self.track_missing = false
|
self.track_missing = false
|
||||||
self.rmempty = false
|
self.rmempty = false
|
||||||
|
@ -816,7 +810,16 @@ end
|
||||||
|
|
||||||
-- Return the UCI value of this object
|
-- Return the UCI value of this object
|
||||||
function AbstractValue.cfgvalue(self, section)
|
function AbstractValue.cfgvalue(self, section)
|
||||||
return self.map:get(section, self.option)
|
local value = self.map:get(section, self.option)
|
||||||
|
if not self.cast or self.cast == type(value) then
|
||||||
|
return value
|
||||||
|
elseif self.cast == "string" then
|
||||||
|
if type(value) == "table" then
|
||||||
|
return value[1]
|
||||||
|
end
|
||||||
|
elseif self.cast == "table" then
|
||||||
|
return {value}
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Validate the form value
|
-- Validate the form value
|
||||||
|
|
Loading…
Reference in a new issue