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