Merge pull request #1154 from stangri/luci-app-simple-adblock
[project/luci.git] / themes / luci-theme-material / luasrc / view / themes / material / header.htm
1 <%#
2         Material is a clean HTML5 theme for LuCI. It is based on luci-theme-bootstrap and MUI
3
4         luci-theme-material
5         Copyright 2015-2017 Lutty Yang <lutty@wcan.in>
6
7         Have a bug? Please create an issue here on GitHub!
8         https://github.com/LuttyYang/luci-theme-material/issues
9
10         luci-theme-bootstrap:
11         Copyright 2008 Steven Barth <steven@midlink.org>
12         Copyright 2008-2016 Jo-Philipp Wich <jow@openwrt.org>
13         Copyright 2012 David Menting <david@nut-bolt.nl>
14
15         MUI:
16         https://github.com/muicss/mui
17
18         Licensed to the public under the Apache License 2.0
19 -%>
20
21 <%
22         local sys  = require "luci.sys"
23         local util = require "luci.util"
24         local http = require "luci.http"
25         local disp = require "luci.dispatcher"
26
27         local boardinfo = util.ubus("system", "board")
28
29         local request  = disp.context.path
30         local request2 = disp.context.request
31
32         local category = request[1]
33         local cattree  = category and disp.node(category)
34
35         local leaf = request2[#request2]
36
37         local tree = disp.node()
38         local node = disp.context.dispatched
39
40         local categories = disp.node_childs(tree)
41
42         local c = tree
43         local i, r
44
45         -- tag all nodes leading to this page
46         for i, r in ipairs(request) do
47                 if c.nodes and c.nodes[r] then
48                         c = c.nodes[r]
49                         c._menu_selected = true
50                 end
51         end
52
53         -- send as HTML5
54         http.prepare_content("text/html")
55
56         local function nodeurl(prefix, name, query)
57                 local u = url(prefix, name)
58                 if query then
59                         u = u .. http.build_querystring(query)
60                 end
61                 return pcdata(u)
62         end
63
64         local function render_tabmenu(prefix, node, level)
65                 if not level then
66                         level = 1
67                 end
68
69                 local childs = disp.node_childs(node)
70                 if #childs > 0 then
71                         if level > 2 then
72                                 write('<ul class="tabs">')
73                         end
74
75                         local selected_node
76                         local selected_name
77                         local i, v
78
79                         for i, v in ipairs(childs) do
80                                 local nnode = node.nodes[v]
81                                 if nnode._menu_selected then
82                                         selected_node = nnode
83                                         selected_name = v
84                                 end
85
86                                 if level > 2 then
87                                         write('<li class="tabmenu-item-%s %s"><a href="%s">%s</a></li>' %{
88                                                 v, (nnode._menu_selected or (node.leaf and v == leaf)) and 'active' or '',
89                                                 nodeurl(prefix, v, nnode.query),
90                                                 striptags(translate(nnode.title))
91                                         })
92                                 end
93                         end
94
95                         if level > 2 then
96                                 write('</ul>')
97                         end
98
99                         if selected_node then
100                                 render_tabmenu(prefix .. "/" .. selected_name, selected_node, level + 1)
101                         end
102                 end
103         end
104
105         local function render_submenu(prefix, node)
106                 local childs = disp.node_childs(node)
107                 if #childs > 0 then
108                         write('<ul class="slide-menu">')
109
110                         for i, r in ipairs(childs) do
111                                 local nnode = node.nodes[r]
112                                 local title = pcdata(striptags(translate(nnode.title)))
113
114                                 write('<li><a data-title="%s" href="%s">%s</a></li>' %{
115                                         title,
116                                         nodeurl(prefix, r, nnode.query),
117                                         title
118                                 })
119                         end
120
121                         write('</ul>')
122                 end
123         end
124
125         local function render_topmenu()
126                 local childs = disp.node_childs(cattree)
127                 if #childs > 0 then
128                         write('<ul class="nav">')
129
130                         for i, r in ipairs(childs) do
131                                 local nnode = cattree.nodes[r]
132                                 local grandchildren = disp.node_childs(nnode)
133
134                                 if #grandchildren > 0 then
135                                         local title = pcdata(striptags(translate(nnode.title)))
136
137                                         write('<li class="slide"><a class="menu" data-title="%s" href="#">%s</a>' %{
138                                                 title,
139                                                 title
140                                         })
141
142                                         render_submenu(category .. "/" .. r, nnode)
143                                         write('</li>')
144                                 else
145                                         local title = pcdata(striptags(translate(nnode.title)))
146
147                                         write('<li><a data-title="%s" href="%s">%s</a></li>' %{
148                                                 title,
149                                                 nodeurl(category, r, nnode.query),
150                                                 title
151                                         })
152                                 end
153                         end
154
155                         write('</ul>')
156                 end
157         end
158
159         local function render_changes()
160                 -- calculate the number of unsaved changes
161                 if tree.nodes[category] and tree.nodes[category].ucidata then
162                         local ucichanges = 0
163
164                         for i, j in pairs(require("luci.model.uci").cursor():changes()) do
165                                 for k, l in pairs(j) do
166                                         for m, n in pairs(l) do
167                                                 ucichanges = ucichanges + 1;
168                                         end
169                                 end
170                         end
171
172                         if ucichanges > 0 then
173                                 write('<a class="label notice" href="%s?redir=%s">%s: %d</a>' %{
174                                         url(category, 'uci/changes'),
175                                         http.urlencode(http.formvalue('redir') or REQUEST_URI),
176                                         translate('Unsaved Changes'),
177                                         ucichanges
178                                 })
179                         end
180                 end
181         end
182 -%>
183 <!DOCTYPE html>
184 <html lang="<%=luci.i18n.context.lang%>">
185 <head>
186     <meta charset="utf-8">
187     <title><%=striptags( (boardinfo.hostname or "?") .. ( (node and node.title) and ' - ' .. translate(node.title) or '')) %> - LuCI</title>
188     <meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" name="viewport"/>
189     <meta name="format-detection" content="telephone=no, email=no"/>
190     <meta name="apple-mobile-web-app-capable" content="yes">
191     <meta name="mobile-web-app-capable" content="yes">
192     <meta name="x5-fullscreen" content="true">
193     <meta name="full-screen" content="yes">
194     <meta name="x5-page-mode" content="app">
195     <meta name="browsermode" content="application">
196     <meta name="theme-color" content="#0099CC">
197     <meta name="msapplication-tap-highlight" content="no">
198     <meta name="msapplication-TileColor" content="#0099CC">
199
200     <meta name="application-name" content="<%=striptags( (boardinfo.hostname or "?") ) %> - LuCI">
201     <meta name="apple-mobile-web-app-title" content="<%=striptags( (boardinfo.hostname or "?") ) %> - LuCI">
202     <meta name="msapplication-TileImage" content="<%=media%>/logo.png"/>
203     <link rel="icon" href="<%=media%>/logo.png" sizes="144x144">
204     <link rel="apple-touch-icon-precomposed" href="<%=media%>/logo.png" sizes="144x144">
205
206     <link rel="stylesheet" href="<%=media%>/css/style.css">
207     <link rel="shortcut icon" href="<%=media%>/favicon.ico">
208     <% if node and node.css then %>
209         <link rel="stylesheet" href="<%=resource%>/<%=node.css%>">
210     <% end -%>
211     <% if css then %>
212         <style title="text/css"><%= css %></style>
213     <% end -%>
214     <script src="<%=resource%>/xhr.js"></script>
215 </head>
216 <body class="lang_<%=luci.i18n.context.lang%> <%- if node then %><%= striptags( node.title ) %><%- end %> <% if luci.dispatcher.context.authsession then %>logged-in<% end %>">
217 <header>
218         <div class="container">
219                 <span class="showSide"></span>
220                 <a class="brand" href="#"><%=boardinfo.hostname or "?"%></a>
221                 <div class="pull-right">
222                         <% render_changes() %>
223                         <span id="xhr_poll_status" style="display:none" onclick="XHR.running() ? XHR.halt() : XHR.run()">
224                                 <span class="label success" id="xhr_poll_status_on"><span class="mobile-hide"><%:Auto Refresh%></span> <%:on%></span>
225                                 <span class="label" id="xhr_poll_status_off" style="display:none"><span class="mobile-hide"><%:Auto Refresh%></span> <%:off%></span>
226                         </span>
227                 </div>
228         </div>
229 </header>
230 <div class="main">
231          <div style="" class="loading"><span><div class="loading-img"></div>Loading...</span></div>
232          <div class="main-left">
233                 <% render_topmenu() %>
234          </div>
235         <div class="main-right">
236                  <div class="darkMask"></div>
237                  <div id="maincontent">
238                          <div class="container">
239                                  <%- if luci.sys.process.info("uid") == 0 and luci.sys.user.getuser("root") and not luci.sys.user.getpasswd("root") then -%>
240                                          <div class="alert-message warning">
241                                                  <h4><%:No password set!%></h4>
242                                                  <%:There is no password set on this router. Please configure a root password to protect the web interface and enable SSH.%><br>
243                                                  <a href="<%=pcdata(luci.dispatcher.build_url("admin/system/admin"))%>"><%:Go to password configuration...%></a>
244                                          </div>
245                                  <%- end -%>
246                                  <% if category then render_tabmenu(category, cattree) end %>
247
248                                 <noscript>
249                                         <div class="alert-message warning">
250                                                 <strong><%:JavaScript required!%></strong><br />
251                                                 <%:You must enable JavaScript in your browser or LuCI will not work properly.%>
252                                         </div>
253                                 </noscript>