2013-08-01 10:57:08 +02:00
|
|
|
angular.module('ponyfm').factory('favourites', [
|
|
|
|
'$rootScope', '$http'
|
|
|
|
($rootScope, $http) ->
|
2013-08-31 03:46:35 +02:00
|
|
|
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()
|
|
|
|
|
2013-08-31 03:46:35 +02:00
|
|
|
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
|
|
|
|
])
|