libs/web: add support for post commit redirects in cbi maps
[project/luci.git] / libs / web / luasrc / view / cbi / apply_xhr.htm
1 <%#
2 LuCI - Lua Configuration Interface
3 Copyright 2010 Jo-Philipp Wich <xm@subsignal.org>
4
5 Licensed under the Apache License, Version 2.0 (the "License");
6 you may not use this file except in compliance with the License.
7 You may obtain a copy of the License at
8
9         http://www.apache.org/licenses/LICENSE-2.0
10
11 $Id$
12
13 -%>
14
15 <% export("cbi_apply_xhr", function(id, configs, redirect) -%>
16 <fieldset class="cbi-section" id="cbi-apply-<%=id%>">
17         <legend><%:Applying changes%></legend>
18         <script type="text/javascript"><![CDATA[
19                 var apply_xhr = new XHR();
20
21                 apply_xhr.get('<%=luci.dispatcher.build_url("servicectl", "restart", table.concat(configs, ","))%>', null,
22                         function() {
23                                 var intv = window.setInterval(
24                                         function() {
25                                                 apply_xhr.abort();
26                                                 apply_xhr.get('<%=luci.dispatcher.build_url("servicectl", "status")%>', null,
27                                                         function(x) {
28                                                                 if( x.responseText == 'finish' )
29                                                                 {
30                                                                         window.clearInterval(intv);
31
32                                                                         var e = document.getElementById('cbi-apply-<%=id%>-status');
33                                                                         if( e )
34                                                                         {
35                                                                                 e.innerHTML = '<%:Configuration applied.%>';
36                                                                                 window.setTimeout(function() {
37                                                                                         e.parentNode.style.display = 'none';
38                                                                                         <% if redirect then %>location.href='<%=redirect%>';<% end %>
39                                                                                 }, 1000);
40                                                                         }
41                                                                 }
42                                                                 else
43                                                                 {
44                                                                         var e = document.getElementById('cbi-apply-<%=id%>-status');
45                                                                         if( e && x.responseText ) e.innerHTML = x.responseText;
46
47                                                                 }
48                                                         }
49                                                 );
50                                         }, 1000
51                                 )
52                         }
53                 );
54         ]]></script>
55
56         <img src="<%=resource%>/icons/loading.gif" alt="<%:Loading%>" style="vertical-align:middle" />
57         <span id="cbi-apply-<%=id%>-status"><%:Waiting for router...%></span>
58 </fieldset>
59 <%-     end) %>