54 lines
1.7 KiB
CoffeeScript
54 lines
1.7 KiB
CoffeeScript
$ = jQuery
|
|
context = window
|
|
context.JK ||= {}
|
|
|
|
context.JK.JamTrackLanding = class JamTrackLanding
|
|
constructor: (@app) ->
|
|
@rest = context.JK.Rest()
|
|
@client = context.jamClient
|
|
@logger = context.JK.logger
|
|
@screen = null
|
|
|
|
initialize:() =>
|
|
screenBindings =
|
|
'beforeShow': @beforeShow
|
|
'afterShow': @afterShow
|
|
@app.bindScreen('jamtrackLanding', screenBindings)
|
|
@screen = $('#jamtrackLanding')
|
|
|
|
beforeShow:() =>
|
|
# Get artist names and build links
|
|
@rest.getJamtracks({group_artist: true})
|
|
.done(this.buildArtistLinks)
|
|
.fail(this.handleFailure)
|
|
|
|
# Bind links to action that will open the jam_tracks list view filtered to given artist_name:
|
|
# artist_name
|
|
this.bindArtistLinks()
|
|
afterShow:() =>
|
|
|
|
buildArtistLinks:(response) =>
|
|
# Get artist names and build links
|
|
jamtracks = response.jamtracks
|
|
$("#band_list>li:not('#no_bands_found')").remove()
|
|
if jamtracks.length==0
|
|
$("#no_bands_found").removeClass("hidden")
|
|
else
|
|
$("#no_bands_found").addClass("hidden")
|
|
|
|
# client#/jamtrack
|
|
for jamtrack in jamtracks
|
|
artistLink = "<a href='client?artist=#{encodeURIComponent(jamtrack.original_artist)}#/jamtrackBrowse' class='artist-link' artist='#{jamtrack.original_artist}'>#{jamtrack.original_artist}</a>"
|
|
$("#band_list").append("<li>#{artistLink}</li>")
|
|
|
|
# We don't want to do a full page load if this is clicked on here:
|
|
bindArtistLinks:() =>
|
|
band_list=$("ul#band_list")
|
|
that=this
|
|
band_list.on "click", "a.artist-link", (event)->
|
|
context.location="client#/jamtrackBrowse"
|
|
window.history.replaceState({}, "", this.href)
|
|
event.preventDefault()
|
|
|
|
handleFailure:(error) =>
|