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,16 +11,26 @@ 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 hostname = sys.hostname()
local load1, load5, load15 = sys.loadavg()
local request = disp.context.path
local category = request[1] local category = request[1]
local tree = luci.dispatcher.node() local cattree = category and disp.node(category)
local cattree = category and luci.dispatcher.node(category)
local node = luci.dispatcher.context.dispatched local tree = disp.node()
local hostname = luci.sys.hostname() local node = disp.context.dispatched
local categories = disp.node_childs(tree)
local c = tree local c = tree
local i, r
-- tag all nodes leading to this page
for i, r in ipairs(request) do for i, r in ipairs(request) do
if c.nodes and c.nodes[r] then if c.nodes and c.nodes[r] then
c = c.nodes[r] c = c.nodes[r]
@ -28,9 +38,7 @@ for i,r in ipairs(request) do
end end
end end
require("luci.i18n").loadc("base") http.prepare_content("text/html")
require("luci.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,14 +98,18 @@ 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 c = tree
local url = controller local url = controller
for k,v in pairs(request) do for i, r in ipairs(request) do
if c.nodes and c.nodes[v] then if c.nodes and c.nodes[r] then
c = c.nodes[v] c = c.nodes[r]
url = url .. "/" .. v url = url .. "/" .. r
%><a href="<%=url%>"><%=pcdata(striptags(translate(c.title) or v))%></a> <% if k ~= #request then %>&#187; <% end %>
<a href="<%=url%>"><%=pcdata(striptags(translate(c.title) or v))%></a>
<% if k ~= #request then %> &#187; <% end %>
<%
end end
end end
%> %>
@ -107,70 +119,58 @@ end
<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 = {}
local count = 0
for k, n in pairs(node.nodes) do
if n.title and n.target then
table.insert(index, {name=k, order=n.order or 100})
count = count + 1
end
end
table.sort(index, function(a, b) return a.order < b.order end)
if count > 0 then
%> %>
<ul> <ul>
<%- for j, v in pairs(index) do <%-
if not v.hidden and #v.name > 0 then for i, r in ipairs(childs) do
local nnode = node.nodes[v.name] local nnode = node.nodes[r]
local href = controller .. prefix .. v.name local href = controller .. prefix .. r ..
href = (nnode.query) and href .. luci.http.build_querystring(nnode.query) or href (nnode.query and http.build_querystring(nnode.query) or "")
%> %>
<li> <li>
<span<% if nnode._menu_selected then %> class="active"<%end%>><a href="<%=pcdata(href)%>"><%=pcdata(striptags(translate(nnode.title)))%></a></span> <span<%=ifattr(nnode._menu_selected, "class", "active")%>>
<%- submenu(prefix .. v.name .. "/", nnode) %> <a href="<%=pcdata(href)%>"><%=pcdata(striptags(translate(nnode.title)))%></a>
</span>
<%- submenu(prefix .. r .. "/", nnode) %>
</li> </li>
<%- end %> <%-
<%- end %> end
%>
</ul> </ul>
<%- <%-
end end
end end
if cattree and cattree.nodes then
local index = {}
for k, node in pairs(cattree.nodes) do
table.insert(index, {name=k, order=node.order or 100})
end
table.sort(index, function(a, b) return a.order < b.order end) childs = disp.node_childs(cattree)
for i, k in ipairs(index) do if #childs > 0 then
node = cattree.nodes[k.name] for i, r in ipairs(childs) do
if not node.hidden and node.title and node.target then local nnode = cattree.nodes[r]
local href = controller.."/"..category.."/"..k.name local href = controller .. "/" .. category .. "/" .. r ..
href = (k.query) and href .. luci.http.build_querystring(k.query) or href %> (nnode.query and http.build_querystring(k.query) or "")
<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<%=ifattr(nnode._menu_selected, "class", "preactive")%>>
<a href="<%=pcdata(href)%>"><%=pcdata(striptags(translate(nnode.title)))%></a>
<%- submenu("/" .. category .. "/" .. r .. "/", nnode) %>
</div> </div>
<% end <%
end 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