Pony.fm/resources/assets/scripts/app/services/account-albums.coffee

27 lines
647 B
CoffeeScript
Raw Normal View History

2015-08-31 17:42:21 +02:00
angular.module('ponyfm').factory('account-albums', [
'$rootScope', '$http'
($rootScope, $http) ->
def = null
albums = []
self =
getEdit: (id, force) ->
url = '/api/web/albums/edit/' + id
force = force || false
return albums[id] if !force && albums[id]
editDef = new $.Deferred()
albums[id] = editDef
$http.get(url).success (album) -> editDef.resolve album
editDef.promise()
refresh: (force) ->
force = force || false
return def if !force && def
def = new $.Deferred()
$http.get('/api/web/albums/owned').success (ownedAlbums) ->
def.resolve(ownedAlbums)
def.promise()
self
])