webmcp

changeset 113:ca88032cb37c

Anchor (#) support for redirect and routing
author jbe
date Sun Jan 19 14:47:08 2014 +0100 (2014-01-19)
parents 407633fd0e84
children 6c4a5b136074
files framework/cgi-bin/webmcp.lua framework/env/request/redirect.lua framework/env/ui/form.lua
line diff
     1.1 --- a/framework/cgi-bin/webmcp.lua	Mon Jan 13 21:40:27 2014 +0100
     1.2 +++ b/framework/cgi-bin/webmcp.lua	Sun Jan 19 14:47:08 2014 +0100
     1.3 @@ -319,11 +319,13 @@
     1.4            routing_mode   = cgi.params["_webmcp_routing." .. action_status .. ".mode"]
     1.5            routing_module = cgi.params["_webmcp_routing." .. action_status .. ".module"]
     1.6            routing_view   = cgi.params["_webmcp_routing." .. action_status .. ".view"]
     1.7 +          routing_anchor = cgi.params["_webmcp_routing." .. action_status .. ".anchor"]
     1.8            if not (routing_mode or routing_module or routing_view) then
     1.9              action_status = "default"
    1.10              routing_mode   = cgi.params["_webmcp_routing.default.mode"]
    1.11              routing_module = cgi.params["_webmcp_routing.default.module"]
    1.12              routing_view   = cgi.params["_webmcp_routing.default.view"]
    1.13 +            routing_anchor = cgi.params["_webmcp_routing.default.anchor"]
    1.14            end
    1.15            assert(routing_module, "Routing information has no module.")
    1.16            assert(routing_view,   "Routing information has no view.")
    1.17 @@ -341,7 +343,8 @@
    1.18                module = routing_module,
    1.19                view   = routing_view,
    1.20                id     = cgi.params["_webmcp_routing." .. action_status .. ".id"],
    1.21 -              params = routing_params
    1.22 +              params = routing_params,
    1.23 +              anchor = routing_anchor
    1.24              }
    1.25            elseif routing_mode == "forward" then
    1.26              request.forward{ module = routing_module, view = routing_view }
    1.27 @@ -452,7 +455,8 @@
    1.28        module = redirect_data.module,
    1.29        view   = redirect_data.view,
    1.30        id     = redirect_data.id,
    1.31 -      params = redirect_params
    1.32 +      params = redirect_params,
    1.33 +      anchor = redirect_data.anchor
    1.34      }
    1.35    )
    1.36    cgi.send_data()
     2.1 --- a/framework/env/request/redirect.lua	Mon Jan 13 21:40:27 2014 +0100
     2.2 +++ b/framework/env/request/redirect.lua	Sun Jan 19 14:47:08 2014 +0100
     2.3 @@ -3,7 +3,8 @@
     2.4    module = module,  -- module name
     2.5    view   = view,    -- view name
     2.6    id     = id,      -- optional id for view
     2.7 -  params = params   -- optional view parameters
     2.8 +  params = params,  -- optional view parameters
     2.9 +  anchor = anchor   -- anchor in URL
    2.10  }
    2.11  
    2.12  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.
    2.13 @@ -17,6 +18,7 @@
    2.14    local view   = args.view
    2.15    local id     = args.id
    2.16    local params = args.params or {}
    2.17 +  local anchor = args.anchor or nil
    2.18    if type(module) ~= "string" then
    2.19      error("No module string passed to request.redirect{...}.")
    2.20    end
    2.21 @@ -26,6 +28,9 @@
    2.22    if type(params) ~= "table" then
    2.23      error("Params array passed to request.redirect{...} is not a table.")
    2.24    end
    2.25 +  if anchor and type(anchor) ~= "string" then
    2.26 +    error("Anchor passed to request.redirect{...} must be a string or nil.")
    2.27 +  end
    2.28    if request.is_rerouted() then
    2.29      error("Tried to redirect after another forward or redirect.")
    2.30    end
    2.31 @@ -33,7 +38,8 @@
    2.32      module = module,
    2.33      view   = view,
    2.34      id     = id,
    2.35 -    params = params
    2.36 +    params = params,
    2.37 +    anchor = anchor
    2.38    }
    2.39    trace.redirect{ module = args.module, view = args.view }
    2.40  end
     3.1 --- a/framework/env/ui/form.lua	Mon Jan 13 21:40:27 2014 +0100
     3.2 +++ b/framework/env/ui/form.lua	Sun Jan 19 14:47:08 2014 +0100
     3.3 @@ -13,7 +13,8 @@
     3.4        module = module,    -- optional module name, defaults to current module
     3.5        view   = view,      -- view name
     3.6        id     = id,        -- optional id to be passed to the view
     3.7 -      params = params     -- optional params to be passed to the view
     3.8 +      params = params,    -- optional params to be passed to the view
     3.9 +      anchor = anchor     -- optional anchor for URL
    3.10      },
    3.11      ok    = { ... },      -- routing when "ok"    is returned by the called action
    3.12      error = { ... },      -- routing when "error" is returned by the called action
    3.13 @@ -53,6 +54,7 @@
    3.14        params["_webmcp_routing." .. status .. ".module"] = module
    3.15        params["_webmcp_routing." .. status .. ".view"]   = settings.view
    3.16        params["_webmcp_routing." .. status .. ".id"]     = settings.id
    3.17 +      params["_webmcp_routing." .. status .. ".anchor"] = settings.anchor
    3.18        if settings.params then
    3.19          for key, value in pairs(settings.params) do
    3.20            params["_webmcp_routing." .. status .. ".params." .. key] = value

Impressum / About Us