libs/web: combine apply actions of all maps on a page, prevents concurrent XHR
This commit is contained in:
parent
cf6bda5c96
commit
9c3db58ee4
3 changed files with 34 additions and 16 deletions
|
@ -322,10 +322,10 @@ function Map.parse(self, readinput, ...)
|
||||||
self.uci:apply(self.parsechain)
|
self.uci:apply(self.parsechain)
|
||||||
self:_run_hooks("on_apply", "on_after_apply")
|
self:_run_hooks("on_apply", "on_after_apply")
|
||||||
else
|
else
|
||||||
self._apply = function()
|
-- This is evaluated by the dispatcher and delegated to the
|
||||||
local cmd = self.uci:apply(self.parsechain, true)
|
-- template which in turn fires XHR to perform the actual
|
||||||
return io.popen(cmd)
|
-- apply actions.
|
||||||
end
|
self.apply_needed = true
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Reparse sections
|
-- Reparse sections
|
||||||
|
@ -358,12 +358,6 @@ end
|
||||||
function Map.render(self, ...)
|
function Map.render(self, ...)
|
||||||
self:_run_hooks("on_init")
|
self:_run_hooks("on_init")
|
||||||
Node.render(self, ...)
|
Node.render(self, ...)
|
||||||
if false and self._apply then
|
|
||||||
local fp = self._apply()
|
|
||||||
fp:read("*a")
|
|
||||||
fp:close()
|
|
||||||
self:_run_hooks("on_apply")
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Creates a child section
|
-- Creates a child section
|
||||||
|
|
|
@ -718,21 +718,45 @@ local function _cbi(self, ...)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local redirect
|
|
||||||
local pageaction = true
|
|
||||||
http.header("X-CBI-State", state or 0)
|
http.header("X-CBI-State", state or 0)
|
||||||
|
|
||||||
if not config.noheader then
|
if not config.noheader then
|
||||||
tpl.render("cbi/header", {state = state})
|
tpl.render("cbi/header", {state = state})
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local redirect
|
||||||
|
local applymap = false
|
||||||
|
local pageaction = true
|
||||||
|
local parsechain = { }
|
||||||
|
|
||||||
for i, res in ipairs(maps) do
|
for i, res in ipairs(maps) do
|
||||||
res:render()
|
if res.apply_needed and res.parsechain then
|
||||||
if res.pageaction == false then
|
local c
|
||||||
pageaction = false
|
for _, c in ipairs(res.parsechain) do
|
||||||
|
parsechain[#parsechain+1] = c
|
||||||
|
end
|
||||||
|
applymap = true
|
||||||
end
|
end
|
||||||
|
|
||||||
if res.redirect then
|
if res.redirect then
|
||||||
redirect = redirect or res.redirect
|
redirect = redirect or res.redirect
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if res.pageaction == false then
|
||||||
|
pageaction = false
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
for i, res in ipairs(maps) do
|
||||||
|
res:render({
|
||||||
|
firstmap = (i == 1),
|
||||||
|
applymap = applymap,
|
||||||
|
redirect = redirect,
|
||||||
|
pageaction = pageaction,
|
||||||
|
parsechain = parsechain
|
||||||
|
})
|
||||||
|
end
|
||||||
|
|
||||||
if not config.nofooter then
|
if not config.nofooter then
|
||||||
tpl.render("cbi/footer", {
|
tpl.render("cbi/footer", {
|
||||||
flow = config,
|
flow = config,
|
||||||
|
|
|
@ -18,7 +18,7 @@ $Id$
|
||||||
<div class="cbi-map" id="cbi-<%=self.config%>">
|
<div class="cbi-map" id="cbi-<%=self.config%>">
|
||||||
<% if self.title and #self.title > 0 then %><h2><a id="content" name="content"><%=self.title%></a></h2><% end %>
|
<% if self.title and #self.title > 0 then %><h2><a id="content" name="content"><%=self.title%></a></h2><% end %>
|
||||||
<% if self.description and #self.description > 0 then %><div class="cbi-map-descr"><%=self.description%></div><% end %>
|
<% if self.description and #self.description > 0 then %><div class="cbi-map-descr"><%=self.description%></div><% end %>
|
||||||
<%- if self._apply then cbi_apply_xhr(self.config, self.parsechain, self.redirect) end -%>
|
<%- if firstmap and applymap then cbi_apply_xhr(self.config, parsechain, redirect) end -%>
|
||||||
<%- self:render_children() %>
|
<%- self:render_children() %>
|
||||||
<br />
|
<br />
|
||||||
</div>
|
</div>
|
||||||
|
|
Loading…
Reference in a new issue