Created
March 23, 2011 21:01
-
-
Save dealingwith/883967 to your computer and use it in GitHub Desktop.
example backbone
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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