c5186c40c5fd506b7dca2d28a351ff5958982072
[oweals/luci.git] / themes / luci-theme-openwrt / luasrc / view / themes / openwrt.org / header.htm
1 <%#
2  Copyright 2008 Steven Barth <steven@midlink.org>
3  Copyright 2008-2010 Jo-Philipp Wich <jow@openwrt.org>
4  Licensed to the public under the Apache License 2.0.
5 -%>
6
7 <%
8         local sys  = require "luci.sys"
9         local util = require "luci.util"
10         local http = require "luci.http"
11         local disp = require "luci.dispatcher"
12         local ver  = require "luci.version"
13
14         local sysinfo = util.ubus("system", "info") or { }
15         local loadinfo = sysinfo.load or { 0, 0, 0 }
16         local boardinfo = util.ubus("system", "board") or { }
17
18         local request  = disp.context.path
19         local request2 = disp.context.request
20
21         local category = request[1]
22         local cattree  = category and disp.node(category)
23
24         local leaf = request2[#request2]
25
26         local tree = disp.node()
27         local node = disp.context.dispatched
28
29         local categories = disp.node_childs(tree)
30
31         local c = tree
32         local i, r
33
34         -- tag all nodes leading to this page
35         for i, r in ipairs(request) do
36                 if c.nodes and c.nodes[r] then
37                         c = c.nodes[r]
38                         c._menu_selected = true
39                 end
40         end
41
42         http.prepare_content("application/xhtml+xml")
43
44         local function nodeurl(prefix, name, query)
45                 local u = url(prefix, name)
46                 if query then
47                         u = u .. http.build_querystring(query)
48                 end
49                 return pcdata(u)
50         end
51
52         local function render_menu(prefix, node, level)
53                 if not level then
54                         level = 1
55                 end
56
57                 local childs = disp.node_childs(node)
58                 if #childs > 0 then
59                         write('<ul class="mainmenu l%d">' % level)
60
61                         local i, v
62                         for i, v in ipairs(childs) do
63                                 local nnode = node.nodes[v]
64
65                                 write('<li class="mainmenu-item-%s %s"><a href="%s">%s</a>' %{
66                                         v, (nnode._menu_selected or (node.leaf and v == leaf)) and 'selected' or '',
67                                         nodeurl(prefix, v, nnode.query),
68                                         striptags(translate(nnode.title))
69                                 })
70
71                                 if level < 2 then
72                                         render_menu(prefix .. "/" .. v, nnode, level + 1)
73                                 end
74
75                                 write('</li>')
76                         end
77
78                         write('</ul>')
79                 end
80         end
81
82         local function render_tabmenu(prefix, node, level)
83                 if not level then
84                         level = 1
85                 end
86
87                 local childs = disp.node_childs(node)
88                 if #childs > 0 then
89                         if level > 2 then
90                                 if level == 3 then
91                                         write('<div id="tabmenu">')
92                                 end
93                                 write('<ul class="cbi-tabmenu">')
94                         end
95
96                         local selected_node
97                         local selected_name
98                         local i, v
99
100                         for i, v in ipairs(childs) do
101                                 local nnode = node.nodes[v]
102                                 if nnode._menu_selected then
103                                         selected_node = nnode
104                                         selected_name = v
105                                 end
106
107                                 if level > 2 then
108                                         write('<li class="tabmenu-item-%s %s"><a href="%s">%s</a></li>' %{
109                                                 v, (nnode._menu_selected or (node.leaf and v == leaf)) and 'cbi-tab' or '',
110                                                 nodeurl(prefix, v, nnode.query),
111                                                 striptags(translate(nnode.title))
112                                         })
113                                 end
114                         end
115
116                         if level > 2 then
117                                 write('</ul>')
118                                 if level == 3 then
119                                         write('</div>')
120                                 end
121                         end
122
123                         if selected_node then
124                                 render_tabmenu(prefix .. "/" .. selected_name, selected_node, level + 1)
125                         end
126                 end
127         end
128
129         local function render_changes()
130                 if tree.nodes[category] and tree.nodes[category].ucidata then
131                         local ucic = 0
132                         local i, j
133                         for i, j in pairs(require("luci.model.uci").cursor():changes()) do
134                                 ucic = ucic + #j
135                         end
136
137                         if ucic > 0 then
138                                 write('<div id="savemenu" class="uci_change_indicator"><a class="warning" href="%s?redir=%s">%s: %d</a></div>' %{
139                                         url(category, 'uci/changes'),
140                                         http.urlencode(http.formvalue('redir') or table.concat(disp.context.request, "/")),
141                                         translate('Unsaved Changes'),
142                                         ucic
143                                 })
144                         end
145                 end
146         end
147 -%>
148
149 <?xml version="1.0" encoding="utf-8"?>
150 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
151 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="<%=luci.i18n.context.lang%>" lang="<%=luci.i18n.context.lang%>">
152 <head>
153 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
154 <meta name="viewport" content="width=device-width, initial-scale=1" />
155 <meta http-equiv="Content-Script-Type" content="text/javascript" />
156 <link rel="stylesheet" type="text/css" media="screen" href="<%=media%>/cascade.css" />
157 <% if node and node.css then %><link rel="stylesheet" type="text/css" media="screen" href="<%=resource%>/<%=node.css%>" />
158 <% end -%>
159 <% if css then %><style title="text/css">
160 <%= css %>
161 </style>
162 <% end -%>
163 <script type="text/javascript" src="<%=url('admin/translations', luci.i18n.context.lang)%><%# ?v=PKG_VERSION %>"></script>
164 <script type="text/javascript" src="<%=resource%>/cbi.js"></script>
165 <script type="text/javascript" src="<%=resource%>/xhr.js"></script>
166 <script type="text/javascript">//<![CDATA[
167         document.addEventListener('DOMContentLoaded', function() {
168                 var event = ('ontouchstart' in window) ? 'touchstart' : 'click';
169
170                 document.querySelectorAll('ul.mainmenu.l1 > li > a').forEach(function(a) {
171                         a.addEventListener(event, function(ev) {
172                                 var a = ev.target, ul1 = a.parentNode.parentNode, ul2 = a.nextElementSibling;
173
174                                 document.querySelectorAll('ul.mainmenu.l1 > li.active').forEach(function(li) {
175                                         if (li !== a.parentNode)
176                                                 li.classList.remove('active');
177                                 });
178
179                                 if (!ul2)
180                                         return;
181
182                                 if (ul2.parentNode.offsetLeft + ul2.offsetWidth <= ul1.offsetLeft + ul1.offsetWidth)
183                                         ul2.classList.add('align-left');
184
185                                 ul1.classList.add('active');
186                                 a.parentNode.classList.add('active');
187                                 a.blur();
188
189                                 ev.preventDefault();
190                                 ev.stopPropagation();
191                         });
192                 });
193
194                 document.addEventListener(event, function(ev) {
195                         var t = ev.target;
196
197                         while (t && t.id != 'mainmenu')
198                                 t = t.parentNode;
199
200                         if (!t)
201                                 document.querySelectorAll('ul.mainmenu > li.active').forEach(function(li) {
202                                         li.classList.remove('active');
203                                 });
204                 });
205         });
206 //]]></script>
207 <title><%=striptags( (boardinfo.hostname or "?") .. ( (node and node.title) and ' - ' .. translate(node.title) or '')) %> - LuCI</title>
208 </head>
209 <body class="lang_<%=luci.i18n.context.lang%>" data-page="<%= table.concat(disp.context.requestpath, "-") %>">
210
211 <p class="skiplink">
212 <span id="skiplink1"><a href="#navigation"><%:Skip to navigation%></a></span>
213 <span id="skiplink2"><a href="#content"><%:Skip to content%></a></span>
214 </p>
215
216 <div id="menubar">
217 <h2 class="navigation"><a id="navigation" name="navigation"><%:Navigation%></a></h2>
218
219 <div class="hostinfo">
220         <%=(boardinfo.hostname or "?")%> | <%=ver.distversion%> |
221         <%:Load%>: <%="%.2f" % (loadinfo[1] / 65535.0)%> <%="%.2f" % (loadinfo[2] / 65535.0)%> <%="%.2f" % (loadinfo[3] / 65535.0)%>
222         <span id="xhr_poll_status" style="display:none" onclick="XHR.running() ? XHR.halt() : XHR.run()">
223                 | <%:Auto Refresh%>:
224                 <span id="xhr_poll_status_on"><%:on%></span>
225                 <span id="xhr_poll_status_off" style="display:none"><%:off%></span>
226         </span>
227 </div>
228
229 <% if #categories > 1 then %>
230         <ul id="modemenu">
231                 <% for i, r in ipairs(categories) do %>
232                         <li><a<% if request[1] == r then %> class="active"<%end%> href="<%=controller%>/<%=r%>/"><%=striptags(translate(tree.nodes[r].title))%></a></li>
233                 <% end %>
234         </ul>
235 <% end %>
236
237 <% render_changes() %>
238
239 <div class="clear"></div>
240 </div>
241
242 <div id="maincontainer">
243         <div id="mainmenu">
244                 <% if category then render_menu(category, cattree) end %>
245         </div>
246
247         <div id="maincontent">
248                 <% if category then render_tabmenu(category, cattree) end %>
249
250                 <noscript>
251                         <div class="alert-message warning">
252                                 <h4><%:JavaScript required!%></h4>
253                                 <p><%:You must enable JavaScript in your browser or LuCI will not work properly.%></p>
254                         </div>
255                 </noscript>
256
257                 <%- if luci.sys.process.info("uid") == 0 and luci.sys.user.getuser("root") and not luci.sys.user.getpasswd("root") and category ~= "failsafe" then -%>
258                 <div class="alert-message warning">
259                         <h4><%:No password set!%></h4>
260                         <p><%:There is no password set on this router. Please configure a root password to protect the web interface and enable SSH.%></p>
261                         <% if disp.lookup("admin/system/admin") then %>
262                                 <div class="right"><a class="btn" href="<%=url("admin/system/admin")%>"><%:Go to password configuration...%></a></div>
263                         <% end %>
264                 </div>
265                 <%- end -%>