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

27 lines
813 B
CoffeeScript
Raw Normal View History

2015-08-31 17:42:21 +02:00
angular.module('ponyfm').factory('comments', [
'$rootScope', '$http'
($rootScope, $http) ->
commentCache = []
self =
filters: {}
addComment: (resourceType, resourceId, content) ->
commentDef = new $.Deferred()
$http.post('/api/web/comments/' + resourceType + '/' + resourceId, {content: content, _token: pfm.token}).success (comment) ->
commentDef.resolve comment
commentDef.promise()
fetchList: (resourceType, resourceId, force) ->
key = resourceType + '-' + resourceId
force = force || false
return commentCache[key] if !force && commentCache[key]
commentDef = new $.Deferred()
$http.get('/api/web/comments/' + resourceType + '/' + resourceId).success (comments) ->
commentDef.resolve comments
commentCache[key] = commentDef.promise()
self
])