libs/web: make apply_xhr less aggressive, only rerequest status if previous response...
[project/luci.git] / libs / web / luasrc / view / cbi / apply_xhr.htm
index 30e7a23..d519a5f 100644 (file)
@@ -12,7 +12,7 @@ $Id$
 
 -%>
 
-<% export("cbi_apply_xhr", function(id, configs) -%>
+<% export("cbi_apply_xhr", function(id, configs, redirect) -%>
 <fieldset class="cbi-section" id="cbi-apply-<%=id%>">
        <legend><%:Applying changes%></legend>
        <script type="text/javascript"><![CDATA[
@@ -20,32 +20,33 @@ $Id$
 
                apply_xhr.get('<%=luci.dispatcher.build_url("servicectl", "restart", table.concat(configs, ","))%>', null,
                        function() {
-                               var intv = window.setInterval(
-                                       function() {
-                                               apply_xhr.abort();
-                                               apply_xhr.get('<%=luci.dispatcher.build_url("servicectl", "status")%>', null,
-                                                       function(x) {
-                                                               if( x.responseText == 'finish' )
+                               var checkfinish = function() {
+                                       apply_xhr.get('<%=luci.dispatcher.build_url("servicectl", "status")%>', null,
+                                               function(x) {
+                                                       if( x.responseText == 'finish' )
+                                                       {
+                                                               var e = document.getElementById('cbi-apply-<%=id%>-status');
+                                                               if( e )
                                                                {
-                                                                       window.clearInterval(intv);
-
-                                                                       var e = document.getElementById('cbi-apply-<%=id%>-status');
-                                                                       if( e )
-                                                                       {
-                                                                               e.innerHTML = '<%:Configuration applied.%>';
-                                                                               window.setTimeout(function() { e.parentNode.style.display = 'none' }, 1000);
-                                                                       }
+                                                                       e.innerHTML = '<%:Configuration applied.%>';
+                                                                       window.setTimeout(function() {
+                                                                               e.parentNode.style.display = 'none';
+                                                                               <% if redirect then %>location.href='<%=redirect%>';<% end %>
+                                                                       }, 1000);
                                                                }
-                                                               else
-                                                               {
-                                                                       var e = document.getElementById('cbi-apply-<%=id%>-status');
-                                                                       if( e && x.responseText ) e.innerHTML = x.responseText;
+                                                       }
+                                                       else
+                                                       {
+                                                               var e = document.getElementById('cbi-apply-<%=id%>-status');
+                                                               if( e && x.responseText ) e.innerHTML = x.responseText;
 
-                                                               }
+                                                               window.setTimeout(checkfinish, 1000);
                                                        }
-                                               );
-                                       }, 1000
-                               )
+                                               }
+                                       );
+                               }
+
+                               window.setTimeout(checkfinish, 1000);
                        }
                );
        ]]></script>