feat(services): add a confirmation modal before deleting one or multiple services (#742)

pull/747/head
Anthony Lapenna 2017-03-30 11:22:59 +02:00 committed by GitHub
parent f9c1941384
commit a48503d821
2 changed files with 29 additions and 6 deletions

View File

@ -1,6 +1,6 @@
angular.module('service', []) angular.module('service', [])
.controller('ServiceController', ['$scope', '$stateParams', '$state', '$location', '$anchorScroll', 'Service', 'ServiceHelper', 'Task', 'Node', 'Messages', 'Pagination', .controller('ServiceController', ['$scope', '$stateParams', '$state', '$location', '$anchorScroll', 'Service', 'ServiceHelper', 'Task', 'Node', 'Messages', 'Pagination', 'ModalService',
function ($scope, $stateParams, $state, $location, $anchorScroll, Service, ServiceHelper, Task, Node, Messages, Pagination) { function ($scope, $stateParams, $state, $location, $anchorScroll, Service, ServiceHelper, Task, Node, Messages, Pagination, ModalService) {
$scope.state = {}; $scope.state = {};
$scope.state.pagination_count = Pagination.getPaginationCount('service_tasks'); $scope.state.pagination_count = Pagination.getPaginationCount('service_tasks');
@ -213,8 +213,17 @@ function ($scope, $stateParams, $state, $location, $anchorScroll, Service, Servi
}); });
}; };
$scope.removeService = function() {
ModalService.confirmDeletion(
'Do you want to delete this service? All the containers associated to this service will be removed too.',
function onConfirm(confirmed) {
if(!confirmed) { return; }
removeService();
}
);
};
$scope.removeService = function removeService() { function removeService() {
$('#loadingViewSpinner').show(); $('#loadingViewSpinner').show();
Service.remove({id: $stateParams.id}, function (d) { Service.remove({id: $stateParams.id}, function (d) {
if (d.message) { if (d.message) {
@ -229,7 +238,7 @@ function ($scope, $stateParams, $state, $location, $anchorScroll, Service, Servi
$('#loadingViewSpinner').hide(); $('#loadingViewSpinner').hide();
Messages.error("Failure", e, "Unable to remove service"); Messages.error("Failure", e, "Unable to remove service");
}); });
}; }
function translateServiceArrays(service) { function translateServiceArrays(service) {
service.ServiceSecrets = service.Secrets; service.ServiceSecrets = service.Secrets;

View File

@ -68,7 +68,17 @@ function ($q, $scope, $stateParams, $state, Service, ServiceHelper, Messages, Pa
}); });
}; };
$scope.removeAction = function () { $scope.removeAction = function() {
ModalService.confirmDeletion(
'Do you want to delete the selected service(s)? All the containers associated to the selected service(s) will be removed too.',
function onConfirm(confirmed) {
if(!confirmed) { return; }
removeServices();
}
);
};
function removeServices() {
$('#loadServicesSpinner').show(); $('#loadServicesSpinner').show();
var counter = 0; var counter = 0;
var complete = function () { var complete = function () {
@ -108,7 +118,11 @@ function ($q, $scope, $stateParams, $state, Service, ServiceHelper, Messages, Pa
}); });
} }
}); });
}; }
// $scope.removeAction = function () {
//
// };
function mapUsersToServices(users) { function mapUsersToServices(users) {
angular.forEach($scope.services, function (service) { angular.forEach($scope.services, function (service) {