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
jp: null
scrobbled: false
albums: []
playlist: []
initJplayer: ->
self = this
@ -51,28 +53,20 @@ class window.Player
autoplay = false
initial_count = $('.playlist-tracks li').length
for item in tracks
_player.playlist.push item
$('.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+'">
<div class="item">
<div class="fade"></div>
<div class="dragbox"></div>
<span class="title">
<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 id="i' +Math.round(Math.random() * 999999)+ '" data-id="'+item.id+'">
<div class="song-duration">' +item.length+ '</div>
<div class="drag"></div>
<div class="artist-name">' +item.artist+ '</div>
<div class="song-title">' +item.name+ '</div>
</li>'
$('.playlist').sortable axis: 'y', handle: '.drag'
$('.playlist').html($('.playlist-tracks')).scrollbar()
$('.playlist-tracks').sortable axis: 'y', handle: '.dragbox'
if autoplay
_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])
# if autoplay
# _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
getDataFromLi: (obj) ->
@ -226,15 +220,12 @@ $('.playlist-tracks li .title .playtrack').live 'click', ->
# Adding To Playlist actions
$('.add-album').live 'click', ->
artist = $('.artist-info .name').html()
album = $(this).parent().parent().parent().find('h2.name').text().replace /\s\([\d]{4}\)$/, ''
tracks = []
for item in $(this).parent().parent().parent().find('.tracklist li')
track = _player.getDataFromLi item
track['artist'] = artist
track['album'] = album
tracks.push track
_player.addTracks tracks
artist = $('.artist-info h2').text()
album = _player.albums[$(this).attr('data-album-id')]
for item in album.tracks.album
item['artist'] = artist
item['album'] = album.name
_player.addTracks album.tracks.album
false
$('.add-track').live 'click', ->

View File

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

View File

@ -67,7 +67,7 @@ class ArtistController < ApplicationController
@loading = true
end
@data[:html] = buildArtistHTML(@artist)
@data[:albums], @data[:html] = buildArtistHTML(@artist)
render :json => @data
end
@ -95,7 +95,7 @@ class ArtistController < ApplicationController
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
def formatTrackDuration length

View File

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