Skip to content

Commit

Permalink
prevent out-of-sync refreshes and multiple refreshes from occurring
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrew Bruce committed Apr 28, 2009
1 parent 65176b6 commit 741b154
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions public/javascripts/iteration_active.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,17 +84,23 @@ DraggableStories.create = function() {
}

DraggableStories.scheduleRefresh = function() {
clearTimeout(DraggableStories.timeout);
if (DraggableStories.refreshedOnce) {
setTimeout('DraggableStories.refresh()', 5000);
DraggableStories.timeout = setTimeout('DraggableStories.refresh()', 5000);
} else {
setTimeout('DraggableStories.refresh()', 0);
DraggableStories.timeout = setTimeout('DraggableStories.refresh()', 0);
DraggableStories.refreshedOnce = true;
}
}

DraggableStories.refresh = function() {
var url, stories, statuses, droppable, draggable_story;

if (DraggableStories.refresh_lock) {
DraggableStories.scheduleRefresh();
return false;
}

url = window.location.href.split('#')[0] + '/stories.json';

$.getJSON(url,
Expand Down Expand Up @@ -221,13 +227,19 @@ function DroppableStatus(input) {
var id_parts = instance.input.id.split('_');
var story_id = id_parts[id_parts.length - 1];

// set the refresh lock to avoid out-of-sync updates
DraggableStories.refresh_lock = true;

// check the radio button
$('li#story_'+story_id+' ol input').val([instance.status]);

// send the request
instance.form.ajaxSubmit({
success: function() {
DroppableStatus.previous_statuses[story_id] = instance.status;

// clear refresh lock
DraggableStories.refresh_lock = false;
}
});

Expand Down

0 comments on commit 741b154

Please sign in to comment.