build: introduce luci-base
[project/luci.git] / modules / base / luasrc / luasrc / view / cbi / apply_xhr.htm
1 <% export("cbi_apply_xhr", function(id, configs, redirect) -%>
2 <fieldset class="cbi-section" id="cbi-apply-<%=id%>">
3         <legend><%:Applying changes%></legend>
4         <script type="text/javascript">//<![CDATA[
5                 var apply_xhr = new XHR();
6
7                 apply_xhr.get('<%=luci.dispatcher.build_url("servicectl", "restart", table.concat(configs, ","))%>', null,
8                         function() {
9                                 var checkfinish = function() {
10                                         apply_xhr.get('<%=luci.dispatcher.build_url("servicectl", "status")%>', null,
11                                                 function(x) {
12                                                         if( x.responseText == 'finish' )
13                                                         {
14                                                                 var e = document.getElementById('cbi-apply-<%=id%>-status');
15                                                                 if( e )
16                                                                 {
17                                                                         e.innerHTML = '<%:Configuration applied.%>';
18                                                                         window.setTimeout(function() {
19                                                                                 e.parentNode.style.display = 'none';
20                                                                                 <% if redirect then %>location.href='<%=redirect%>';<% end %>
21                                                                         }, 1000);
22                                                                 }
23                                                         }
24                                                         else
25                                                         {
26                                                                 var e = document.getElementById('cbi-apply-<%=id%>-status');
27                                                                 if( e && x.responseText ) e.innerHTML = x.responseText;
28
29                                                                 window.setTimeout(checkfinish, 1000);
30                                                         }
31                                                 }
32                                         );
33                                 }
34
35                                 window.setTimeout(checkfinish, 1000);
36                         }
37                 );
38         //]]></script>
39
40         <img src="<%=resource%>/icons/loading.gif" alt="<%:Loading%>" style="vertical-align:middle" />
41         <span id="cbi-apply-<%=id%>-status"><%:Waiting for changes to be applied...%></span>
42 </fieldset>
43 <%-     end) %>