Changeset 7229

Show
Ignore:
Timestamp:
06/25/11 22:51:12 (2 years ago)
Author:
jow
Message:

modules/admin-full: defer writing of interface related dhcp options until an actual save occurs, prevents "unsaved changes" upon opening the interface settings page

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • luci/trunk/modules/admin-full/luasrc/model/cbi/admin_network/ifaces.lua

    r7115 r7229  
    33 
    44Copyright 2008 Steven Barth <steven@midlink.org> 
    5 Copyright 2008 Jo-Philipp Wich <xm@subsignal.org> 
     5Copyright 2008-2011 Jo-Philipp Wich <xm@subsignal.org> 
    66 
    77Licensed under the Apache License, Version 2.0 (the "License"); 
     
    660660if has_dnsmasq and net:proto() == "static" then 
    661661    m2 = Map("dhcp", "", "") 
     662     
     663    local section_id = "-" 
     664 
    662665    function m2.on_parse() 
    663         local has_section = false 
    664  
    665666        m2.uci:foreach("dhcp", "dhcp", function(s) 
    666667            if s.interface == arg[1] then 
    667                 has_section = true 
     668                section_id = s['.name'] 
    668669                return false 
    669670            end 
    670671        end) 
    671  
    672         if not has_section then 
    673             m2.uci:section("dhcp", "dhcp", nil, { interface = arg[1], ignore = "1" }) 
    674             m2.uci:save("dhcp") 
    675         end 
    676672    end 
    677673 
     
    682678    s:tab("advanced", translate("Advanced Settings")) 
    683679 
    684     function s.filter(self, section) 
    685         return m2.uci:get("dhcp", section, "interface") == arg[1] 
     680    function s.cfgsections(self) 
     681        return { section_id } 
    686682    end 
    687683 
     
    692688 
    693689    ignore.rmempty = false 
     690 
     691    function ignore.cfgvalue(self, section) 
     692        return (section == "-") and self.enabled or Flag.cfgvalue(self, section) 
     693    end 
     694 
     695    function ignore.write(self, section, value) 
     696        section_id = m2.uci:section("dhcp", "dhcp", nil, { 
     697            ignore    = value, 
     698            interface = arg[1] 
     699        }) 
     700    end  
     701 
    694702 
    695703    local start = s:taboption("general", Value, "start", translate("Start"), 
     
    735743            "192.168.2.2</code>\" which advertises different DNS servers to clients.")) 
    736744 
     745 
     746    local function write_opt(self, section, value) 
     747        return getmetatable(self).__index.write(self, section_id, value) 
     748    end 
     749 
     750    local function remove_opt(self, section, value) 
     751        return getmetatable(self).__index.remove(self, section_id, value) 
     752    end 
     753 
    737754    for i, n in ipairs(s.children) do 
    738755        if n ~= ignore then 
    739756            n:depends("ignore", "") 
     757            n.write  = write_opt 
     758            n.remove = remove_opt 
    740759        end 
    741760    end