summaryrefslogtreecommitdiffhomepage
path: root/libs/web/luasrc
diff options
context:
space:
mode:
authorJo-Philipp Wich <jow@openwrt.org>2011-10-25 22:48:43 +0000
committerJo-Philipp Wich <jow@openwrt.org>2011-10-25 22:48:43 +0000
commit6021cf3bdffaff58636e181fccf2343b0cf6a790 (patch)
tree9e56e5189ef02a6da0a1554ac8f7c9803bfb773f /libs/web/luasrc
parentd033763924518a5c33a71b003a6aa5d3201ea3ea (diff)
libs/web: dispatcher: implement a "firstchild()" target which simply redirects to the first child of a node, useful for menus that are empty by default and may gain arbritary childs
Diffstat (limited to 'libs/web/luasrc')
-rw-r--r--libs/web/luasrc/dispatcher.lua29
1 files changed, 29 insertions, 0 deletions
diff --git a/libs/web/luasrc/dispatcher.lua b/libs/web/luasrc/dispatcher.lua
index 9bfa413cf8..5f893dad95 100644
--- a/libs/web/luasrc/dispatcher.lua
+++ b/libs/web/luasrc/dispatcher.lua
@@ -638,6 +638,35 @@ end
-- Subdispatchers --
+function _firstchild()
+ local path = { unpack(context.path) }
+ local name = table.concat(path, ".")
+ local node = context.treecache[name]
+
+ local lowest
+ if node and node.nodes and next(node.nodes) then
+ local k, v
+ for k, v in pairs(node.nodes) do
+ if not lowest or
+ (v.order or 100) < (node.nodes[lowest].order or 100)
+ then
+ lowest = k
+ end
+ end
+ end
+
+ assert(lowest ~= nil,
+ "The requested node contains no childs, unable to redispatch")
+
+ path[#path+1] = lowest
+ dispatch(path)
+end
+
+--- Alias the first (lowest order) page automatically
+function firstchild()
+ return { type = "firstchild", target = _firstchild }
+end
+
--- Create a redirect to another dispatching node.
-- @param ... Virtual path destination
function alias(...)