themes/openwrt: hide modemenu if there is only one entry
[project/luci.git] / themes / openwrt / luasrc / view / themes / openwrt.org / header.htm
1 <%#
2 LuCI - Lua Configuration Interface
3 Copyright 2008 Steven Barth <steven@midlink.org>
4 Copyright 2008-2010 Jo-Philipp Wich <xm@subsignal.org>
5
6 Licensed under the Apache License, Version 2.0 (the "License");
7 you may not use this file except in compliance with the License.
8 You may obtain a copy of the License at
9
10         http://www.apache.org/licenses/LICENSE-2.0
11
12 $Id$
13
14 -%>
15 <%
16 require("luci.sys")
17 local load1, load5, load15 = luci.sys.loadavg()
18 local request  = require("luci.dispatcher").context.path
19 local category = request[1]
20 local request2 = require("luci.dispatcher").context.request
21 local leaf     = request2[#request2]
22 local tree     = luci.dispatcher.node()
23 local cattree  = category and luci.dispatcher.node(category)
24 local node     = luci.dispatcher.context.dispatched
25 local hostname = luci.sys.hostname()
26
27 local c = tree
28 local i, r
29 for i,r in ipairs(request) do
30         if c.nodes and c.nodes[r] then
31                 c = c.nodes[r]
32                 c._menu_selected = true
33         end
34 end
35
36 local has_categories = 0
37 for i,r in pairs(tree.nodes) do
38         if r.title and not r.hidden then
39                 has_categories = has_categories + 1
40         end
41 end
42
43 require("luci.i18n").loadc("base")
44 require("luci.http").prepare_content("application/xhtml+xml")
45
46
47         local function nodeurl(prefix, name, query)
48                 local url = controller .. prefix .. name .. "/"
49                 if query then
50                         url = url .. luci.http.build_querystring(query)
51                 end
52                 return pcdata(url)
53         end
54
55         local function subtree(prefix, node, level)
56                 if not node.nodes or node.hidden then
57                         return false
58                 end
59
60                 if not level then
61                         level = 1
62                 end
63
64                 local index = {}
65                 local count = 0
66                 for k, n in pairs(node.nodes) do
67                         if n.title and n.target then
68                                 table.insert(index, {name=k, order=n.order or 100})
69                                 count = count + 1
70                         end
71                 end
72
73                 table.sort(index, function(a, b) return a.order < b.order end)
74
75                 if count > 0 then
76 %>
77         <div class="tabmenu<%=level%>">
78         <ul class="tabmenu l<%=level%>">
79                 <%
80                         local selected_node
81                         local selected_name
82
83                         for j, v in pairs(index) do
84                                 if #v.name > 0 then
85                                         local nnode = node.nodes[v.name]
86
87                                         if nnode._menu_selected then
88                                                 selected_node = nnode
89                                                 selected_name = v.name
90                                         end
91                 %>
92                         <li class="tabmenu-item-<%=v.name%><% if nnode._menu_selected or (node.leaf and v.name == leaf) then %> active<% end %>">
93                                 <a href="<%=nodeurl(prefix, v.name, nnode.query)%>"><%=striptags(translate(nnode.title))%></a>
94                         </li>
95                 <%
96                                 end
97                         end
98                 %>
99         </ul>
100         <br style="clear:both" />
101 <%
102                         if selected_node then
103                                 subtree(prefix .. selected_name .. "/", selected_node, level + 1)
104                         end
105 %>
106         </div>
107 <%
108                 end
109         end
110
111
112 -%>
113
114 <?xml version="1.0" encoding="utf-8"?>
115 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
116 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="<%=luci.i18n.context.lang%>" lang="<%=luci.i18n.context.lang%>">
117 <head>
118 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
119 <meta http-equiv="Content-Script-Type" content="text/javascript" />
120 <link rel="stylesheet" type="text/css" media="screen" href="<%=media%>/cascade.css" />
121 <!--[if IE 6]><link rel="stylesheet" type="text/css" media="screen" href="<%=media%>/ie6.css" /><![endif]-->
122 <!--[if IE 7]><link rel="stylesheet" type="text/css" media="screen" href="<%=media%>/ie7.css" /><![endif]-->
123 <!--[if IE 8]><link rel="stylesheet" type="text/css" media="screen" href="<%=media%>/ie8.css" /><![endif]-->
124 <% if node and node.css then %><link rel="stylesheet" type="text/css" media="screen" href="<%=resource%>/<%=node.css%>" />
125 <% end -%>
126 <script type="text/javascript" src="<%=resource%>/xhr.js"></script>
127 <title><%=striptags( hostname .. ( (node and node.title) and ' - ' .. translate(node.title) or '')) %> - LuCI</title>
128 </head>
129 <body class="lang_<%=luci.i18n.context.lang%>">
130
131 <p class="skiplink">
132 <span id="skiplink1"><a href="#navigation"><%:Skip to navigation%></a></span>
133 <span id="skiplink2"><a href="#content"><%:Skip to content%></a></span>
134 </p>
135
136 <div id="menubar">
137 <h2 class="navigation"><a id="navigation" name="navigation"><%:Navigation%></a></h2>
138
139 <div class="hostinfo">
140         <%=hostname%> | <%=luci.version.distversion%> |
141         <%:Load%>: <%="%.2f" % load1%> <%="%.2f" % load5%> <%="%.2f" % load15%>
142         <span id="xhr_poll_status" style="display:none" onclick="XHR.running() ? XHR.halt() : XHR.run()">
143                 | <%:Auto Refresh%>:
144                 <span id="xhr_poll_status_on"><%:on%></span>
145                 <span id="xhr_poll_status_off" style="display:none"><%:off%></span>
146         </span>
147 </div>
148
149 <% if has_categories > 1 then %>
150 <ul id="modemenu"><%
151 for k,node in pairs(tree.nodes) do
152         if node.title and not node.hidden then %>
153 <li><a<% if request[1] == k then %> class="active"<%end%> href="<%=controller%>/<%=k%>/"><%=striptags(translate(node.title))%></a></li><%
154         end
155 end
156 %>
157 </ul>
158 <% end %>
159
160 <%
161 if tree.nodes[category] and tree.nodes[category].ucidata then
162         local ucic = 0
163         for i, j in pairs(require("luci.model.uci").cursor():changes()) do
164                 for k, l in pairs(j) do
165                         for m, n in pairs(l) do
166                                 ucic = ucic + 1;
167                         end
168                 end
169         end
170 -%>
171 <div id="savemenu">
172         <% if ucic > 0 then %>
173                 <a class="warning" href="<%=controller%>/<%=category%>/uci/changes/?redir=<%=luci.http.urlencode(luci.http.formvalue("redir") or REQUEST_URI)%>"><%:Unsaved Changes%>: <%=ucic%></a>
174         <%- else -%>
175                 <a href="#"><%:Changes%>: 0</a>
176         <% end -%>
177 </div><% end %>
178
179 <div class="clear"></div>
180 </div>
181
182 <div id="maincontainer">
183         <div id="tabmenu">
184                 <% if category then subtree("/" .. category .. "/", cattree) end %>
185         </div>
186
187         <div id="maincontent">
188                 <noscript>
189                         <div class="errorbox">
190                                 <strong><%:Java Script required!%></strong><br />
191                                 <%:You must enable Java Script in your browser or LuCI will not work properly.%>
192                         </div>
193                 </noscript>
194
195                 <%- if luci.sys.user.getuser("root") and not luci.sys.user.getpasswd("root") then -%>
196                 <div class="errorbox">
197                         <strong><%:No password set!%></strong><br />
198                         <%:There is no password set on this router. Please configure a root password to protect the web interface and enable SSH.%>
199                 </div>
200                 <%- end -%>