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