applications, modules: remove i18n handling from controller modules as it moved to...
[project/luci.git] / modules / admin-full / luasrc / controller / admin / uci.lua
1 --[[
2 LuCI - Lua Configuration Interface
3
4 Copyright 2008 Steven Barth <steven@midlink.org>
5 Copyright 2010 Jo-Philipp Wich <xm@subsignal.org>
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 module("luci.controller.admin.uci", package.seeall)
17
18 function index()
19 local redir = luci.http.formvalue("redir", true) or
20 luci.dispatcher.build_url(unpack(luci.dispatcher.context.request))
21
22 entry({"admin", "uci"}, nil, _("Configuration"))
23 entry({"admin", "uci", "changes"}, call("action_changes"), _("Changes"), 40).query = {redir=redir}
24 entry({"admin", "uci", "revert"}, call("action_revert"), _("Revert"), 30).query = {redir=redir}
25 entry({"admin", "uci", "apply"}, call("action_apply"), _("Apply"), 20).query = {redir=redir}
26 entry({"admin", "uci", "saveapply"}, call("action_apply"), _("Save &#38; Apply"), 10).query = {redir=redir}
27 end
28
29 function action_changes()
30 local uci = luci.model.uci.cursor()
31 local changes = uci:changes()
32
33 luci.template.render("admin_uci/changes", {
34 changes = next(changes) and changes
35 })
36 end
37
38 function action_apply()
39 local path = luci.dispatcher.context.path
40 local uci = luci.model.uci.cursor()
41 local changes = uci:changes()
42 local reload = {}
43
44 -- Collect files to be applied and commit changes
45 for r, tbl in pairs(changes) do
46 table.insert(reload, r)
47 if path[#path] ~= "apply" then
48 uci:load(r)
49 uci:commit(r)
50 uci:unload(r)
51 end
52 end
53
54 luci.template.render("admin_uci/apply", {
55 changes = next(changes) and changes,
56 configs = reload
57 })
58 end
59
60
61 function action_revert()
62 local uci = luci.model.uci.cursor()
63 local changes = uci:changes()
64
65 -- Collect files to be reverted
66 for r, tbl in pairs(changes) do
67 uci:load(r)
68 uci:revert(r)
69 uci:unload(r)
70 end
71
72 luci.template.render("admin_uci/revert", {
73 changes = next(changes) and changes
74 })
75 end