Created
March 30, 2012 22:04
-
-
Save randallb/2255959 to your computer and use it in GitHub Desktop.
This file contains 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
exports.Item = class PostView extends Backbone.View | |
template: require "../templates/post.jade" | |
events: | |
"click" : "loadDetails" | |
render: () => | |
debug @model.toJSON() | |
$(@el).html(@template @model.toJSON()) | |
@ | |
loadDetails: () => | |
@model.trigger "loadDetails", @model | |
initialize: () -> | |
debug "PostView initialized" | |
@model.on "change", @render | |
exports.Model = class Post extends Backbone.Model | |
initialize: => | |
debug "initialized post" | |
@on "send", @send | |
send: => | |
debug "Probably an ajax post to a server." | |
exports.Model = class FbPost extends Post.Model | |
parse: (response) => | |
debug "Parsing FB Model" | |
response.id = "fb_#{response.id}" | |
response.picture = "http://graph.facebook.com/#{response.from.id}/picture?type=large" | |
response | |
exports.Collection = class Posts extends Backbone.Collection | |
initialize: (models, options) -> | |
@id = options.id | |
@activeDetails = false | |
@on "loadDetails", @loadDetails | |
@on "detailsLoaded", @logger | |
debug "initialized posts" | |
@fetch | |
success: (collection, response) => | |
debug "successfully loaded ajax" | |
@trigger "postsLoaded" | |
error: (collection, response) => @trigger "postsLoadingError" | |
loadDetails: (model) => | |
debug "details!" | |
debug model | |
if @activeDetails | |
@activeDetails.set "active", "false" | |
@activeDetails = {} | |
@activeDetails = model | |
model.set "active", "true" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment