2013-08-01 10:57:08 +02:00
|
|
|
angular.module('ponyfm').directive 'pfmFavouriteButton', () ->
|
|
|
|
restrict: 'E'
|
|
|
|
templateUrl: '/templates/directives/favourite-button.html'
|
|
|
|
scope:
|
|
|
|
resource: '=resource',
|
|
|
|
class: '@class',
|
|
|
|
type: '@type'
|
2013-08-23 02:48:40 +02:00
|
|
|
replace: true
|
2013-08-01 10:57:08 +02:00
|
|
|
|
|
|
|
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
|
2013-08-19 05:39:29 +02:00
|
|
|
$scope.resource.user_data.is_favourited = res.is_favourited
|
2013-08-01 10:57:08 +02:00
|
|
|
]
|