Pony.fm/resources/assets/scripts/app/directives/favouriteButton.coffee

21 lines
586 B
CoffeeScript
Raw Normal View History

2015-08-31 17:42:21 +02:00
angular.module('ponyfm').directive 'pfmFavouriteButton', () ->
restrict: 'E'
templateUrl: '/templates/directives/favourite-button.html'
scope:
resource: '=resource',
class: '@class',
type: '@type'
replace: true
controller: [
'$scope', 'favourites', 'auth'
($scope, favourites, auth) ->
$scope.auth = auth.data
$scope.isWorking = false
$scope.toggleFavourite = () ->
$scope.isWorking = true
favourites.toggle($scope.type, $scope.resource.id).done (res) ->
$scope.isWorking = false
$scope.resource.user_data.is_favourited = res.is_favourited
]