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

44 lines
1.2 KiB
CoffeeScript
Raw Normal View History

2013-07-30 06:53:57 +02:00
window.pfm.preloaders['account-tracks'] = [
'account-tracks', 'account-albums', 'taxonomies'
(tracks, albums, taxonomies) ->
$.when.all [tracks.refresh(null, true), albums.refresh(true), taxonomies.refresh()]
]
2013-07-28 09:09:10 +02:00
angular.module('ponyfm').controller "account-tracks", [
2013-07-30 06:53:57 +02:00
'$scope', '$state', 'taxonomies', '$dialog', 'lightbox', 'account-albums', 'account-tracks'
($scope, $state, taxonomies, $dialog, lightbox, albums, tracks) ->
$scope.data =
selectedTrack: null
$scope.tracks = []
2013-07-28 19:45:21 +02:00
tracksDb = {}
2013-07-28 08:07:25 +02:00
2013-07-30 06:53:57 +02:00
setTracks = (tracks) ->
$scope.tracks.length = 0
tracksDb = {}
for track in tracks
tracksDb[track.id] = track
$scope.tracks.push track
if $state.params.track_id
$scope.data.selectedTrack = tracksDb[$state.params.track_id]
tracks.refresh().done setTracks
2013-07-25 23:33:04 +02:00
$scope.refreshList = () ->
tracks.refresh().done setTracks
2013-07-25 23:33:04 +02:00
2013-07-30 06:53:57 +02:00
$scope.selectTrack = (track) ->
$scope.data.selectedTrack = track
2013-07-25 23:33:04 +02:00
$scope.$on '$stateChangeSuccess', () ->
if $state.params.track_id
2013-07-30 06:53:57 +02:00
$scope.selectTrack tracksDb[$state.params.track_id]
2013-07-25 23:33:04 +02:00
else
2013-07-30 06:53:57 +02:00
$scope.selectTrack null
2013-07-28 19:45:21 +02:00
2013-07-30 06:53:57 +02:00
$scope.$on 'track-deleted', () ->
tracks.clearCache()
$scope.refreshList()
2013-07-25 23:33:04 +02:00
]