Pony.fm/public/scripts/app/controllers/account-albums.coffee
nelsonlaquet 18e41d2af4 Logout
Volume Slider
Track Uploader
Fav list
A bunch of other things
And stuff.
2013-08-30 20:46:35 -05:00

46 lines
No EOL
1.3 KiB
CoffeeScript

window.pfm.preloaders['account-albums'] = [
'account-tracks', 'account-albums'
(tracks, albums) ->
$.when.all [tracks.refresh('published=true&in_album=false', true), albums.refresh(true)]
]
angular.module('ponyfm').controller "account-albums", [
'$scope', '$state', 'account-albums', 'account-tracks'
($scope, $state, albums, tracks) ->
$scope.albums = []
$scope.data =
isEditorOpen: false
selectedAlbum: null
tracksDb: []
selectAlbum = (album) -> $scope.data.selectedAlbum = album
updateTracks = (tracks) ->
$scope.data.tracksDb.push track for track in tracks
tracks.refresh('published=true&in_album=false').done updateTracks
albumsDb = {}
updateAlbums = (albums) ->
$scope.albums.length = 0
for album in albums
$scope.albums.push album
albumsDb[album.id] = album
if $state.params.album_id
selectAlbum albumsDb[$state.params.album_id]
albums.refresh().done updateAlbums
$scope.$on '$stateChangeSuccess', () ->
if $state.params.album_id
selectAlbum albumsDb[$state.params.album_id]
else
selectAlbum null
$scope.$on 'album-created', () -> albums.refresh(true).done(updateAlbums)
$scope.$on 'album-deleted', () -> albums.refresh(true).done(updateAlbums)
$scope.$on 'album-updated', () -> tracks.refresh('published=true&in_album=false', true).done updateTracks
]