2013-07-25 16:33:04 -05:00
|
|
|
angular.module('ponyfm').factory('taxonomies', [
|
2013-07-29 23:53:57 -05:00
|
|
|
'$rootScope', '$http'
|
|
|
|
($rootScope, $http) ->
|
2013-07-25 16:33:04 -05:00
|
|
|
def = null
|
|
|
|
|
|
|
|
self =
|
2013-07-27 23:37:32 -05:00
|
|
|
trackTypes: []
|
2013-07-31 06:47:16 -05:00
|
|
|
trackTypesWithTracks: []
|
2013-07-25 16:33:04 -05:00
|
|
|
licenses: []
|
|
|
|
genres: []
|
2013-07-31 06:47:16 -05:00
|
|
|
genresWithTracks: []
|
2013-07-27 23:37:32 -05:00
|
|
|
showSongs: []
|
2013-07-31 06:47:16 -05:00
|
|
|
showSongsWithTracks: []
|
2013-07-25 16:33:04 -05:00
|
|
|
refresh: () ->
|
2013-07-29 23:53:57 -05:00
|
|
|
return def.promise() if def != null
|
2013-07-25 16:33:04 -05:00
|
|
|
|
|
|
|
def = new $.Deferred()
|
2013-07-29 23:53:57 -05:00
|
|
|
$http.get('/api/web/taxonomies/all')
|
|
|
|
.success (taxonomies) ->
|
2013-07-31 06:47:16 -05: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 16:33:04 -05:00
|
|
|
self.licenses.push t for t in taxonomies.licenses
|
|
|
|
def.resolve self
|
2013-07-29 23:53:57 -05:00
|
|
|
|
|
|
|
def.promise()
|
2013-07-25 16:33:04 -05:00
|
|
|
|
|
|
|
self
|
|
|
|
])
|