2015-08-31 17:42:21 +02:00
|
|
|
angular.module('ponyfm').factory('images', [
|
2015-10-25 03:35:37 +01:00
|
|
|
'$rootScope'
|
|
|
|
($rootScope) ->
|
|
|
|
def = null
|
|
|
|
self =
|
|
|
|
images: []
|
|
|
|
isLoading: true
|
|
|
|
refresh: (force) ->
|
|
|
|
return def if !force && def
|
|
|
|
def = new $.Deferred()
|
2015-08-31 17:42:21 +02:00
|
|
|
|
2015-10-25 03:35:37 +01:00
|
|
|
self.images = []
|
|
|
|
self.isLoading = true
|
2015-08-31 17:42:21 +02:00
|
|
|
|
2015-10-25 03:35:37 +01:00
|
|
|
$.getJSON('/api/web/images/owned').done (images) -> $rootScope.$apply ->
|
|
|
|
self.images = images
|
|
|
|
self.isLoading = false
|
|
|
|
def.resolve images
|
2015-08-31 17:42:21 +02:00
|
|
|
|
2015-10-25 03:35:37 +01:00
|
|
|
return def
|
2015-08-31 17:42:21 +02:00
|
|
|
|
2015-10-25 03:35:37 +01:00
|
|
|
self.refresh()
|
|
|
|
return self
|
2015-08-31 17:42:21 +02:00
|
|
|
])
|
|
|
|
|