Pony.fm/public/scripts/app/controllers/account-albums.coffee

46 lines
1.3 KiB
CoffeeScript
Raw Normal View History

2013-07-30 06:53:57 +02:00
window.pfm.preloaders['account-albums'] = [
'account-tracks', 'account-albums'
(tracks, albums) ->
$.when.all [tracks.refresh('published=true&in_album=false', true), albums.refresh(true)]
]
2013-07-28 09:09:10 +02:00
2013-07-30 06:53:57 +02:00
angular.module('ponyfm').controller "account-albums", [
'$scope', '$state', 'account-albums', 'account-tracks'
($scope, $state, albums, tracks) ->
2013-07-28 10:35:31 +02:00
$scope.albums = []
2013-07-28 09:09:10 +02:00
$scope.data =
isEditorOpen: false
selectedAlbum: null
2013-07-30 06:53:57 +02:00
tracksDb: []
selectAlbum = (album) -> $scope.data.selectedAlbum = album
2013-07-30 06:53:57 +02:00
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
2013-07-28 10:35:31 +02:00
2013-07-28 09:09:10 +02:00
$scope.$on '$stateChangeSuccess', () ->
if $state.params.album_id
selectAlbum albumsDb[$state.params.album_id]
else
selectAlbum null
2013-07-28 10:35:31 +02:00
2013-07-30 06:53:57 +02:00
$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
2013-07-28 09:09:10 +02:00
]