summaryrefslogtreecommitdiffhomepage
path: root/libs/web/luasrc/cbi.lua
diff options
context:
space:
mode:
authorJo-Philipp Wich <jow@openwrt.org>2011-01-29 17:54:00 +0000
committerJo-Philipp Wich <jow@openwrt.org>2011-01-29 17:54:00 +0000
commitbe5b1015b2a3d87384ece96eba7d3c2a4a217fd4 (patch)
tree227681babdd06cccf5036f531cf85391d97c92e5 /libs/web/luasrc/cbi.lua
parentece62bd9abc158ab6b26a7e19ef89af789dff87d (diff)
libs/web: improve cbi handling of Flag values, support usage of .default attribute to signalize default-on checkboxes, this helps to deal with the reversed logic of various uci bools within OpenWrt configs
Diffstat (limited to 'libs/web/luasrc/cbi.lua')
-rw-r--r--libs/web/luasrc/cbi.lua23
1 files changed, 13 insertions, 10 deletions
diff --git a/libs/web/luasrc/cbi.lua b/libs/web/luasrc/cbi.lua
index 8bb3488a70..5dd57e2e96 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
--[[