libs/cbi: interface with service control backend to trigger service reload asynchronously

This commit is contained in:
Jo-Philipp Wich 2010-10-11 22:54:35 +00:00
parent e2db48ab36
commit 2c22ea7b77

View file

@ -19,23 +19,44 @@ $Id$
<%- if self._apply then -%> <%- if self._apply then -%>
<fieldset class="cbi-section" id="cbi-apply-<%=self.config%>"> <fieldset class="cbi-section" id="cbi-apply-<%=self.config%>">
<legend><%:Applying changes%></legend> <legend><%:Applying changes%></legend>
<ul class="cbi-apply"><%- <script type="text/javascript"><![CDATA[
local fp = self._apply() var apply_xhr = new XHR();
self._apply = nil
local line = fp:read() apply_xhr.get('<%=luci.dispatcher.build_url("servicectl", "restart", table.concat(self.parsechain, ","))%>', null,
while line do function() {
write("<li>" .. pcdata(line) .. "</li>\n") var intv = window.setInterval(
line = fp:read() function() {
end apply_xhr.abort();
fp:close() apply_xhr.get('<%=luci.dispatcher.build_url("servicectl", "status")%>', null,
-%></ul> function(x) {
if( x.responseText == 'finish' )
{
window.clearInterval(intv);
var e = document.getElementById('cbi-apply-<%=self.config%>-status');
if( e )
{
e.innerHTML = '<%:Configuration applied.%>';
window.setTimeout(function() { e.parentNode.style.display = 'none' }, 1000);
}
}
else
{
var e = document.getElementById('cbi-apply-<%=self.config%>-status');
if( e && x.responseText ) e.innerHTML = x.responseText;
}
}
);
}, 1000
)
}
);
]]></script>
<img src="<%=resource%>/icons/loading.gif" alt="<%:Loading%>" style="vertical-align:middle" />
<span id="cbi-apply-<%=self.config%>-status"><%:Waiting for router...%></span>
</fieldset> </fieldset>
<script type="text/javascript">
window.setTimeout(function() {
var e = document.getElementById('cbi-apply-<%=self.config%>');
if(e) e.style.display = 'none';
}, 750);
</script>
<%- end -%> <%- end -%>
<%- self:render_children() %> <%- self:render_children() %>
<br /> <br />