1
|
var blacklistControllers = angular.module('blacklistControllers', []);
|
2
|
|
3
|
function common_init($scope, $http, $sce, $location) {
|
4
|
initSpinner();
|
5
|
$scope.showError = function (error) {
|
6
|
show_notification("error", error);
|
7
|
};
|
8
|
$scope.showNotification = function (message) {
|
9
|
show_notification("info", message);
|
10
|
};
|
11
|
$scope.showSpinner = function () {
|
12
|
showSpinner();
|
13
|
};
|
14
|
$scope.hideSpinner = function () {
|
15
|
hideSpinner();
|
16
|
};
|
17
|
$scope.to_trusted = function (html) {
|
18
|
return $sce.trustAsHtml(html);
|
19
|
};
|
20
|
$scope.go = function (path) {
|
21
|
$location.path(path);
|
22
|
};
|
23
|
$scope.encodeValue = function (val) {
|
24
|
return val;
|
25
|
};
|
26
|
}
|
27
|
|
28
|
blacklistControllers.controller('blacklistCtrl', [
|
29
|
'$scope', '$http', '$sce', '$location', function ($scope, $http, $sce, $location) {
|
30
|
common_init($scope, $http, $sce, $location);
|
31
|
|
32
|
$scope.blacklist = [];
|
33
|
|
34
|
$scope.getBlacklist = function () {
|
35
|
$scope.blacklist = [];
|
36
|
|
37
|
$scope.showSpinner();
|
38
|
|
39
|
$http.get('blacklist/getBlacklist.do').success(function (data) {
|
40
|
$scope.hideSpinner();
|
41
|
$scope.blacklist = data;
|
42
|
}).error(function () {
|
43
|
$scope.showError('Something really bad must have happened to our fellow hamster..');
|
44
|
$scope.hideSpinner();
|
45
|
});
|
46
|
};
|
47
|
|
48
|
$scope.getBlacklist();
|
49
|
|
50
|
$scope.addToBlacklist = function (newEntry) {
|
51
|
$('.modal').modal('hide');
|
52
|
$scope.showSpinner();
|
53
|
$http.post('blacklist/addToBlacklist.do', newEntry).success(function (data) {
|
54
|
if (data === 'false') {
|
55
|
$scope.showError('Cannot add blacklist entry: probably it is a duplicate')
|
56
|
}
|
57
|
else {
|
58
|
$scope.showNotification('Blacklist entry successfully added');
|
59
|
$scope.getBlacklist();
|
60
|
}
|
61
|
}).error(function () {
|
62
|
$scope.showError('ERROR: cannot add blacklist entry');
|
63
|
});
|
64
|
$scope.hideSpinner();
|
65
|
$scope.entry = [];
|
66
|
};
|
67
|
|
68
|
$scope.prepareForEdit = function (entry) {
|
69
|
$scope.entryToEdit = entry;
|
70
|
$('#editBlacklistEntryModal').modal('show');
|
71
|
};
|
72
|
|
73
|
|
74
|
$scope.editBlacklistEntry = function (entry) {
|
75
|
$('.modal').modal('hide');
|
76
|
$scope.showSpinner();
|
77
|
$http.post('blacklist/editBlacklistEntry.do', entry).success(function (data) {
|
78
|
if (data === 'false') {
|
79
|
$scope.showError('Cannot edit entry')
|
80
|
}
|
81
|
else $scope.showNotification('Blacklist entry successfully edited');
|
82
|
}).error(function () {
|
83
|
$scope.showError('ERROR: cannot edit blacklist entry');
|
84
|
});
|
85
|
$scope.hideSpinner();
|
86
|
$scope.entryToEdit = [];
|
87
|
};
|
88
|
|
89
|
$scope.deleteFromBlacklist = function (id) {
|
90
|
var result = confirm("Are you sure you want to delete it?");
|
91
|
if (result) {
|
92
|
$scope.showSpinner();
|
93
|
$http.post('blacklist/deleteFromBlacklist.do', id).success(function (data) {
|
94
|
if (data === 'false') {
|
95
|
$scope.showError('Cannot delete entry')
|
96
|
}
|
97
|
else {
|
98
|
$scope.showNotification('Blacklist entry successfully deleted');
|
99
|
$scope.getBlacklist();
|
100
|
}
|
101
|
|
102
|
}).error(function () {
|
103
|
$scope.showError('ERROR: cannot delete blacklist entry');
|
104
|
});
|
105
|
$scope.hideSpinner();
|
106
|
$scope.entry = [];
|
107
|
}
|
108
|
};
|
109
|
|
110
|
|
111
|
}
|
112
|
]);
|