CREATE_PREFIX = "cbi.cts."
REMOVE_PREFIX = "cbi.rts."
RESORT_PREFIX = "cbi.sts."
+FEXIST_PREFIX = "cbi.cbe."
-- Loads a CBI map from given file, creating an environment and returns it
function load(cbimap, ...)
AbstractValue.__init__(self, ...)
self.template = "cbi/fvalue"
- self.enabled = "1"
+ self.enabled = "1"
self.disabled = "0"
+ self.default = self.disabled
end
-- A flag can only have two states: set or unset
function Flag.parse(self, section)
- local fvalue = self:formvalue(section)
-
- if fvalue then
- fvalue = self.enabled
- else
- fvalue = self.disabled
- end
+ local fexists = self.map:formvalue(
+ FEXIST_PREFIX .. self.config .. "." .. section .. "." .. self.option)
- if fvalue == self.enabled or (not self.optional and not self.rmempty) then
- if not(fvalue == self:cfgvalue(section)) then
+ if fexists then
+ local fvalue = self:formvalue(section) and self.enabled or self.disabled
+ if fvalue ~= self.default or (not self.optional and not self.rmempty) then
self:write(section, fvalue)
+ else
+ self:remove(section)
end
else
self:remove(section)
end
end
+function Flag.cfgvalue(self, section)
+ return AbstractValue.cfgvalue(self, section) or self.default
+end
--[[
-%>
<%+cbi/valueheader%>
+ <input type="hidden" value="1"<%=
+ attr("name", "cbi.cbe." .. self.config .. "." .. section .. "." .. self.option)
+ %> />
<input class="cbi-input-checkbox" onclick="cbi_d_update(this.id)" onchange="cbi_d_update(this.id)" type="checkbox"<%=
attr("id", cbid) .. attr("name", cbid) .. attr("value", self.enabled or 1) ..
ifattr((self:cfgvalue(section) or self.default) == self.enabled, "checked", "checked")
defaultroute:depends("proto", "pppoe")
defaultroute:depends("proto", "pptp")
defaultroute:depends("proto", "3g")
- defaultroute.rmempty = false
- function defaultroute.cfgvalue(...)
- return ( AbstractValue.cfgvalue(...) or '1' )
- end
+ defaultroute.default = defaultroute.enabled
peerdns = s:taboption("ppp", Flag, "peerdns",
translate("Use peer DNS"),
peerdns:depends("proto", "pppoe")
peerdns:depends("proto", "pptp")
peerdns:depends("proto", "3g")
- peerdns.rmempty = false
- function peerdns.cfgvalue(...)
- return ( AbstractValue.cfgvalue(...) or '1' )
- end
+ peerdns.default = peerdns.enabled
if has_ipv6 then
ipv6 = s:taboption("ppp", Flag, "ipv6", translate("Enable IPv6 on PPP link") )
translate("Dynamic <abbr title=\"Dynamic Host Configuration Protocol\">DHCP</abbr>"),
translate("Dynamically allocate DHCP addresses for clients. If disabled, only " ..
"clients having static leases will be served."))
-
- dd.rmempty = false
- function dd.cfgvalue(self, section)
- return Flag.cfgvalue(self, section) or "1"
- end
+ dd.default = dd.enabled
s:taboption("advanced", Flag, "force", translate("Force"),
translate("Force DHCP on this network even if another server is detected."))