c10dea9dd5ab89b8520000f0d23044f76d9dc6d6
[oweals/luci.git] / themes / luci-theme-rosy / luasrc / view / themes / rosy / header.htm
1 <%#
2     Rosy is a theme for LuCI. It is based on luci-theme-bootstrap
3     luci-theme-rosy
4         Copyright 2018 Rosy Song <rosysong@rosinson.com>
5         Copyright 2018 Yan Lan Shen <yanlan.shen@rosinson.com>
6     
7     Have a bug? Please create an issue here on GitHub!
8         https://github.com/rosywrt/luci-theme-rosy/issues
9
10     luci-theme-bootstrap:
11         Copyright 2008 Steven Barth <steven@midlink.org>
12         Copyright 2008 Jo-Philipp Wich <jow@openwrt.org>
13         Copyright 2012 David Menting <david@nut-bolt.nl>
14
15     Licensed to the public under the Apache License 2.0
16
17 -%>
18
19 <%
20         local sys  = require "luci.sys"
21         local util = require "luci.util"
22         local http = require "luci.http"
23         local disp = require "luci.dispatcher"
24
25         local boardinfo = util.ubus("system", "board")
26
27         local request  = disp.context.path
28         local request2 = disp.context.request
29
30         local category = request[1]
31         local cattree  = category and disp.node(category)
32
33         local leaf = request2[#request2]
34
35         local tree = disp.node()
36         local node = disp.context.dispatched
37
38         local categories = disp.node_childs(tree)
39
40         local c = tree
41         local i, r
42
43         -- tag all nodes leading to this page
44         for i, r in ipairs(request) do
45                 if c.nodes and c.nodes[r] then
46                         c = c.nodes[r]
47                         c._menu_selected = true
48                 end
49         end
50
51         -- send as HTML5
52         http.prepare_content("text/html")
53
54         local function nodeurl(prefix, name, query)
55                 local u = url(prefix, name)
56                 if query then
57                         u = u .. http.build_querystring(query)
58                 end
59                 return pcdata(u)
60         end
61
62         local function render_tabmenu(prefix, node, level)
63                 if not level then
64                         level = 1
65                 end
66
67                 local childs = disp.node_childs(node)
68                 if #childs > 0 then
69                         if level > 2 then
70                                 write('<ul class="tabs">')
71                         end
72
73                         local selected_node
74                         local selected_name
75                         local i, v
76
77                         for i, v in ipairs(childs) do
78                                 local nnode = node.nodes[v]
79                                 if nnode._menu_selected then
80                                         selected_node = nnode
81                                         selected_name = v
82                                 end
83
84                                 if level > 2 then
85                                         write('<li class="tabmenu-item-%s %s"><a href="%s">%s</a></li>' %{
86                                                 v, (nnode._menu_selected or (node.leaf and v == leaf)) and 'active' or '',
87                                                 nodeurl(prefix, v, nnode.query),
88                                                 striptags(translate(nnode.title))
89                                         })
90                                 end
91                         end
92
93                         if level > 2 then
94                                 write('</ul>')
95                         end
96
97                         if selected_node then
98                                 render_tabmenu(prefix .. "/" .. selected_name, selected_node, level + 1)
99                         end
100                 end
101         end
102
103         local function render_submenu(prefix, node)
104                 local childs = disp.node_childs(node)
105                 if #childs > 0 then
106                         write('<ul class="slide-menu">')
107
108                         for i, r in ipairs(childs) do
109                                 local nnode = node.nodes[r]
110                                 local title = pcdata(striptags(translate(nnode.title)))
111
112                                 write('<li><a data-title="%s" href="%s">%s</a></li>' %{
113                                         title,
114                                         nodeurl(prefix, r, nnode.query),
115                                         title
116                                 })
117                         end
118
119                         write('</ul>')
120                 end
121         end
122
123         local function render_topmenu()
124                 local childs = disp.node_childs(cattree)
125                 if #childs > 0 then
126                         write('<ul class="nav scroll">')
127
128                         for i, r in ipairs(childs) do
129                                 local nnode = cattree.nodes[r]
130                                 local grandchildren = disp.node_childs(nnode)
131
132                                 if #grandchildren > 0 then
133                                         local title = pcdata(striptags(translate(nnode.title)))
134
135                                         write('<li class="slide"><a class="menu" data-title="%s" href="#">%s</a>' %{
136                                                 title,
137                                                 title
138                                         })
139
140                                         render_submenu(category .. "/" .. r, nnode)
141                                         write('</li>')
142                                 end
143                         end
144
145                         write('</ul>')
146                 end
147         end
148
149         local function render_logout()                                                                             
150                 local childs = disp.node_childs(cattree)                               
151                 if #childs > 0 then                                                                                 
152                                                                                                
153                         for i, r in ipairs(childs) do                                     
154                                 local nnode = cattree.nodes[r]                                                      
155                                 local grandchildren = disp.node_childs(nnode)          
156                                                                                                                     
157                                 if #grandchildren <= 0 then
158                                         local title = pcdata(striptags(translate(nnode.title)))                      
159                                                                                           
160                                         write('<span class="label logout"><a data-title="%s" href="%s">%s</a></span>' %{                      
161                                                 title,                                    
162                                                 nodeurl(category, r, nnode.query),                                   
163                                                 title                              
164                                         })                                                                           
165                                 end                                                       
166                         end                                                                                          
167                                                                                           
168                 end                                                      
169         end                                                                                                          
170
171
172         local function render_changes()
173                 -- calculate the number of unsaved changes
174                 if tree.nodes[category] and tree.nodes[category].ucidata then
175                         local ucichanges = 0
176
177                         for i, j in pairs(require("luci.model.uci").cursor():changes()) do
178                                 for k, l in pairs(j) do
179                                         for m, n in pairs(l) do
180                                                 ucichanges = ucichanges + 1;
181                                         end
182                                 end
183                         end
184
185                         if ucichanges > 0 then
186                                 write('<a class="uci_change_indicator label notice" href="%s?redir=%s"><span class="mobile-hide">%s:</span> %d</a>' %{
187                                         url(category, 'uci/changes'),
188                                         http.urlencode(http.formvalue('redir') or table.concat(disp.context.request, "/")),
189                                         translate('Unsaved Changes'),
190                                         ucichanges
191                                 })
192                         end
193                 end
194         end
195
196         local function auth_level()
197                 local childs = disp.node_childs(cattree)                               
198                 if #childs > 0 then
199                         for i, r in ipairs(childs) do                                                                     
200                                 local nnode = cattree.nodes[r]                  
201                                 local grandchildren = disp.node_childs(nnode)          
202                                                      
203                                 if #grandchildren > 0 then
204                                         -- If this value is returned, the current interface is the logged-in data output interface
205                                         return "auth"
206                                 else
207                                         -- If this value is returned, it indicates that the current interface is a data output interface that does not require login.
208                                         return "noauth"
209                                 end                                       
210                         end                                     
211                 end
212                 -- If this value is returned, the current interface is the login interface
213                 return "login"
214         end
215 -%>
216 <!DOCTYPE html>
217 <html lang="<%=luci.i18n.context.lang%>">
218
219 <head>
220         <meta charset="utf-8">
221         <title>
222                 <%=striptags( (boardinfo.hostname or "?") .. ( (node and node.title) and ' - ' .. translate(node.title) or '')) %> -
223                 LuCI</title>
224         <meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" name="viewport" />
225         <meta name="format-detection" content="telephone=no, email=no" />
226         <meta name="apple-mobile-web-app-capable" content="yes">
227         <meta name="mobile-web-app-capable" content="yes">
228         <meta name="x5-fullscreen" content="true">
229         <meta name="full-screen" content="yes">
230         <meta name="x5-page-mode" content="app">
231         <meta name="browsermode" content="application">
232         <meta name="theme-color" content="#0099CC">
233         <meta name="msapplication-tap-highlight" content="no">
234         <meta name="msapplication-TileColor" content="#0099CC">
235
236         <meta name="application-name" content="<%=striptags( (boardinfo.hostname or " ?") ) %> - LuCI">
237         <meta name="apple-mobile-web-app-title" content="<%=striptags( (boardinfo.hostname or " ?") ) %> - LuCI">
238         <meta name="msapplication-TileImage" content="<%=media%>/logo.png" />
239         <link rel="icon" href="<%=media%>/logo.png" sizes="144x144">
240         <link rel="apple-touch-icon-precomposed" href="<%=media%>/logo.png" sizes="144x144">
241
242         <link rel="stylesheet" href="<%=media%>/cascade.css">
243         <link rel="shortcut icon" href="<%=media%>/favicon.ico">
244         <% if node and node.css then %>
245         <link rel="stylesheet" href="<%=resource%>/<%=node.css%>">
246         <% end -%>
247         <% if css then %>
248         <style title="text/css">
249                 <%=css %>
250         </style>
251         <% end -%>
252         <script src="<%=resource%>/cbi.js"></script>
253         <script src="<%=resource%>/xhr.js"></script>
254         <script src="<%=media%>/js/ScrollY.js"></script>
255 </head>
256
257 <body class="lang_<%=luci.i18n.context.lang%> <%- if node then %><%= striptags( node.title ) %><%- end %> <%- if auth_level() == "auth" then %> logged-in<%- end %> <%- if auth_level() == "noauth" then %> login-info<%- end %> <%- if auth_level() == "login" then %> login<%- end %>">
258         <header>
259                 <div class="container">
260                         <span class="showSide"></span>
261                         <a class="brand PC-hide" href="#"><%=boardinfo.hostname or "?"%></a>
262                         <div class="btn-con pull-right">
263                                 <% render_changes() %>
264                                 <span id="xhr_poll_status" style="display:none" onclick="XHR.running() ? XHR.halt() : XHR.run()">
265                                         <span class="label success" id="xhr_poll_status_on"><span class="mobile-hide">
266                                                         <%:Auto Refresh%></span>
267                                                 <%:on%></span>
268                                         <span class="label" id="xhr_poll_status_off" style="display:none"><span class="mobile-hide">
269                                                         <%:Auto Refresh%></span>
270                                                 <%:off%></span>
271                                 </span>
272                                 <% render_logout() %>
273                         </div>
274                 </div>
275         </header>
276         <div style="" class="loading">
277                 <span>                                                                                                                                                 
278                         <div class="loading-img">                                                                           
279                                 <img src="<%=media%>/loading.svg">                                                          
280                         </div>Loading...                                                                    
281                 </span>
282         </div>
283         <div class="main">
284                 <div class="main-left">
285                         <div class="nav-container">
286                                 <a class="brand" href="#">
287                                         <%=boardinfo.hostname or "?"%></a>
288                                 <div class="navbar-container" id="navBox">
289                                         <% render_topmenu() %>
290                                 </div>
291                         </div>
292                 </div>
293                 <div class="main-right">
294                         <div id="maincontent">
295                                 <div class="logoImg">                                                       
296                                         <img class="mobile-hide" src="<%=media%>/logo.png" alt="Rosy">                                                                 
297                                         <img src="<%=media%>/mobile-loginBG.png" class="PC-hide">
298                                         <a class="brand" href="#"><%=boardinfo.hostname or "?"%></a>                             
299                                 </div>
300                                 <div class="container">
301                                         <%- if luci.sys.process.info("uid") == 0 and luci.sys.user.getuser("root") and not luci.sys.user.getpasswd("root") then -%>
302                                         <div class="alert-message warning">
303                                                 <h4>
304                                                         <%:No password set!%>
305                                                 </h4>
306                                                 <p>
307                                                         <%:There is no password set on this router. Please configure a root password to protect the web interface and enable SSH.%>
308                                                 </p>
309                                                 <div><a class="btn" href="<%=url("admin/system/admin")%>"> <%:Go to password configuration...%></a></div>
310                                         </div>
311                                         <%- end -%>
312
313                                         <noscript>
314                                                 <div class="alert-message warning">
315                                                         <h4>
316                                                                 <%:JavaScript required!%>
317                                                         </h4>
318                                                         <p>
319                                                                 <%:You must enable JavaScript in your browser or LuCI will not work properly.%>
320                                                         </p>
321                                                 </div>
322                                         </noscript>
323
324                                         <% if category then render_tabmenu(category, cattree) end %>