1
0
Fork 0

Albums as array of objects

This commit is contained in:
Gregory Eremin 2011-09-15 12:52:29 +04:00
parent 809364a4a2
commit 904265dd2f
4 changed files with 24 additions and 31 deletions

View File

@ -3,6 +3,8 @@ class window.Player
bar_width: 330 bar_width: 330
jp: null jp: null
scrobbled: false scrobbled: false
albums: []
playlist: []
initJplayer: -> initJplayer: ->
self = this self = this
@ -51,28 +53,20 @@ class window.Player
autoplay = false autoplay = false
initial_count = $('.playlist-tracks li').length initial_count = $('.playlist-tracks li').length
for item in tracks for item in tracks
_player.playlist.push item
$('.playlist-tracks').append ' $('.playlist-tracks').append '
<li id="i' +Math.round(Math.random() * 999999)+ '" data-id="'+item.id+'" data-artist="'+item.artist.trim()+'" data-album="'+item.album.trim()+'" data-track="'+item.name.trim()+'" data-length="'+item.length+'"> <li id="i' +Math.round(Math.random() * 999999)+ '" data-id="'+item.id+'">
<div class="item"> <div class="song-duration">' +item.length+ '</div>
<div class="fade"></div> <div class="drag"></div>
<div class="dragbox"></div> <div class="artist-name">' +item.artist+ '</div>
<span class="title"> <div class="song-title">' +item.name+ '</div>
<span class="data artist" title="Open ' +item.artist.htmlsafe()+ '\'s page">' +item.artist+ '</span>
&mdash;
<span class="playtrack" title="Play ' +item.name.htmlsafe()+ ' by ' +item.artist.htmlsafe()+ '">' +item.name+ '</span>
</span>
<span class="duration">' +item.length+ '</span>
<div class="remove">remove</div>
</div>
</li>' </li>'
$('.playlist').sortable axis: 'y', handle: '.drag'
$('.playlist').html($('.playlist-tracks')).scrollbar() # if autoplay
$('.playlist-tracks').sortable axis: 'y', handle: '.dragbox' # _player.setTrack($('.playlist-tracks li').last().attr('id').split('i')[1])
# else if initial_count == 0 and not _player.hasTrack()
if autoplay # _player.setTrack($('.playlist-tracks li').first().attr('id').split('i')[1])
_player.setTrack($('.playlist-tracks li').last().attr('id').split('i')[1])
else if initial_count == 0 and not _player.hasTrack()
_player.setTrack($('.playlist-tracks li').first().attr('id').split('i')[1])
false false
getDataFromLi: (obj) -> getDataFromLi: (obj) ->
@ -226,15 +220,12 @@ $('.playlist-tracks li .title .playtrack').live 'click', ->
# Adding To Playlist actions # Adding To Playlist actions
$('.add-album').live 'click', -> $('.add-album').live 'click', ->
artist = $('.artist-info .name').html() artist = $('.artist-info h2').text()
album = $(this).parent().parent().parent().find('h2.name').text().replace /\s\([\d]{4}\)$/, '' album = _player.albums[$(this).attr('data-album-id')]
tracks = [] for item in album.tracks.album
for item in $(this).parent().parent().parent().find('.tracklist li') item['artist'] = artist
track = _player.getDataFromLi item item['album'] = album.name
track['artist'] = artist _player.addTracks album.tracks.album
track['album'] = album
tracks.push track
_player.addTracks tracks
false false
$('.add-track').live 'click', -> $('.add-track').live 'click', ->

View File

@ -19,6 +19,8 @@ class window.Search
if data.status in ['ok', 'loading'] if data.status in ['ok', 'loading']
_ajax.setArchor '/artist/' +name+ '/' _ajax.setArchor '/artist/' +name+ '/'
_page.print data.html _page.print data.html
for album in data.albums
_player.albums[album.id] = album
_search.hideSpinner() _search.hideSpinner()
if data.status is 'loading' if data.status is 'loading'
setTimeout () -> setTimeout () ->

View File

@ -67,7 +67,7 @@ class ArtistController < ApplicationController
@loading = true @loading = true
end end
@data[:html] = buildArtistHTML(@artist) @data[:albums], @data[:html] = buildArtistHTML(@artist)
render :json => @data render :json => @data
end end
@ -95,7 +95,7 @@ class ArtistController < ApplicationController
end end
end end
(render_to_string :partial => 'page').gsub(/\n\s+/, '').gsub(/\n/, '') return @artist[:albums], (render_to_string :partial => 'page').gsub(/\n\s+/, '').gsub(/\n/, '')
end end
def formatTrackDuration length def formatTrackDuration length

View File

@ -14,7 +14,7 @@
.span4.columns.art .span4.columns.art
%img{ :src => album[:pic] } %img{ :src => album[:pic] }
.button-container .button-container
%a.btn= I18n.t 'player.add' %a.btn.add-album{ :'data-album-id' => album[:id] }= I18n.t 'player.add'
.span7.columns.tracks .span7.columns.tracks
%h3= album[:name] + " (" + album[:year].to_s + ")" %h3= album[:name] + " (" + album[:year].to_s + ")"
%table.zebra-striped.tracklist %table.zebra-striped.tracklist