diff options
author | Jo-Philipp Wich <jow@openwrt.org> | 2010-10-25 17:04:03 +0000 |
---|---|---|
committer | Jo-Philipp Wich <jow@openwrt.org> | 2010-10-25 17:04:03 +0000 |
commit | 70706cf388f8ac100778831e9ef9d7b1eb74c752 (patch) | |
tree | 096cada604879e8806762a050fd176b9b592f24c /libs/web/luasrc/cbi.lua | |
parent | eecec8b0f2a2cd86827115c1479de974ece00850 (diff) |
libs/web: rework DynamicList widget
Diffstat (limited to 'libs/web/luasrc/cbi.lua')
-rw-r--r-- | libs/web/luasrc/cbi.lua | 45 |
1 files changed, 34 insertions, 11 deletions
diff --git a/libs/web/luasrc/cbi.lua b/libs/web/luasrc/cbi.lua index 5fa992dee8..17ca18c941 100644 --- a/libs/web/luasrc/cbi.lua +++ b/libs/web/luasrc/cbi.lua @@ -1641,25 +1641,48 @@ function DynamicList.value(self, key, val) table.insert(self.vallist, tostring(val)) end -function DynamicList.write(self, ...) - self.map.proceed = true - return AbstractValue.write(self, ...) +function DynamicList.write(self, section, value) + if self.cast == "string" and type(value) == "table" then + value = table.concat(value, " ") + elseif self.cast == "table" and type(value) == "string" then + local x, t = { } + for x in value:gmatch("%S+") do + t[#t+1] = x + end + value = t + end + + return AbstractValue.write(self, section, value) +end + +function DynamicList.cfgvalue(self, section) + local value = AbstractValue.cfgvalue(self, section) + + if type(value) == "string" then + local x + local t = { } + for x in value:gmatch("%S+") do + t[#t+1] = x + end + value = t + end + + return value end function DynamicList.formvalue(self, section) local value = AbstractValue.formvalue(self, section) - value = (type(value) == "table") and value or {value} - local valid = {} - for i, v in ipairs(value) do - if v and #v > 0 - and not self.map:formvalue("cbi.rle."..section.."."..self.option.."."..i) - and not self.map:formvalue("cbi.rle."..section.."."..self.option.."."..i..".x") then - table.insert(valid, v) + if type(value) == "string" then + local x + local t = { } + for x in value:gmatch("%S+") do + t[#t+1] = x end + value = t end - return valid + return value end |