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

28 lines
855 B
CoffeeScript
Raw Normal View History

2015-08-31 17:42:21 +02:00
angular.module('ponyfm').factory('account-albums', [
2015-10-25 03:35:37 +01:00
'$rootScope', '$http'
($rootScope, $http) ->
def = null
albums = []
2015-08-31 17:42:21 +02:00
2015-10-25 03:35:37 +01:00
self =
getEdit: (id, force) ->
url = '/api/web/albums/edit/' + id
force = force || false
return albums[id] if !force && albums[id]
2015-08-31 17:42:21 +02:00
2015-10-25 03:35:37 +01:00
editDef = new $.Deferred()
albums[id] = editDef
$http.get(url).success (album) -> editDef.resolve album
editDef.promise()
2015-08-31 17:42:21 +02:00
2015-10-25 03:35:37 +01:00
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()
2015-08-31 17:42:21 +02:00
2015-10-25 03:35:37 +01:00
self
])