/
streama-dash-media-item.js
85 lines (75 loc) · 2.6 KB
/
streama-dash-media-item.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
//= wrapped
angular.module('streama').directive('streamaDashMediaItem', function () {
return {
restrict: 'E',
templateUrl: '/streama/directive--streama-dash-media-item.htm',
scope: {
entity: '='
},
bindToController: true,
controllerAs: 'vm',
controller: controller
}
});
function controller(apiService, modalService, $rootScope, $state, $scope) {
var vm = this;
vm.fetchFirstEpisodeAndPlay = fetchFirstEpisodeAndPlay;
vm.showDetails = showDetails;
vm.handleWatchlistUpdate = handleWatchlistUpdate;
vm.markCompleted = markCompleted;
$scope.$on('video.markAsUnviewed', onVideoMarkAsUnviewed);
function fetchFirstEpisodeAndPlay(tvShow) {
apiService.dash.firstEpisodeForShow(tvShow.id).then(function (response) {
$state.go('player', {videoId: response.data.id});
});
}
function showDetails(media) {
if(media.mediaType === 'episode'){
modalService.mediaDetailModal({mediaId: media.tvShowId, mediaType: 'tvShow', isApiMovie: false});
}else{
modalService.mediaDetailModal({mediaId: media.id, mediaType: media.mediaType, isApiMovie: false}, function (response) {
$rootScope.$broadcast('video.updateWatchlist', {response: response, media: media});
});
}
}
function handleWatchlistUpdate(action, item){
switch (action) {
case "added":
addToWatchlist(item);
break;
case "removed":
removeFromWatchlist(item);
break;
}
}
function addToWatchlist(item) {
apiService.watchlistEntry.create(item).then(function (response) {
$rootScope.$broadcast('video.updateWatchlist', {action: 'added', response: response, media: item});
});
}
function removeFromWatchlist(item) {
alertify.set({buttonReverse: true, labels: {ok: "Yes", cancel: "Cancel"}});
alertify.confirm("Are you sure you want to remove this video from your watchlist?", function (confirmed) {
if (confirmed) {
apiService.watchlistEntry.delete(item).then(function (response) {
$rootScope.$broadcast('video.updateWatchlist', {action: 'removed', media: item});
});
}
});
}
function markCompleted() {
alertify.set({buttonReverse: true, labels: {ok: "Yes", cancel: "Cancel"}});
alertify.confirm("Are you sure you want to mark this video as completed?", function (confirmed) {
if (confirmed) {
apiService.video.markCompleted({id: vm.entity.id}).then(function (data) {
vm.entity.deleted = true;
});
}
})
}
function onVideoMarkAsUnviewed(e, data) {
if(data.id === vm.entity.id){
vm.entity.status = 'unviewed';
}
}
}