themes/freifunk: port to updated dispatcher api

This commit is contained in:
Jo-Philipp Wich 2011-10-26 02:51:34 +00:00
parent e12b8dbc1f
commit 7918c83586

View file

@ -11,26 +11,34 @@ You may obtain a copy of the License at
-%> -%>
<% <%
require("luci.sys") local sys = require "luci.sys"
local load1, load5, load15 = luci.sys.loadavg() local http = require "luci.http"
local request = require("luci.dispatcher").context.path local disp = require "luci.dispatcher"
local category = request[1]
local tree = luci.dispatcher.node()
local cattree = category and luci.dispatcher.node(category)
local node = luci.dispatcher.context.dispatched
local hostname = luci.sys.hostname()
local c = tree local hostname = sys.hostname()
for i,r in ipairs(request) do local load1, load5, load15 = sys.loadavg()
if c.nodes and c.nodes[r] then
c = c.nodes[r] local request = disp.context.path
c._menu_selected = true local category = request[1]
local cattree = category and disp.node(category)
local tree = disp.node()
local node = disp.context.dispatched
local categories = disp.node_childs(tree)
local c = tree
local i, r
-- tag all nodes leading to this page
for i, r in ipairs(request) do
if c.nodes and c.nodes[r] then
c = c.nodes[r]
c._menu_selected = true
end
end end
end
require("luci.i18n").loadc("base")
require("luci.http").prepare_content("text/html")
http.prepare_content("text/html")
-%> -%>
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
@ -62,7 +70,7 @@ require("luci.http").prepare_content("text/html")
</script> </script>
<![endif]--> <![endif]-->
</head> </head>
<body onload="window.setup_hover && setup_hover()"> <body onload="if (window.setup_hover) setup_hover()">
<div id="all"> <div id="all">
<center> <center>
@ -90,87 +98,79 @@ require("luci.http").prepare_content("text/html")
</div> </div>
<div class="pathbar separator black whitetext bold"> <div class="pathbar separator black whitetext bold">
<%:Path%>: <% <%:Path%>:
local c = tree <%
local url = controller local c = tree
for k,v in pairs(request) do local url = controller
if c.nodes and c.nodes[v] then for i, r in ipairs(request) do
c = c.nodes[v] if c.nodes and c.nodes[r] then
url = url .. "/" .. v c = c.nodes[r]
%><a href="<%=url%>"><%=pcdata(striptags(translate(c.title) or v))%></a> <% if k ~= #request then %>&#187; <% end url = url .. "/" .. r
%>
<a href="<%=url%>"><%=pcdata(striptags(translate(c.title) or v))%></a>
<% if k ~= #request then %> &#187; <% end %>
<%
end
end end
end
%> %>
</div> </div>
<div class="menubar"> <div class="menubar">
<div id="mainmenu" class="mainmenu"> <div id="mainmenu" class="mainmenu">
<%- <%-
local function submenu(prefix, node) local function submenu(prefix, node)
if not node.nodes or node.hidden then local childs = disp.node_childs(node)
return false if #childs > 0 then
end %>
local index = {} <ul>
local count = 0 <%-
for k, n in pairs(node.nodes) do for i, r in ipairs(childs) do
if n.title and n.target then local nnode = node.nodes[r]
table.insert(index, {name=k, order=n.order or 100}) local href = controller .. prefix .. r ..
count = count + 1 (nnode.query and http.build_querystring(nnode.query) or "")
%>
<li>
<span<%=ifattr(nnode._menu_selected, "class", "active")%>>
<a href="<%=pcdata(href)%>"><%=pcdata(striptags(translate(nnode.title)))%></a>
</span>
<%- submenu(prefix .. r .. "/", nnode) %>
</li>
<%-
end
%>
</ul>
<%-
end
end end
end
table.sort(index, function(a, b) return a.order < b.order end)
if count > 0 then childs = disp.node_childs(cattree)
%>
<ul>
<%- for j, v in pairs(index) do
if not v.hidden and #v.name > 0 then
local nnode = node.nodes[v.name]
local href = controller .. prefix .. v.name
href = (nnode.query) and href .. luci.http.build_querystring(nnode.query) or href
%>
<li>
<span<% if nnode._menu_selected then %> class="active"<%end%>><a href="<%=pcdata(href)%>"><%=pcdata(striptags(translate(nnode.title)))%></a></span>
<%- submenu(prefix .. v.name .. "/", nnode) %>
</li>
<%- end %>
<%- end %>
</ul>
<%-
end
end
if cattree and cattree.nodes then if #childs > 0 then
local index = {} for i, r in ipairs(childs) do
for k, node in pairs(cattree.nodes) do local nnode = cattree.nodes[r]
table.insert(index, {name=k, order=node.order or 100}) local href = controller .. "/" .. category .. "/" .. r ..
end (nnode.query and http.build_querystring(k.query) or "")
%>
table.sort(index, function(a, b) return a.order < b.order end) <div<%=ifattr(nnode._menu_selected, "class", "preactive")%>>
<a href="<%=pcdata(href)%>"><%=pcdata(striptags(translate(nnode.title)))%></a>
for i, k in ipairs(index) do <%- submenu("/" .. category .. "/" .. r .. "/", nnode) %>
node = cattree.nodes[k.name] </div>
if not node.hidden and node.title and node.target then <%
local href = controller.."/"..category.."/"..k.name end
href = (k.query) and href .. luci.http.build_querystring(k.query) or href %> end
<div<% if node._menu_selected then %> class="preactive"<%end%>><a href="<%=pcdata(href)%>"><%=pcdata(striptags(translate(node.title)))%></a> %>
<%submenu("/" .. category .. "/" .. k.name .. "/", node)%>
</div>
<% end
end
end
%>
</div> </div>
<% if #categories > 1 then %>
<div class="modemenu"> <div class="modemenu">
<ul><% <ul>
for k,node in pairs(tree.nodes) do <% for i, r in ipairs(categories) do %>
if node.title and not node.hidden then %> <li><a<%=ifattr(request[1] == r, "class", "active")%> href="<%=controller%>/<%=r%>/"><%=striptags(translate(tree.nodes[r].title))%></a></li>
<li<% if request[1] == k then %> class="active"<%end%>><a href="<%=controller%>/<%=k%>"><%=pcdata(translate(node.title))%></a></li> <% end %>
<% end
end%>
</ul> </ul>
</div> </div>
<% end %>
<% <%
if tree.nodes[category] and tree.nodes[category].ucidata then if tree.nodes[category] and tree.nodes[category].ucidata then