From 65117b2599cb3e111fc17f2640788014917f290b Mon Sep 17 00:00:00 2001 From: Sean Harvey Date: Wed, 13 Aug 2014 14:55:47 +1200 Subject: [PATCH] BUG Indicator stuck on 0% until you refresh the page. admin/externallinks/start is called, but asynchronously, so the poll() call is never called immediately on start, you have to refresh the page to get it to show. --- javascript/BrokenExternalLinksReport.js | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/javascript/BrokenExternalLinksReport.js b/javascript/BrokenExternalLinksReport.js index 5b3c853..c6d84c9 100644 --- a/javascript/BrokenExternalLinksReport.js +++ b/javascript/BrokenExternalLinksReport.js @@ -1,13 +1,14 @@ (function($) { $.entwine('ss', function($) { $('#externalLinksReport').entwine({ + PollTimeout: null, onclick: function() { - $(this).start(); + this.start(); }, onmatch: function() { // poll the current job and update the front end status $('#externalLinksReport').hide(); - $(this).poll(0); + this.poll(); }, start: function() { // initiate a new job @@ -15,10 +16,12 @@ $('#ReportHolder').text('Running report 0%'); $('#ReportHolder').append(''); $('#externalLinksReport').hide(); - $.ajax({url: "admin/externallinks/start", async: true, timeout: 3000 }); - $(this).poll(1); + $.ajax({url: "admin/externallinks/start", async: false, timeout: 3000 }); + this.poll(); }, - poll: function(start) { + poll: function() { + var self = this; + $.ajax({ url: "admin/externallinks/getJobStatus", async: true, @@ -47,11 +50,14 @@ .text('Running report ' + completed + '/' + total + ' (' + percent.toFixed(2) + '%)') .append(''); } - + // Ensure the regular poll method is run - if(!start) { - setTimeout(function() { $('#externalLinksReport').poll(0); }, 1000); + // kill any existing timeout + if(self.getPollTimeout() !== null) { + clearTimeout(self.getPollTimeout()); } + + self.setPollTimeout(setTimeout(function() { $('#externalLinksReport').poll(); }, 1000)); }, error: function(e) { if(typeof console !== 'undefined') console.log(e);