Huuuuuuuuuuuge rewrite of the Wireless Configuration
[project/luci.git] / libs / cbi / luasrc / cbi.lua
index bf4bfb8..6cc0908 100644 (file)
@@ -157,7 +157,7 @@ function Map.__init__(self, config, ...)
        self.config = config
        self.parsechain = {self.config}
        self.template = "cbi/map"
-       if not uci.load(self.config) then
+       if not uci.load_config(self.config) then
                error("Unable to read UCI data: " .. self.config)
        end
 end
@@ -170,9 +170,16 @@ end
 
 -- Use optimized UCI writing
 function Map.parse(self, ...)
+       if self.stateful then
+               uci.load_state(self.config)
+       else
+               uci.load_config(self.config)
+       end
+       
        Node.parse(self, ...)
+       
        for i, config in ipairs(self.parsechain) do
-               uci.save(config)
+               uci.save_config(config)
        end
        if luci.http.formvalue("cbi.apply") then
                for i, config in ipairs(self.parsechain) do
@@ -182,8 +189,7 @@ function Map.parse(self, ...)
                        end
 
                        -- Refresh data because commit changes section names
-                       uci.unload(config)
-                       uci.load(config)
+                       uci.load_config(config)
                end
 
                -- Reparse sections
@@ -240,11 +246,6 @@ function Map.get(self, section, option)
        end
 end
 
--- UCI stateget
-function Map.stateget(self, section, option)
-       return uci.get_statevalue(self.config, section, option)
-end
-
 
 --[[
 Page - A simple node
@@ -705,12 +706,19 @@ function AbstractValue.__init__(self, map, option, ...)
        self.default   = nil
        self.size      = nil
        self.optional  = false
-       self.stateful  = false
 end
 
 -- Add a dependencie to another section field
 function AbstractValue.depends(self, field, value)
-       table.insert(self.deps, {field=field, value=value})
+       local deps
+       if type(field) == "string" then
+               deps = {}
+               deps[field] = value
+       else
+               deps = field
+       end
+       
+       table.insert(self.deps, {deps=deps, add=""})
 end
 
 -- Generates the unique CBID
@@ -789,9 +797,7 @@ end
 
 -- Return the UCI value of this object
 function AbstractValue.cfgvalue(self, section)
-       return self.stateful
-        and self.map:stateget(section, self.option)
-        or  self.map:get(section, self.option)
+       return self.map:get(section, self.option)
 end
 
 -- Validate the form value
@@ -899,10 +905,14 @@ function ListValue.__init__(self, ...)
        self.widget = "select"
 end
 
-function ListValue.value(self, key, val)
+function ListValue.value(self, key, val, ...)
        val = val or key
        table.insert(self.keylist, tostring(key))
        table.insert(self.vallist, tostring(val))
+       
+       for i, deps in ipairs({...}) do
+               table.insert(self.deps, {add = "-"..key, deps=deps})
+       end
 end
 
 function ListValue.validate(self, val)