Skip to content

Instantly share code, notes, and snippets.

@randallb
Created March 30, 2012 22:04
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save randallb/2255959 to your computer and use it in GitHub Desktop.
Save randallb/2255959 to your computer and use it in GitHub Desktop.
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