Skip to content

Instantly share code, notes, and snippets.

@willrjmarshall
Created September 19, 2011 00:47
Show Gist options
  • Save willrjmarshall/1225774 to your computer and use it in GitHub Desktop.
Save willrjmarshall/1225774 to your computer and use it in GitHub Desktop.
class Opjam.Models.Track extends Backbone.Model
paramRoot: 'track'
# Set of tracks, scope to a particular broadcast
class Opjam.Collections.TrackCollection extends Backbone.Collection
model: Opjam.Models.Track
url: ->
"/broadcasts/:broadcast_id/tracks"
broadcast_id: ->
@broadcast.id
#======================================================================
class Opjam.Models.Broadcast extends Backbone.Model
paramRoot: 'broadcast'
initialize: ->
# Set track collection
@tracks = new Opjam.Collections.TrackCollection()
# Backbone collections don't have attributes, and we can't easily set this association in the initializer
# So we simply set this field after the create
@tracks.broadcast = @
getCurrentTrack: ->
@currentTrack || @trackCollection.at(0)
setCurrentTrack: (index)->
@currentTrack = @trackCollection.at(index) if index < @length
currentTrack: ->
#console.log(@tracks.fetch())
console.log(@tracks)
@tracks.first()
class Opjam.Collections.BroadcastsCollection extends Backbone.Collection
model: Opjam.Models.Broadcast
url: '/broadcasts'
#======================================================================
# Basically, I want a TrackCollection that attaches to a Broadcast
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment