changeset 4556:dbd2f2891585

pull requests: abort pending ajax requests before starting new one Quick navigation and different load times could cause an old result to overwrite a new one.
author Mads Kiilerich <madski@unity3d.com>
date Fri, 03 Oct 2014 00:20:36 +0200
parents 0ece1a4cf6e3
children cb360bf40863
files kallithea/public/js/base.js kallithea/templates/pullrequests/pullrequest.html
diffstat 2 files changed, 16 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/kallithea/public/js/base.js	Fri Oct 03 00:20:36 2014 +0200
+++ b/kallithea/public/js/base.js	Fri Oct 03 00:20:36 2014 +0200
@@ -362,7 +362,7 @@
     }
     $target.html(_TM['Loading ...']).css('opacity','0.3');
 
-    $.ajax({url: url, data: args, headers: {'X-PARTIAL-XHR': '1'}, cache: false, dataType: 'html'})
+    return $.ajax({url: url, data: args, headers: {'X-PARTIAL-XHR': '1'}, cache: false, dataType: 'html'})
         .done(function(html) {
                 $target.html(html);
                 $target.css('opacity','1.0');
@@ -372,6 +372,8 @@
                 }
             })
         .fail(function(jqXHR, textStatus, errorThrown) {
+                if (textStatus == "abort")
+                    return;
                 console.log('Ajax failure: ' + textStatus);
                 $target.html('<span class="error_red">ERROR: {0}</span>'.format(textStatus));
                 $target.css('opacity','1.0');
--- a/kallithea/templates/pullrequests/pullrequest.html	Fri Oct 03 00:20:36 2014 +0200
+++ b/kallithea/templates/pullrequests/pullrequest.html	Fri Oct 03 00:20:36 2014 +0200
@@ -146,10 +146,16 @@
 
   pyroutes.register('pullrequest_repo_info', "${url('pullrequest_repo_info',repo_name='%(repo_name)s')}", ['repo_name']);
 
+  var pendingajax = undefined;
   var otherrepoChanged = function(){
       var repo_name = $('#other_repo').val();
-      ajaxGET(pyroutes.url('pullrequest_repo_info', {"repo_name": repo_name}),
+      if (pendingajax) {
+          pendingajax.abort();
+          pendingajax = undefined;
+      }
+      pendingajax = ajaxGET(pyroutes.url('pullrequest_repo_info', {"repo_name": repo_name}),
           function(o){
+              pendingajax = undefined;
               var data = JSON.parse(o.responseText);
               $('#other_repo_desc').html(data.description);
 
@@ -217,7 +223,12 @@
           url = url.replace(k,rev_data[k]);
       }
 
-      asynchtml(url, $('#pull_request_overview'), function(o){
+      if (pendingajax) {
+          pendingajax.abort();
+          pendingajax = undefined;
+      }
+      pendingajax = asynchtml(url, $('#pull_request_overview'), function(o){
+          pendingajax = undefined;
           var jsdata = eval('('+YUD.get('jsdata').innerHTML+')'); // TODO: just get json
           var r = new BranchRenderer('graph_canvas', 'graph_content_pr');
           r.render(jsdata,100);