Skip to content

Commit

Permalink
Merge pull request #53 from iturgeon/issue/52-udoit-submit-handle-pro…
Browse files Browse the repository at this point in the history
…cess-error

handle process.php and progress.php errors in ajax
  • Loading branch information
bagofarms committed Dec 17, 2015
2 parents 29f493e + 935229d commit 745fa85
Showing 1 changed file with 14 additions and 19 deletions.
33 changes: 14 additions & 19 deletions assets/js/default.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
*
* Primary Author Contact: Jacob Bates <[email protected]>
*/

var progressTimer = null;

/* Fades out and destroys the popup window and background. */
function killButton(callback) {
if($("#popup").length > 0) {
Expand Down Expand Up @@ -85,6 +88,7 @@ function checker() {
context_title: context_title
},
success: function(data){
clearInterval(progressTimer);
$('#scanner').append('<section id="result">'+data+'</section>');
killButton(function() {
$('#result').fadeIn();
Expand All @@ -93,6 +97,7 @@ function checker() {
jscolor.bind();
},
error: function(data){
clearInterval(progressTimer);
killButton();
$('#failMsg').fadeIn();
}
Expand Down Expand Up @@ -145,30 +150,20 @@ $(document).ready(function() {

var old = 0;

var timer = setInterval(function(){

// start progress checker, this is cleared here or from checker()
clearInterval(progressTimer);
progressTimer = setInterval(function(){
$.ajax({
url: 'lib/progress.php',
error: function(xhr, status, error) {
clearInterval(progressTimer);
},
success: function(data){
// update display if progress state has changed
if(data != old) {
if(data == 'announcements') {
$('#submit').html('<div id="popup"><div class="circle"></div></div> Scanning announcements...');
}
if(data == 'assignments') {
$('#submit').html('<div id="popup"><div class="circle"></div></div> Scanning assignments...');
}
if(data == 'discussions') {
$('#submit').html('<div id="popup"><div class="circle"></div></div> Scanning discussions...');
}
if(data == 'files') {
$('#submit').html('<div id="popup"><div class="circle"></div></div> Scanning files...');
}
if(data == 'pages') {
$('#submit').html('<div id="popup"><div class="circle"></div></div> Scanning pages...');
}
if(data == 'done') {
clearInterval(timer);
}
old = data;
$('#submit').html('<div id="popup"><div class="circle"></div></div> Scanning '+data+'...');
}
}
});
Expand Down

0 comments on commit 745fa85

Please sign in to comment.