luci-base: initialize CBI optionals on initial Map render (#618)
Signed-off-by: Jo-Philipp Wich <jow@openwrt.org>
This commit is contained in:
parent
ad064f0b03
commit
eaf961fa70
1 changed files with 21 additions and 3 deletions
|
@ -336,7 +336,7 @@ function Map.__init__(self, config, ...)
|
||||||
end
|
end
|
||||||
|
|
||||||
function Map.formvalue(self, key)
|
function Map.formvalue(self, key)
|
||||||
return self.readinput and luci.http.formvalue(key)
|
return self.readinput and luci.http.formvalue(key) or nil
|
||||||
end
|
end
|
||||||
|
|
||||||
function Map.formvaluetable(self, key)
|
function Map.formvaluetable(self, key)
|
||||||
|
@ -886,14 +886,18 @@ function AbstractSection.render_tab(self, tab, ...)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Parse optional options
|
-- Parse optional options
|
||||||
function AbstractSection.parse_optionals(self, section)
|
function AbstractSection.parse_optionals(self, section, noparse)
|
||||||
if not self.optional then
|
if not self.optional then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
self.optionals[section] = {}
|
self.optionals[section] = {}
|
||||||
|
|
||||||
local field = self.map:formvalue("cbi.opt."..self.config.."."..section)
|
local field = nil
|
||||||
|
if not noparse then
|
||||||
|
field = self.map:formvalue("cbi.opt."..self.config.."."..section)
|
||||||
|
end
|
||||||
|
|
||||||
for k,v in ipairs(self.children) do
|
for k,v in ipairs(self.children) do
|
||||||
if v.optional and not v:cfgvalue(section) and not self:has_tabs() then
|
if v.optional and not v:cfgvalue(section) and not self:has_tabs() then
|
||||||
if field == v.option then
|
if field == v.option then
|
||||||
|
@ -1071,6 +1075,11 @@ function NamedSection.__init__(self, map, section, stype, ...)
|
||||||
self.section = section
|
self.section = section
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function NamedSection.prepare(self)
|
||||||
|
AbstractSection.prepare(self)
|
||||||
|
AbstractSection.parse_optionals(self, self.section, true)
|
||||||
|
end
|
||||||
|
|
||||||
function NamedSection.parse(self, novld)
|
function NamedSection.parse(self, novld)
|
||||||
local s = self.section
|
local s = self.section
|
||||||
local active = self:cfgvalue(s)
|
local active = self:cfgvalue(s)
|
||||||
|
@ -1120,6 +1129,15 @@ function TypedSection.__init__(self, map, type, ...)
|
||||||
self.anonymous = false
|
self.anonymous = false
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function TypedSection.prepare(self)
|
||||||
|
AbstractSection.prepare(self)
|
||||||
|
|
||||||
|
local i, s
|
||||||
|
for i, s in ipairs(self:cfgsections()) do
|
||||||
|
AbstractSection.parse_optionals(self, s, true)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
-- Return all matching UCI sections for this TypedSection
|
-- Return all matching UCI sections for this TypedSection
|
||||||
function TypedSection.cfgsections(self)
|
function TypedSection.cfgsections(self)
|
||||||
local sections = {}
|
local sections = {}
|
||||||
|
|
Loading…
Reference in a new issue