# HG changeset patch # User jbe # Date 1390139228 -3600 # Node ID ca88032cb37ca1230b702c307fc72e4bbf5f5008 # Parent 407633fd0e84cb6e330aed8946b764b5d2b28c80 Anchor (#) support for redirect and routing diff -r 407633fd0e84 -r ca88032cb37c framework/cgi-bin/webmcp.lua --- a/framework/cgi-bin/webmcp.lua Mon Jan 13 21:40:27 2014 +0100 +++ b/framework/cgi-bin/webmcp.lua Sun Jan 19 14:47:08 2014 +0100 @@ -319,11 +319,13 @@ routing_mode = cgi.params["_webmcp_routing." .. action_status .. ".mode"] routing_module = cgi.params["_webmcp_routing." .. action_status .. ".module"] routing_view = cgi.params["_webmcp_routing." .. action_status .. ".view"] + routing_anchor = cgi.params["_webmcp_routing." .. action_status .. ".anchor"] if not (routing_mode or routing_module or routing_view) then action_status = "default" routing_mode = cgi.params["_webmcp_routing.default.mode"] routing_module = cgi.params["_webmcp_routing.default.module"] routing_view = cgi.params["_webmcp_routing.default.view"] + routing_anchor = cgi.params["_webmcp_routing.default.anchor"] end assert(routing_module, "Routing information has no module.") assert(routing_view, "Routing information has no view.") @@ -341,7 +343,8 @@ module = routing_module, view = routing_view, id = cgi.params["_webmcp_routing." .. action_status .. ".id"], - params = routing_params + params = routing_params, + anchor = routing_anchor } elseif routing_mode == "forward" then request.forward{ module = routing_module, view = routing_view } @@ -452,7 +455,8 @@ module = redirect_data.module, view = redirect_data.view, id = redirect_data.id, - params = redirect_params + params = redirect_params, + anchor = redirect_data.anchor } ) cgi.send_data() diff -r 407633fd0e84 -r ca88032cb37c framework/env/request/redirect.lua --- a/framework/env/request/redirect.lua Mon Jan 13 21:40:27 2014 +0100 +++ b/framework/env/request/redirect.lua Sun Jan 19 14:47:08 2014 +0100 @@ -3,7 +3,8 @@ module = module, -- module name view = view, -- view name id = id, -- optional id for view - params = params -- optional view parameters + params = params, -- optional view parameters + anchor = anchor -- anchor in URL } Calling this function causes the WebMCP to do a 303 HTTP redirect after the current view or action and all filters have finished execution. If routing mode "redirect" has been chosen, then this function is called automatically after an action and all its filters have finished execution. Calling request.redirect{...} (or request.forward{...}) explicitly inside an action will cause routing information from the browser to be ignored. To preserve GET/POST parameters of an action, use request.forward{...} instead. Currently no redirects to external (absolute) URLs are possible, there will be an implementation in future though. @@ -17,6 +18,7 @@ local view = args.view local id = args.id local params = args.params or {} + local anchor = args.anchor or nil if type(module) ~= "string" then error("No module string passed to request.redirect{...}.") end @@ -26,6 +28,9 @@ if type(params) ~= "table" then error("Params array passed to request.redirect{...} is not a table.") end + if anchor and type(anchor) ~= "string" then + error("Anchor passed to request.redirect{...} must be a string or nil.") + end if request.is_rerouted() then error("Tried to redirect after another forward or redirect.") end @@ -33,7 +38,8 @@ module = module, view = view, id = id, - params = params + params = params, + anchor = anchor } trace.redirect{ module = args.module, view = args.view } end diff -r 407633fd0e84 -r ca88032cb37c framework/env/ui/form.lua --- a/framework/env/ui/form.lua Mon Jan 13 21:40:27 2014 +0100 +++ b/framework/env/ui/form.lua Sun Jan 19 14:47:08 2014 +0100 @@ -13,7 +13,8 @@ module = module, -- optional module name, defaults to current module view = view, -- view name id = id, -- optional id to be passed to the view - params = params -- optional params to be passed to the view + params = params, -- optional params to be passed to the view + anchor = anchor -- optional anchor for URL }, ok = { ... }, -- routing when "ok" is returned by the called action error = { ... }, -- routing when "error" is returned by the called action @@ -53,6 +54,7 @@ params["_webmcp_routing." .. status .. ".module"] = module params["_webmcp_routing." .. status .. ".view"] = settings.view params["_webmcp_routing." .. status .. ".id"] = settings.id + params["_webmcp_routing." .. status .. ".anchor"] = settings.anchor if settings.params then for key, value in pairs(settings.params) do params["_webmcp_routing." .. status .. ".params." .. key] = value