# HG changeset patch # User jbe # Date 1498577642 -7200 # Node ID 93ebbc1e5dbc116652ae308a04192e8b861abe63 # Parent 7a7770297ae862dc1fa795a2f9d5edd06d17d931 Allow actions to directly return content (e.g. for XMLHttpRequests) by calling slot.set_layout(...) during request handling diff -r 7a7770297ae8 -r 93ebbc1e5dbc framework/env/request/handler.lua --- a/framework/env/request/handler.lua Tue Jun 27 15:38:24 2017 +0200 +++ b/framework/env/request/handler.lua Tue Jun 27 17:34:02 2017 +0200 @@ -144,7 +144,7 @@ module = request.get_module(), action = request.get_action(), } - if not request.is_rerouted() then + if not (request.is_rerouted() or slot.layout_is_set()) then local routing_mode, routing_module, routing_view, routing_anchor routing_mode = http_request.post_params["_webmcp_routing." .. action_status .. ".mode"] routing_module = http_request.post_params["_webmcp_routing." .. action_status .. ".module"] diff -r 7a7770297ae8 -r 93ebbc1e5dbc framework/env/request/is_in_progress.lua --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/framework/env/request/is_in_progress.lua Tue Jun 27 17:34:02 2017 +0200 @@ -0,0 +1,11 @@ +--[[-- +bool = -- true, if a request is currently in progress (i.e. being answered) +request.is_in_progress() + +This function can be used to check if a request is currently in progress. Returns false during configuration. + +--]]-- + +function request.is_in_progress() + return request._in_progress +end diff -r 7a7770297ae8 -r 93ebbc1e5dbc framework/env/slot/__init.lua --- a/framework/env/slot/__init.lua Tue Jun 27 15:38:24 2017 +0200 +++ b/framework/env/slot/__init.lua Tue Jun 27 17:34:02 2017 +0200 @@ -4,6 +4,7 @@ slot._current_layout = "default" slot._content_type = nil + slot._layout_set = false slot._data = nil slot.reset_all() diff -r 7a7770297ae8 -r 93ebbc1e5dbc framework/env/slot/layout_is_set.lua --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/framework/env/slot/layout_is_set.lua Tue Jun 27 17:34:02 2017 +0200 @@ -0,0 +1,11 @@ +--[[-- +bool = -- set to true if layout has been set explicitly during processing request +slot.layout_is_set() + +Returns true if slot.set_layout(...) has been called during handling of a request. + +--]]-- + +function slot.layout_is_set() + return slot._layout_set +end diff -r 7a7770297ae8 -r 93ebbc1e5dbc framework/env/slot/set_layout.lua --- a/framework/env/slot/set_layout.lua Tue Jun 27 15:38:24 2017 +0200 +++ b/framework/env/slot/set_layout.lua Tue Jun 27 17:34:02 2017 +0200 @@ -9,8 +9,12 @@ --]]-- function slot.set_layout(layout_ident, content_type) + local in_progress = request.is_in_progress() request.configure(function() slot._current_layout = layout_ident slot._content_type = content_type + if in_progress then + slot._layout_set = true + end end) end