webmcp
changeset 492:93ebbc1e5dbc
Allow actions to directly return content (e.g. for XMLHttpRequests) by calling slot.set_layout(...) during request handling
author | jbe |
---|---|
date | Tue Jun 27 17:34:02 2017 +0200 (2017-06-27) |
parents | 7a7770297ae8 |
children | 9f9a67c8f6f5 |
files | framework/env/request/handler.lua framework/env/request/is_in_progress.lua framework/env/slot/__init.lua framework/env/slot/layout_is_set.lua framework/env/slot/set_layout.lua |
line diff
1.1 --- a/framework/env/request/handler.lua Tue Jun 27 15:38:24 2017 +0200 1.2 +++ b/framework/env/request/handler.lua Tue Jun 27 17:34:02 2017 +0200 1.3 @@ -144,7 +144,7 @@ 1.4 module = request.get_module(), 1.5 action = request.get_action(), 1.6 } 1.7 - if not request.is_rerouted() then 1.8 + if not (request.is_rerouted() or slot.layout_is_set()) then 1.9 local routing_mode, routing_module, routing_view, routing_anchor 1.10 routing_mode = http_request.post_params["_webmcp_routing." .. action_status .. ".mode"] 1.11 routing_module = http_request.post_params["_webmcp_routing." .. action_status .. ".module"]
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 2.2 +++ b/framework/env/request/is_in_progress.lua Tue Jun 27 17:34:02 2017 +0200 2.3 @@ -0,0 +1,11 @@ 2.4 +--[[-- 2.5 +bool = -- true, if a request is currently in progress (i.e. being answered) 2.6 +request.is_in_progress() 2.7 + 2.8 +This function can be used to check if a request is currently in progress. Returns false during configuration. 2.9 + 2.10 +--]]-- 2.11 + 2.12 +function request.is_in_progress() 2.13 + return request._in_progress 2.14 +end
3.1 --- a/framework/env/slot/__init.lua Tue Jun 27 15:38:24 2017 +0200 3.2 +++ b/framework/env/slot/__init.lua Tue Jun 27 17:34:02 2017 +0200 3.3 @@ -4,6 +4,7 @@ 3.4 3.5 slot._current_layout = "default" 3.6 slot._content_type = nil 3.7 + slot._layout_set = false 3.8 3.9 slot._data = nil 3.10 slot.reset_all()
4.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 4.2 +++ b/framework/env/slot/layout_is_set.lua Tue Jun 27 17:34:02 2017 +0200 4.3 @@ -0,0 +1,11 @@ 4.4 +--[[-- 4.5 +bool = -- set to true if layout has been set explicitly during processing request 4.6 +slot.layout_is_set() 4.7 + 4.8 +Returns true if slot.set_layout(...) has been called during handling of a request. 4.9 + 4.10 +--]]-- 4.11 + 4.12 +function slot.layout_is_set() 4.13 + return slot._layout_set 4.14 +end
5.1 --- a/framework/env/slot/set_layout.lua Tue Jun 27 15:38:24 2017 +0200 5.2 +++ b/framework/env/slot/set_layout.lua Tue Jun 27 17:34:02 2017 +0200 5.3 @@ -9,8 +9,12 @@ 5.4 --]]-- 5.5 5.6 function slot.set_layout(layout_ident, content_type) 5.7 + local in_progress = request.is_in_progress() 5.8 request.configure(function() 5.9 slot._current_layout = layout_ident 5.10 slot._content_type = content_type 5.11 + if in_progress then 5.12 + slot._layout_set = true 5.13 + end 5.14 end) 5.15 end