From: Jo-Philipp Wich Date: Sat, 12 Feb 2011 16:33:05 +0000 (+0000) Subject: luci-0.10: merge r6821 and r6822 (#199) X-Git-Tag: 0.10.0~182 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=39c2331d23703743fdf28cbd864575dd949f3694;p=oweals%2Fluci.git luci-0.10: merge r6821 and r6822 (#199) --- diff --git a/libs/web/luasrc/cbi.lua b/libs/web/luasrc/cbi.lua index 8bb3488a7..5dd57e2e9 100644 --- a/libs/web/luasrc/cbi.lua +++ b/libs/web/luasrc/cbi.lua @@ -51,6 +51,7 @@ AUTO = true 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, ...) @@ -1481,29 +1482,31 @@ function Flag.__init__(self, ...) 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 --[[ diff --git a/libs/web/luasrc/view/cbi/fvalue.htm b/libs/web/luasrc/view/cbi/fvalue.htm index 013c54e68..df96fe2c6 100644 --- a/libs/web/luasrc/view/cbi/fvalue.htm +++ b/libs/web/luasrc/view/cbi/fvalue.htm @@ -13,6 +13,9 @@ $Id$ -%> <%+cbi/valueheader%> + /> DHCP"), 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."))