Add remove button for tracks in playlists.

Resolves #3
This commit is contained in:
Mihail-K 2016-03-20 16:27:22 -04:00
parent 4a5c2418eb
commit fb2997c2e9
3 changed files with 16 additions and 4 deletions

View file

@ -12,6 +12,9 @@
<a pfm-eat-click class="icon-favourite" href="#" ng-click="toggleFavourite(track)" ng-if="::auth.isLogged"> <a pfm-eat-click class="icon-favourite" href="#" ng-click="toggleFavourite(track)" ng-if="::auth.isLogged">
<i class="icon-star-empty"></i> <i class="icon-star-empty"></i>
</a> </a>
<a pfm-eat-click href="#" ng-click="removeFromPlaylist(track)" ng-if="::canModifyPlaylist()">
<i class="icon-trash"></i>
</a>
</div> </div>
<a class="info" ng-href="{{::track.url}}"> <a class="info" ng-href="{{::track.url}}">
<span class="title">{{::track.title}}</span> <span class="title">{{::track.title}}</span>

View file

@ -57,7 +57,7 @@
</div> </div>
<h2>Tracks</h2> <h2>Tracks</h2>
<pfm-tracks-list tracks="::playlist.tracks"></pfm-tracks-list> <pfm-tracks-list tracks="::playlist.tracks" playlist="::playlist"></pfm-tracks-list>
<pfm-comments type="playlist" resource="::playlist"></pfm-comments> <pfm-comments type="playlist" resource="::playlist"></pfm-comments>
</div> </div>

View file

@ -19,14 +19,23 @@ module.exports = angular.module('ponyfm').directive 'pfmTracksList', () ->
templateUrl: '/templates/directives/tracks-list.html' templateUrl: '/templates/directives/tracks-list.html'
replace: true replace: true
scope: scope:
tracks: '=tracks', playlist: '='
tracks: '=tracks'
class: '@class' class: '@class'
controller: [ controller: [
'$scope', 'favourites', 'player', 'auth' '$scope', 'favourites', 'player', 'playlists', 'auth'
($scope, favourites, player, auth) -> ($scope, favourites, player, playlists, auth) ->
$scope.auth = auth.data $scope.auth = auth.data
$scope.canModifyPlaylist = ->
$scope.playlist and $scope.auth.isLogged and $scope.playlist.user.id == $scope.auth.user.id
$scope.removeFromPlaylist = (track) ->
playlists.removeTrackFromPlaylist $scope.playlist?.id, track.id
.done ->
$scope.tracks = _.reject $scope.tracks, (t) -> t.id == track.id
$scope.toggleFavourite = (track) -> $scope.toggleFavourite = (track) ->
favourites.toggle('track', track.id).done (res) -> favourites.toggle('track', track.id).done (res) ->
track.user_data.is_favourited = res.is_favourited track.user_data.is_favourited = res.is_favourited