Changeset 7915

Show
Ignore:
Timestamp:
11/10/11 13:57:13 (19 months ago)
Author:
soma
Message:

admin-full: Better fix for the last change (timeserver setup), add button to add the missing section

Files:
1 modified

Legend:

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

    r7913 r7915  
    155155 
    156156if has_ntpd then 
    157     s = m:section(TypedSection, "timeserver", translate("Time Synchronization")) 
    158     s.anonymous = true 
    159     s.addremove = false 
    160  
    161     function m.on_parse() 
    162         local has_section = false 
    163  
    164         m.uci:foreach("system", "timeserver", 
    165             function(s) 
    166                 has_section = true 
    167                 return false 
    168         end) 
    169  
    170         if not has_section then 
    171             m.uci:section("system", "timeserver", "ntp") 
     157 
     158    -- timeserver setup was requested, create section and reload page 
     159    if m:formvalue("cbid.system._timeserver._enable") then 
     160        m.uci:section("system", "timeserver", "ntp") 
     161        m.uci:save("system") 
     162        luci.http.redirect(luci.dispatcher.build_url("admin/system", arg[1])) 
     163        return 
     164    end 
     165 
     166    local has_section = false 
     167    m.uci:foreach("system", "timeserver",  
     168        function(s)  
     169            has_section = true  
     170            return false 
     171    end) 
     172 
     173    if not has_section then 
     174 
     175        s = m:section(TypedSection, "timeserver", translate("Time Synchronization")) 
     176        s.anonymous   = true 
     177        s.cfgsections = function() return { "_timeserver" } end 
     178 
     179        x = s:option(Button, "_enable") 
     180        x.title      = translate("Time Synchronization is not configured yet.") 
     181        x.inputtitle = translate("Setup Time Synchronization") 
     182        x.inputstyle = "apply" 
     183 
     184    else 
     185         
     186        s = m:section(TypedSection, "timeserver", translate("Time Synchronization")) 
     187        s.anonymous = true 
     188        s.addremove = false 
     189 
     190        o = s:option(Flag, "enable", translate("Enable builtin NTP server")) 
     191        o.rmempty = false 
     192 
     193        function o.cfgvalue(self) 
     194            return luci.sys.init.enabled("sysntpd") 
     195                and self.enabled or self.disabled 
    172196        end 
    173     end 
    174  
    175     o = s:option(Flag, "enable", translate("Enable builtin NTP server")) 
    176     o.rmempty = false 
    177  
    178     function o.cfgvalue(self) 
    179         return luci.sys.init.enabled("sysntpd") 
    180             and self.enabled or self.disabled 
    181     end 
    182  
    183     function o.write(self, section, value) 
    184         if value == self.enabled then 
    185             luci.sys.init.enable("sysntpd") 
    186             luci.sys.call("env -i /etc/init.d/sysntpd start >/dev/null") 
    187         else 
    188             luci.sys.call("env -i /etc/init.d/sysntpd stop >/dev/null") 
    189             luci.sys.init.disable("sysntpd") 
     197 
     198        function o.write(self, section, value) 
     199            if value == self.enabled then 
     200                luci.sys.init.enable("sysntpd") 
     201                luci.sys.call("env -i /etc/init.d/sysntpd start >/dev/null") 
     202            else 
     203                luci.sys.call("env -i /etc/init.d/sysntpd stop >/dev/null") 
     204                luci.sys.init.disable("sysntpd") 
     205            end 
    190206        end 
    191     end 
    192  
    193  
    194     o = s:option(DynamicList, "server", translate("NTP server candidates")) 
    195     o.datatype = "host" 
    196     o:depends("enable", "1") 
    197  
    198     -- retain server list even if disabled 
    199     function o.remove() end 
    200 end 
    201  
     207 
     208 
     209        o = s:option(DynamicList, "server", translate("NTP server candidates")) 
     210        o.datatype = "host" 
     211        o:depends("enable", "1") 
     212 
     213        -- retain server list even if disabled 
     214        function o.remove() end 
     215 
     216    end 
     217end 
    202218 
    203219return m