libs/cbi: Fixed CBI handling of "Save & Apply"
authorSteven Barth <steven@midlink.org>
Wed, 30 Jul 2008 19:01:07 +0000 (19:01 +0000)
committerSteven Barth <steven@midlink.org>
Wed, 30 Jul 2008 19:01:07 +0000 (19:01 +0000)
libs/cbi/luasrc/cbi.lua
modules/admin-mini/luasrc/model/cbi/mini/wifi.lua

index e695289..fe99f02 100644 (file)
@@ -144,20 +144,44 @@ function Map.__init__(self, config, ...)
        Node._i18n(self, config, nil, nil, ...)
 
        self.config = config
        Node._i18n(self, config, nil, nil, ...)
 
        self.config = config
+       self.parsechain = {self.config}
        self.template = "cbi/map"
        if not uci.load(self.config) then
                error("Unable to read UCI data: " .. self.config)
        end
 end
 
        self.template = "cbi/map"
        if not uci.load(self.config) then
                error("Unable to read UCI data: " .. self.config)
        end
 end
 
+
+-- Chain foreign config
+function Map.chain(self, config)
+       table.insert(self.parsechain, config)
+end
+
 -- Use optimized UCI writing
 function Map.parse(self, ...)
        Node.parse(self, ...)
 -- Use optimized UCI writing
 function Map.parse(self, ...)
        Node.parse(self, ...)
-       uci.save(self.config)
+       for i, config in ipairs(self.parsechain) do
+               uci.save(config)
+       end
        if luci.http.formvalue("cbi.apply") then
        if luci.http.formvalue("cbi.apply") then
-               uci.commit(self.config)
+               for i, config in ipairs(self.parsechain) do
+                       uci.commit(config)
+                       if luci.config.uci_oncommit and luci.config.uci_oncommit[config] then
+                               luci.sys.exec(luci.config.uci_oncommit[config])
+                       end
+
+                       -- Refresh data because commit changes section names
+                       uci.unload(config)
+                       uci.load(config)
+               end
+
+               -- Reparse sections
+               Node.parse(self, ...)
+
+       end
+       for i, config in ipairs(self.parsechain) do
+               uci.unload(config)
        end
        end
-       uci.unload(self.config)
 end
 
 -- Creates a child section
 end
 
 -- Creates a child section
index 30766a4..2890a78 100644 (file)
@@ -13,6 +13,7 @@ You may obtain a copy of the License at
 $Id$
 ]]--
 m = Map("wireless", translate("wifi"), translate("a_w_devices1"))
 $Id$
 ]]--
 m = Map("wireless", translate("wifi"), translate("a_w_devices1"))
+m:chain("network")
 
 s = m:section(TypedSection, "wifi-device", translate("devices"))
 
 
 s = m:section(TypedSection, "wifi-device", translate("devices"))
 
@@ -67,8 +68,6 @@ function mode.write(self, section, value)
                        luci.model.uci.set("network", "wan", "_ifname", oldif)
                end
                luci.model.uci.set("network", "wan", "ifname", " ")
                        luci.model.uci.set("network", "wan", "_ifname", oldif)
                end
                luci.model.uci.set("network", "wan", "ifname", " ")
-               luci.model.uci.save("network")
-               luci.model.uci.unload("network")
 
                self.map:set(section, "network", "wan")
        else
 
                self.map:set(section, "network", "wan")
        else