2015-08-31 17:42:21 +02:00
|
|
|
angular.module('ponyfm').factory('comments', [
|
2015-10-25 03:35:37 +01:00
|
|
|
'$rootScope', '$http'
|
|
|
|
($rootScope, $http) ->
|
|
|
|
commentCache = []
|
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
|
|
|
addComment: (resourceType, resourceId, content) ->
|
|
|
|
commentDef = new $.Deferred()
|
|
|
|
$http.post('/api/web/comments/' + resourceType + '/' + resourceId, {content: content, _token: pfm.token}).success (comment) ->
|
|
|
|
commentDef.resolve comment
|
2015-08-31 17:42:21 +02:00
|
|
|
|
2015-10-25 03:35:37 +01:00
|
|
|
commentDef.promise()
|
2015-08-31 17:42:21 +02:00
|
|
|
|
2015-10-25 03:35:37 +01:00
|
|
|
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
|
2015-08-31 17:42:21 +02:00
|
|
|
|
2015-10-25 03:35:37 +01:00
|
|
|
commentCache[key] = commentDef.promise()
|
2015-08-31 17:42:21 +02:00
|
|
|
|
2015-10-25 03:35:37 +01:00
|
|
|
self
|
|
|
|
])
|