luci-0.9: merge r5764
[project/luci.git] / applications / luci-initmgr / luasrc / model / cbi / init / init.lua
index 5d915a8..c3cbc46 100644 (file)
@@ -32,28 +32,54 @@ end
 
 m = SimpleForm("initmgr", translate("initmgr"), translate("initmgr_desc"))
 m.reset = false
+m.submit = false
+
 
 s = m:section(Table, inits)
 
 i = s:option(DummyValue, "index", translate("initmgr_index"))
 n = s:option(DummyValue, "name", translate("initmgr_name"))
 
-e = s:option(Flag, "enabled", translate("initmgr_enabled"))
-e.rmempty = false
 
-e.cfgvalue = function(self, section)
-       return inits[section].enabled and "1" or "0"
+e = s:option(Button, "endisable", translate("initmgr_enabled"))
+
+e.render = function(self, section, scope)
+       if inits[section].enabled then
+               self.title = translate("initmgr_enable", "Enabled")
+               self.inputstyle = "save"
+       else
+               self.title = translate("initmgr_disable", "Disabled")
+               self.inputstyle = "reset"
+       end
+
+       Button.render(self, section, scope)
 end
 
-e.write = function(self, section, value)
-       if value == "1" and not inits[section].enabled then
-               inits[section].enabled = true
-               return luci.sys.init.enable(inits[section].name)
-       elseif value == "0" and inits[section].enabled then
+e.write = function(self, section)
+       if inits[section].enabled then
                inits[section].enabled = false
                return luci.sys.init.disable(inits[section].name)
+       else
+               inits[section].enabled = true
+               return luci.sys.init.enable(inits[section].name)
        end
-       return true
 end
 
+
+start = s:option(Button, "start", translate("initmgr_start",  "Start"))
+start.inputstyle = "apply"
+start.write = function(self, section)
+       luci.sys.call("/etc/init.d/%s %s" %{ inits[section].name, self.option })
+end
+
+restart = s:option(Button, "restart", translate("initmgr_restart", "Restart"))
+restart.inputstyle = "reload"
+restart.write = start.write
+
+stop = s:option(Button, "stop", translate("initmgr_stop",   "Stop"))
+stop.inputstyle = "remove"
+stop.write = start.write
+
+
 return m
+