2015-08-31 17:42:21 +02:00
|
|
|
angular.module('ponyfm').factory('favourites', [
|
2015-10-25 03:35:37 +01:00
|
|
|
'$rootScope', '$http'
|
|
|
|
($rootScope, $http) ->
|
|
|
|
tracksDef = null
|
|
|
|
playlistsDef = null
|
|
|
|
albumsDef = null
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
self
|
|
|
|
])
|