themes: eliminate uses of luci.sys.loadavg()
[project/luci.git] / themes / luci-theme-bootstrap / luasrc / view / themes / bootstrap / header.htm
1 <%#
2 LuCI - Lua Configuration Interface
3 Copyright 2008 Steven Barth <steven@midlink.org>
4 Copyright 2008 Jo-Philipp Wich <xm@leipzig.freifunk.net>
5 Copyright 2012 David Menting <david@nut-bolt.nl>
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 -%>
14 <%
15 local sys = require "luci.sys"
16 local util = require "luci.util"
17 local http = require "luci.http"
18 local disp = require "luci.dispatcher"
19
20 local boardinfo = util.ubus("system", "board")
21
22 local request = disp.context.path
23 local request2 = disp.context.request
24
25 local category = request[1]
26 local cattree = category and disp.node(category)
27
28 local leaf = request2[#request2]
29
30 local tree = disp.node()
31 local node = disp.context.dispatched
32
33 local categories = disp.node_childs(tree)
34
35 local c = tree
36 local i, r
37
38 -- tag all nodes leading to this page
39 for i, r in ipairs(request) do
40 if c.nodes and c.nodes[r] then
41 c = c.nodes[r]
42 c._menu_selected = true
43 end
44 end
45
46 -- send as HTML5
47 http.prepare_content("text/html")
48
49 local function nodeurl(prefix, name, query)
50 local url = controller .. prefix .. name .. "/"
51 if query then
52 url = url .. http.build_querystring(query)
53 end
54 return pcdata(url)
55 end
56
57 local function subtree(prefix, node, level)
58 if not level then
59 level = 1
60 end
61
62 local childs = disp.node_childs(node)
63 if #childs > 0 then
64
65 if level > 2 then
66 %>
67 <ul class="tabs">
68 <%
69 end
70
71 local selected_node
72 local selected_name
73 local i, v
74
75 for i, v in ipairs(childs) do
76 local nnode = node.nodes[v]
77 if nnode._menu_selected then
78 selected_node = nnode
79 selected_name = v
80 end
81 if level > 2 then
82 %>
83 <li class="tabmenu-item-<%=v%><%- if nnode._menu_selected or (node.leaf and v == leaf) then %> active<% end %>">
84 <a href="<%=nodeurl(prefix, v, nnode.query)%>"><%=striptags(translate(nnode.title))%></a>
85 </li>
86 <% end
87 end
88
89 if level > 2 then
90 %>
91 </ul>
92 <% end
93
94 if selected_node then
95 subtree(prefix .. selected_name .. "/", selected_node, level + 1)
96 end
97 end
98 end
99 -%>
100 <!DOCTYPE html>
101 <html lang="<%=luci.i18n.context.lang%>">
102 <head>
103 <meta charset="utf-8">
104 <title><%=striptags( (boardinfo.hostname or "?") .. ( (node and node.title) and ' - ' .. translate(node.title) or '')) %> - LuCI</title>
105 <!--[if lt IE 9]><script src="<%=media%>/html5.js"></script><![endif]-->
106 <meta name="viewport" content="initial-scale=1.0">
107 <link rel="stylesheet" href="<%=media%>/cascade.css">
108 <link rel="stylesheet" media="only screen and (max-device-width: 854px)" href="<%=media%>/mobile.css" type="text/css" />
109 <link rel="shortcut icon" href="<%=media%>/favicon.ico">
110 <% if node and node.css then %><link rel="stylesheet" href="<%=resource%>/<%=node.css%>">
111 <% end -%>
112 <% if css then %><style title="text/css">
113 <%-= css %>
114 </style>
115 <% end -%>
116 <script src="<%=resource%>/xhr.js"></script>
117 </head>
118
119 <body class="lang_<%=luci.i18n.context.lang%> <%- if node then %><%= striptags( node.title ) %><%- end %>">
120 <header>
121 <div class="fill">
122 <div class="container">
123 <a class="brand" href="#"><%=boardinfo.hostname or "?"%></a>
124 <ul class="nav">
125 <%-
126 local function submenu(prefix, node)
127 local childs = disp.node_childs(node)
128 if #childs > 0 then
129 %>
130 <ul class="dropdown-menu">
131 <%-
132 for i, r in ipairs(childs) do
133 local nnode = node.nodes[r]
134 local href = controller .. prefix .. r ..
135 (nnode.query and http.build_querystring(nnode.query) or "")
136 %>
137 <li><a href="<%=pcdata(href)%>"><%=pcdata(striptags(translate(nnode.title)))%></a></li>
138 <%-
139 end
140 %>
141 </ul>
142 <%-
143 end
144 end
145
146 childs = disp.node_childs(cattree)
147
148 if #childs > 0 then
149 for i, r in ipairs(childs) do
150 local nnode = cattree.nodes[r]
151 local href = controller .. "/" .. category .. "/" .. r ..
152 (nnode.query and http.build_querystring(k.query) or "")
153 local grandchildren = disp.node_childs(nnode)
154
155 if #grandchildren > 0 then
156 %>
157 <li class="dropdown">
158 <a class="menu" href="#"><%=pcdata(striptags(translate(nnode.title)))%></a>
159 <%- submenu("/" .. category .. "/" .. r .. "/", nnode) %>
160 </li>
161 <% else %>
162 <li>
163 <a href="<%=pcdata(href)%>"><%=pcdata(striptags(translate(nnode.title)))%></a>
164 </li>
165 <%
166 end
167 end
168 end
169 %>
170 </ul>
171
172 <%
173 -- calculate the number of unsaved changes
174 if tree.nodes[category] and tree.nodes[category].ucidata then
175 local ucichanges = 0
176
177 for i, j in pairs(require("luci.model.uci").cursor():changes()) do
178 for k, l in pairs(j) do
179 for m, n in pairs(l) do
180 ucichanges = ucichanges + 1;
181 end
182 end
183 end
184 %>
185 <div class="pull-right">
186 <% if ucichanges > 0 then %>
187 <a class="label notice" href="<%=controller%>/<%=category%>/uci/changes"><%:Unsaved Changes%>: <%=ucichanges%></a>
188 <% end %>
189 <span id="xhr_poll_status" style="display:none" onclick="XHR.running() ? XHR.halt() : XHR.run()">
190 <span class="label success" id="xhr_poll_status_on"><%:Auto Refresh%> <%:on%></span>
191 <span class="label" id="xhr_poll_status_off" style="display:none"><%:Auto Refresh%> <%:off%></span>
192 </span>
193 </div>
194 <% end %>
195 </div>
196 </div>
197 </header>
198
199 <%- if luci.sys.process.info("uid") == 0 and luci.sys.user.getuser("root") and not luci.sys.user.getpasswd("root") then -%>
200 <div class="container">
201 <div class="alert-message warning">
202 <h4><%:No password set!%></h4>
203 <%:There is no password set on this router. Please configure a root password to protect the web interface and enable SSH.%><br>
204 <a href="<%=pcdata(luci.dispatcher.build_url("admin/system/admin"))%>"><%:Go to password configuration...%></a>
205 </div>
206 </div>
207 <%- end -%>
208
209 <div id="maincontent" class="container">
210 <% if category then subtree("/" .. category .. "/", cattree) end %>