all: change most translate statements to new format, some need manual cleanup
[project/luci.git] / applications / luci-initmgr / luasrc / model / cbi / init / init.lua
1 --[[
2 LuCI - Lua Configuration Interface
3
4 Copyright 2008 Steven Barth <steven@midlink.org>
5 Copyright 2008 Jo-Philipp Wich <xm@leipzig.freifunk.net>
6
7 Licensed under the Apache License, Version 2.0 (the "License");
8 you may not use this file except in compliance with the License.
9 You may obtain a copy of the License at
10
11         http://www.apache.org/licenses/LICENSE-2.0
12
13 $Id$
14 ]]--
15
16 require("luci.sys")
17 require("luci.util")
18
19 local inits = { }
20
21 for _, name in ipairs(luci.sys.init.names()) do
22         local index   = luci.sys.init.index(name)
23         local enabled = luci.sys.init.enabled(name)
24
25         inits["%02i.%s" % { index, name }] = {
26                 name    = name,
27                 index   = tostring(index),
28                 enabled = enabled
29         }
30 end
31
32
33 m = SimpleForm("initmgr", translate("Initscripts"), translate("You can enable or disable installed init scripts here. Changes will applied after a device reboot.<br /><strong>Warning: If you disable essential init scripts like \"network\", your device might become inaccesable!</strong>"))
34 m.reset = false
35
36 s = m:section(Table, inits)
37
38 i = s:option(DummyValue, "index", translate("Start priority"))
39 n = s:option(DummyValue, "name", translate("Initscript"))
40
41 e = s:option(Flag, "enabled", translate("initmgr_enabled"))
42
43 e.cfgvalue = function(self, section)
44         return inits[section].enabled and "1" or "0"
45 end
46
47 e.write = function(self, section, value)
48         if value == "1" and not inits[section].enabled then
49                 inits[section].enabled = true
50                 return luci.sys.init.enable(inits[section].name)
51         elseif value == "0" and inits[section].enabled then
52                 inits[section].enabled = false
53                 return luci.sys.init.disable(inits[section].name)
54         end
55         return true
56 end
57
58 return m