Skip to content

Instantly share code, notes, and snippets.

@dealingwith
Created March 23, 2011 21:01
Show Gist options
  • Save dealingwith/883967 to your computer and use it in GitHub Desktop.
Save dealingwith/883967 to your computer and use it in GitHub Desktop.
example backbone
Todoblin.Views.Stage = Backbone.View.extend({
initialize: function() {
var self = this;
this.completedTasks = 0;
_.bindAll(this, "render", "fetchGoals", "fetchRewards", "fetchPoints", "pointsUpdate");
this.render();
$("#goals").bind("points.update", function() {
self.completedTasks ++;
if(self.completedTasks % 3 == 0) {
new Todoblin.Views.Notice();
}
});
}
, render: function() {
this.fetchGoals();
this.fetchRewards();
this.fetchPoints();
}
, fetchRewards: function() {
var self = this;
var rewards = new Todoblin.Collections.Rewards();
rewards.fetch({
success: function() {
new Todoblin.Views.Rewards.Panel({collection: rewards});
}
, error: function() {
new Error({message: "Error loading rewards."});
}
});
}
, fetchPoints: function() {
var self = this;
$.getJSON("/users/points", function(summary) {
new Todoblin.Views.Points(summary);
});
}
, fetchGoals: function() {
var self = this;
var goals = new Todoblin.Collections.Goals();
goals.fetch({
success: function() {
new Todoblin.Views.Goals.List({collection: goals});
}
, error: function() {
new Error({message: "Error loading goals."});
}
});
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment