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

41 lines
1,016 B
CoffeeScript
Raw Normal View History

2013-08-01 10:57:08 +02:00
angular.module('ponyfm').factory('favourites', [
'$rootScope', '$http'
($rootScope, $http) ->
tracksDef = null
playlistsDef = null
albumsDef = null
2013-08-01 10:57:08 +02:00
self =
toggle: (type, id) ->
def = new $.Deferred()
$http.post('/api/web/favourites/toggle', {type: type, id: id, _token: pfm.token}).success (res) ->
def.resolve res
def.promise()
fetchTracks: (force) ->
return tracksDef if !force && tracksDef
tracksDef = new $.Deferred()
$http.get('/api/web/favourites/tracks').success (res) ->
tracksDef.resolve res
tracksDef
fetchAlbums: (force) ->
return albumsDef if !force && albumsDef
albumsDef = new $.Deferred()
$http.get('/api/web/favourites/albums').success (res) ->
albumsDef.resolve res
albumsDef
fetchPlaylists: (force) ->
return playlistsDef if !force && playlistsDef
playlistsDef = new $.Deferred()
$http.get('/api/web/favourites/playlists').success (res) ->
playlistsDef.resolve res
playlistsDef
2013-08-01 10:57:08 +02:00
self
])