Pony.fm/public/scripts/app/services/taxonomies.coffee

38 lines
902 B
CoffeeScript
Raw Normal View History

2013-07-25 23:33:04 +02:00
angular.module('ponyfm').factory('taxonomies', [
2013-07-30 06:53:57 +02:00
'$rootScope', '$http'
($rootScope, $http) ->
2013-07-25 23:33:04 +02:00
def = null
self =
2013-07-28 06:37:32 +02:00
trackTypes: []
2013-07-31 13:47:16 +02:00
trackTypesWithTracks: []
2013-07-25 23:33:04 +02:00
licenses: []
genres: []
2013-07-31 13:47:16 +02:00
genresWithTracks: []
2013-07-28 06:37:32 +02:00
showSongs: []
2013-07-31 13:47:16 +02:00
showSongsWithTracks: []
2013-07-25 23:33:04 +02:00
refresh: () ->
2013-07-30 06:53:57 +02:00
return def.promise() if def != null
2013-07-25 23:33:04 +02:00
def = new $.Deferred()
2013-07-30 06:53:57 +02:00
$http.get('/api/web/taxonomies/all')
.success (taxonomies) ->
2013-07-31 13:47:16 +02:00
for t in taxonomies.track_types
self.trackTypes.push t
self.trackTypesWithTracks.push t if t.track_count > 0
for t in taxonomies.genres
self.genres.push t
self.genresWithTracks.push t if t.track_count > 0
for t in taxonomies.show_songs
self.showSongs.push t
self.showSongsWithTracks.push t if t.track_count > 0
2013-07-25 23:33:04 +02:00
self.licenses.push t for t in taxonomies.licenses
def.resolve self
2013-07-30 06:53:57 +02:00
def.promise()
2013-07-25 23:33:04 +02:00
self
])