Skip to content

Commit

Permalink
update ranks when removing a cat
Browse files Browse the repository at this point in the history
  • Loading branch information
davidsulc committed Apr 21, 2012
1 parent f0befae commit e8e1870
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions assets/javascripts/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,16 @@ AngryCats = Backbone.Collection.extend({
self.rankDown(cat);
self.sort();
});

MyApp.vent.on("cat:disqualify", function(cat){
var disqualifiedRank = cat.get('rank');
var catsToUprank = self.filter(
function(cat){ return cat.get('rank') > disqualifiedRank; }
);
catsToUprank.forEach(function(cat){
cat.rankUp();
});
});
},

comparator: function(cat) {
Expand Down Expand Up @@ -112,6 +122,7 @@ AngryCatView = Backbone.Marionette.ItemView.extend({
},

disqualify: function(){
MyApp.vent.trigger("cat:disqualify", this.model);
this.model.destroy();
}
});
Expand Down

0 comments on commit e8e1870

Please sign in to comment.