-
Notifications
You must be signed in to change notification settings - Fork 983
/
modal-movie-ctrl.js
104 lines (81 loc) · 2.54 KB
/
modal-movie-ctrl.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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
'use strict';
angular.module('streama').controller('modalMovieCtrl', [
'$scope', '$uibModalInstance', 'apiService', 'movie', '$state', 'uploadService', 'modalService',
function ($scope, $uibModalInstance, apiService, movie, $state, uploadService, modalService) {
$scope.loading = false;
$scope.movie = movie || {};
$scope.movieDB = true;
$scope.hasMovieDBKey = true;
$scope.addManually = ($scope.movie.id && !$scope.movie.apiId);
$scope.chooseNewBackdrop = chooseNewBackdrop;
apiService.theMovieDb.hasKey().success(function (data) {
if (!data.key) {
$scope.hasMovieDBKey = false;
}
});
$scope.saveMovie = function (movie) {
apiService.movie.save(movie).success(function (data) {
$uibModalInstance.close(data);
alertify.success("Movie saved.");
});
};
$scope.toggleAddManually = function () {
$scope.addManually = !$scope.addManually;
};
$scope.selectFromAPI = function ($item) {
console.log('%c selectFromAPI', 'color: deeppink; font-weight: bold; text-shadow: 0 0 5px deeppink;');
var apiId = $item.id;
delete $item.id;
$scope.movie = $item;
$scope.movie.apiId = apiId;
$scope.addManually = false;
$scope.hasMovieDBKey = true;
$scope.formVisible = true;
};
$scope.search = function (query) {
return apiService.theMovieDb.search('movie', query).then(function (data) {
return data.data;
});
};
$scope.imageUpload = {};
$scope.uploadImage = function (files, type) {
uploadService.doUpload($scope.imageUpload, 'file/upload.json', function (data) {
$scope.imageUpload.percentage = null;
if(data.error) return
$scope.movie[type] = data;
$scope.movie[type+'_src'] = data.src;
}, function () {}, files);
};
$scope.onTagSelect = function (tag) {
apiService.tag.save(tag);
};
$scope.tagTransform = function (newTag) {
var item = {
name: newTag,
isNew: true
};
return item;
};
$scope.deleteTag = function (tag) {
alertify.set({ buttonReverse: true, labels: {ok: "Yes", cancel : "Cancel"}});
alertify.confirm('Are you sure you want to delete the tag ' + tag.name, function (confirmed) {
if(confirmed){
apiService.tag.delete(tag.id).success(function () {
_.remove($scope.tags, {id: tag.id});
})
}
});
};
apiService.tag.list().success(function (data) {
$scope.tags = data;
});
setTimeout(function () {
$('.name-input').focus();
}, 200);
$scope.cancel = function () {
$uibModalInstance.dismiss('cancel');
};
function chooseNewBackdrop() {
modalService.openImageChooser('movie', $scope.movie);
}
}]);