Commit 2b76fd29 authored by Joshua Tauberer's avatar Joshua Tauberer

admin: ensure multiple concurrent api calls dont confuse the ajax loading...

admin: ensure multiple concurrent api calls dont confuse the ajax loading indicator (track number of open requets, stop fade animation when it is time to hide)
parent 90592bb1
...@@ -264,12 +264,13 @@ function show_modal_confirm(title, question, verb, yes_callback, cancel_callback ...@@ -264,12 +264,13 @@ function show_modal_confirm(title, question, verb, yes_callback, cancel_callback
$('#global_modal').modal({}); $('#global_modal').modal({});
} }
var is_ajax_loading = false; var ajax_num_executing_requests = 0;
function ajax(options) { function ajax(options) {
setTimeout("if (is_ajax_loading) $('#ajax_loading_indicator').fadeIn()", 100); setTimeout("if (ajax_num_executing_requests > 0) $('#ajax_loading_indicator').fadeIn()", 100);
function hide_loading_indicator() { function hide_loading_indicator() {
is_ajax_loading = false; ajax_num_executing_requests--;
$('#ajax_loading_indicator').hide(); if (ajax_num_executing_requests == 0)
$('#ajax_loading_indicator').stop().hide(); // stop() prevents an ongoing fade from causing the thing to be shown again after this call
} }
var old_success = options.success; var old_success = options.success;
var old_error = options.error; var old_error = options.error;
...@@ -287,7 +288,7 @@ function ajax(options) { ...@@ -287,7 +288,7 @@ function ajax(options) {
else else
old_error(jqxhr.responseText, jqxhr); old_error(jqxhr.responseText, jqxhr);
}; };
is_ajax_loading = true; ajax_num_executing_requests++;
$.ajax(options); $.ajax(options);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment