Prevent race conditions in ajax calls

pull/6827/head
Mark Maglana 14 years ago
parent 431030cc5f
commit d26d887933
  1. 4
      assets/javascripts/backlog.js
  2. 22
      assets/javascripts/common.js
  3. 4
      assets/javascripts/index_main.js
  4. 3
      assets/javascripts/story.js

@ -172,7 +172,7 @@ RB.Backlog = RB.Object.create(RB.Model, {
},
loadStoryTemplate: function(){
$.ajax({
RB.ajax({
type: "GET",
async: false,
url: RB.urlFor['new_story'] + "?project_id=" + RB.constants.project_id,
@ -227,7 +227,7 @@ RB.Backlog = RB.Object.create(RB.Model, {
}
});
$.ajax({
RB.ajax({
type: "POST",
url: RB.urlFor['update_backlog'],
data: editors.serialize() + "&id=" + j.find('.id').text(),

@ -47,6 +47,28 @@ RB.dialog = RB.Object.create({
}
});
RB.ajaxQueue = new Array()
RB.ajaxOngoing = false;
RB.ajax = function(options){
RB.ajaxQueue.push(options);
if(!RB.ajaxOngoing){ RB.processAjaxQueue(); }
}
RB.processAjaxQueue = function(){
var options = RB.ajaxQueue.shift();
if(options!=null){
RB.ajaxOngoing = true;
$.ajax(options);
}
}
$(document).ajaxComplete(function(event, xhr, settings){
RB.ajaxOngoing = false;
RB.processAjaxQueue();
});
// Modify the ajax request before being sent to the server
$(document).ajaxSend(function(event, request, settings) {
var c = RB.constants;

@ -31,13 +31,13 @@ RB.indexMain = RB.Object.create({
},
loadData: function(){
$('body').addClass('loading');
$.ajax({
RB.ajax({
type: "GET",
url: RB.urlFor['list_stories'],
data: { after : $('#last_updated').text(),
project_id: RB.constants.project_id
},
beforeSend: function(){ $('body').addClass('loading'); },
success: RB.indexMain.refresh
});
},

@ -143,6 +143,7 @@ RB.Story = RB.Object.create(RB.Model, {
refresh: function(){
this.endEdit();
this.unmarkSaving();
var sprint = this.$.parents('.sprint.backlog');
if(sprint.size()>0) sprint.data('this').recalcPoints();
},
@ -195,7 +196,7 @@ RB.Story = RB.Object.create(RB.Model, {
// Get the save directives. This should be overriden by descendant objects of RB.Story
var saveDir = this.saveDirectives();
$.ajax({
RB.ajax({
type: "POST",
url: saveDir.url,
data: saveDir.data,

Loading…
Cancel
Save