modules/admin-full: fix initial state of network_ifacelist widget
[project/luci.git] / modules / admin-full / luasrc / model / cbi / admin_network / ifaces.lua
index 3debf58baffa184f3678231825cbf6474e7e0f15..8f5f5e42fae5b01fed126260dc9ccc17a568e81d 100644 (file)
@@ -103,6 +103,9 @@ if not ( has_pppd and has_pppoe and has_pppoa and has_3g and has_pptp ) then
        p.description = translate("You need to install \"comgt\" for UMTS/GPRS, \"ppp-mod-pppoe\" for PPPoE, \"ppp-mod-pppoa\" for PPPoA or \"pptp\" for PPtP support")
 end
 
+auto = s:taboption("physical", Flag, "auto", translate("Bring up on boot"))                                                                                            
+auto.default = (m.uci:get("network", arg[1], "proto") == "none") and auto.disabled or auto.enabled
+
 br = s:taboption("physical", Flag, "type", translate("Bridge interfaces"), translate("creates a bridge over specified interface(s)"))
 br.enabled = "bridge"
 br.rmempty = true
@@ -120,7 +123,6 @@ ifname_single.template = "cbi/network_ifacelist"
 ifname_single.widget = "radio"
 ifname_single.nobridges = true
 ifname_single.network = arg[1]
-ifname_single.rmempty = true
 ifname_single:depends({ type = "", proto = "static" })
 ifname_single:depends({ type = "", proto = "dhcp"   })
 ifname_single:depends({ type = "", proto = "pppoe"  })
@@ -129,7 +131,8 @@ ifname_single:depends({ type = "", proto = "ahcp"   })
 ifname_single:depends({ type = "", proto = "none"   })
 
 function ifname_single.cfgvalue(self, s)
-       return self.map.uci:get("network", s, "ifname")
+       -- let the template figure out the related ifaces through the network model
+       return nil
 end
 
 function ifname_single.write(self, s, val)
@@ -151,6 +154,11 @@ function ifname_single.write(self, s, val)
        end
 end
 
+function ifname_single.remove(self, s)
+       self:write(s, "")
+end
+
+
 ifname_multi = s:taboption("physical", Value, "ifname_multi", translate("Interface"))
 ifname_multi.template = "cbi/network_ifacelist"
 ifname_multi.nobridges = true
@@ -159,6 +167,7 @@ ifname_multi.widget = "checkbox"
 ifname_multi:depends("type", "bridge")
 ifname_multi.cfgvalue = ifname_single.cfgvalue
 ifname_multi.write = ifname_single.write
+ifname_multi.remove = ifname_single.remove
 
 
 if has_firewall then
@@ -660,8 +669,7 @@ end
 if has_dnsmasq and net:proto() == "static" then
        m2 = Map("dhcp", "", "")
        
-       local section_id = "-"
-
+       local section_id
        function m2.on_parse()
                m2.uci:foreach("dhcp", "dhcp", function(s)
                        if s.interface == arg[1] then
@@ -669,6 +677,15 @@ if has_dnsmasq and net:proto() == "static" then
                                return false
                        end
                end)
+
+               if not section_id then
+                       local c = 1
+                       section_id = arg[1]
+                       while m2.uci:get("dhcp", section_id) do
+                               section_id = arg[1] .. c
+                               c = c + 1
+                       end
+               end
        end
 
        s = m2:section(TypedSection, "dhcp", translate("DHCP Server"))
@@ -687,17 +704,16 @@ if has_dnsmasq and net:proto() == "static" then
                        "this interface."))
 
        ignore.rmempty = false
-
-       function ignore.cfgvalue(self, section)
-               return (section == "-") and self.enabled or Flag.cfgvalue(self, section)
-       end
+       ignore.default = ignore.enabled
 
        function ignore.write(self, section, value)
-               section_id = m2.uci:section("dhcp", "dhcp", nil, {
-                       ignore    = value,
-                       interface = arg[1]
-               })
-       end 
+               if m2.uci:get("dhcp", section) ~= "dhcp" then
+                       m2.uci:section("dhcp", "dhcp", section, {
+                               interface = arg[1]
+                       })
+               end
+               m2.uci:set("dhcp", section, "ignore", (value == "1") and "1" or "0")
+       end
 
 
        local start = s:taboption("general", Value, "start", translate("Start"),
@@ -743,19 +759,9 @@ if has_dnsmasq and net:proto() == "static" then
                        "192.168.2.2</code>\" which advertises different DNS servers to clients."))
 
 
-       local function write_opt(self, section, value)
-               return getmetatable(self).__index.write(self, section_id, value)
-       end
-
-       local function remove_opt(self, section, value)
-               return getmetatable(self).__index.remove(self, section_id, value)
-       end
-
        for i, n in ipairs(s.children) do
                if n ~= ignore then
                        n:depends("ignore", "")
-                       n.write  = write_opt
-                       n.remove = remove_opt
                end
        end
 end