2014-07-30 02:34:39 +02:00
|
|
|
(function($) {
|
2014-08-07 03:56:15 +02:00
|
|
|
$.entwine('ss', function($) {
|
|
|
|
$('#externalLinksReport').entwine({
|
2014-08-13 04:55:47 +02:00
|
|
|
PollTimeout: null,
|
2014-08-07 03:56:15 +02:00
|
|
|
onclick: function() {
|
2014-08-13 04:55:47 +02:00
|
|
|
this.start();
|
2014-08-07 03:56:15 +02:00
|
|
|
},
|
|
|
|
onmatch: function() {
|
|
|
|
// poll the current job and update the front end status
|
|
|
|
$('#externalLinksReport').hide();
|
2014-08-13 04:55:47 +02:00
|
|
|
this.poll();
|
2014-08-07 03:56:15 +02:00
|
|
|
},
|
|
|
|
start: function() {
|
|
|
|
// initiate a new job
|
|
|
|
$('#ReportHolder').empty();
|
|
|
|
$('#ReportHolder').text('Running report 0%');
|
|
|
|
$('#ReportHolder').append('<span class="ss-ui-loading-icon"></span>');
|
|
|
|
$('#externalLinksReport').hide();
|
2014-08-13 04:55:47 +02:00
|
|
|
$.ajax({url: "admin/externallinks/start", async: false, timeout: 3000 });
|
|
|
|
this.poll();
|
2014-08-07 03:56:15 +02:00
|
|
|
},
|
2014-08-13 04:55:47 +02:00
|
|
|
poll: function() {
|
|
|
|
var self = this;
|
|
|
|
|
2014-08-07 03:56:15 +02:00
|
|
|
$.ajax({
|
|
|
|
url: "admin/externallinks/getJobStatus",
|
|
|
|
async: true,
|
|
|
|
success: function(data) {
|
|
|
|
// No report, so let user create one
|
|
|
|
if (!data) {
|
|
|
|
$('#externalLinksReport').show();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Parse data
|
|
|
|
var completed = data.Completed ? data.Completed : 0;
|
|
|
|
var total = data.Total ? data.Total : 0;
|
|
|
|
|
|
|
|
// If complete status
|
|
|
|
if (data.Status === 'Completed') {
|
|
|
|
$('#ReportHolder').text('Report Finished ' + completed + '/' + total);
|
|
|
|
$('#externalLinksReport').show();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If incomplete update status
|
2014-07-30 02:34:39 +02:00
|
|
|
if (completed < total) {
|
|
|
|
var percent = (completed / total) * 100;
|
2014-08-07 03:56:15 +02:00
|
|
|
$('#ReportHolder')
|
|
|
|
.text('Running report ' + completed + '/' + total + ' (' + percent.toFixed(2) + '%)')
|
|
|
|
.append('<span class="ss-ui-loading-icon"></span>');
|
|
|
|
}
|
2014-08-13 04:55:47 +02:00
|
|
|
|
2014-08-07 03:56:15 +02:00
|
|
|
// Ensure the regular poll method is run
|
2014-08-13 04:55:47 +02:00
|
|
|
// kill any existing timeout
|
|
|
|
if(self.getPollTimeout() !== null) {
|
|
|
|
clearTimeout(self.getPollTimeout());
|
2014-08-07 03:56:15 +02:00
|
|
|
}
|
2014-08-13 04:55:47 +02:00
|
|
|
|
|
|
|
self.setPollTimeout(setTimeout(function() { $('#externalLinksReport').poll(); }, 1000));
|
2014-08-07 03:56:15 +02:00
|
|
|
},
|
|
|
|
error: function(e) {
|
|
|
|
if(typeof console !== 'undefined') console.log(e);
|
2014-07-30 02:34:39 +02:00
|
|
|
}
|
2014-08-07 03:56:15 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
2014-07-30 02:34:39 +02:00
|
|
|
});
|
|
|
|
}(jQuery));
|