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

33 lines
1 KiB
CoffeeScript
Raw Normal View History

2015-08-31 17:42:21 +02:00
angular.module('ponyfm').factory('albums', [
2015-10-25 03:35:37 +01:00
'$rootScope', '$http'
($rootScope, $http) ->
albumPages = []
albums = {}
2015-08-31 17:42:21 +02:00
2015-10-25 03:35:37 +01:00
self =
filters: {}
2015-08-31 17:42:21 +02:00
2015-10-25 03:35:37 +01:00
fetchList: (page, force) ->
force = force || false
page = 1 if !page
return albumPages[page] if !force && albumPages[page]
albumsDef = new $.Deferred()
$http.get('/api/web/albums?page=' + page).success (albums) ->
albumsDef.resolve albums
$rootScope.$broadcast 'albums-feteched', albums
2015-08-31 17:42:21 +02:00
2015-10-25 03:35:37 +01:00
albumPages[page] = albumsDef.promise()
2015-08-31 17:42:21 +02:00
2015-10-25 03:35:37 +01:00
fetch: (id, force) ->
force = force || false
id = 1 if !id
return albums[id] if !force && albums[id]
albumsDef = new $.Deferred()
$http.get('/api/web/albums/' + id + '?log=true').success (albums) ->
albumsDef.resolve albums
2015-08-31 17:42:21 +02:00
2015-10-25 03:35:37 +01:00
albums[id] = albumsDef.promise()
2015-08-31 17:42:21 +02:00
2015-10-25 03:35:37 +01:00
self
])