Added confirmation when removing role from app or realm
This commit is contained in:
parent
2c8ea5d368
commit
362cf14d49
3 changed files with 79 additions and 83 deletions
|
@ -203,6 +203,10 @@ module.directive('kcEnter', function() {
|
|||
|
||||
module.filter('remove', function() {
|
||||
return function(input, remove) {
|
||||
if (!input || !remove) {
|
||||
return input;
|
||||
}
|
||||
|
||||
var out = [];
|
||||
for (var i = 0; i < input.length; i++) {
|
||||
if (remove.indexOf(input[i]) == -1) {
|
||||
|
|
|
@ -20,7 +20,7 @@ module.controller('ApplicationListCtrl', function($scope, applications) {
|
|||
$scope.applications = applications;
|
||||
});
|
||||
|
||||
module.controller('ApplicationDetailCtrl', function($scope, applications, application, Application, realms, providers, $location, $window, $dialog,
|
||||
module.controller('ApplicationDetailCtrl', function($scope, applications, application, Application, realms, providers, $location, $window, Dialog,
|
||||
Notifications) {
|
||||
$scope.application = angular.copy(application);
|
||||
$scope.applications = applications;
|
||||
|
@ -41,6 +41,7 @@ module.controller('ApplicationDetailCtrl', function($scope, applications, applic
|
|||
|
||||
$scope.addRole = function() {
|
||||
if ($scope.newRole) {
|
||||
if ($scope.application.roles) {
|
||||
for ( var i = 0; i < $scope.application.roles.length; i++) {
|
||||
if ($scope.application.roles[i] == $scope.newRole) {
|
||||
Notifications.warn("Role already exists");
|
||||
|
@ -48,6 +49,7 @@ module.controller('ApplicationDetailCtrl', function($scope, applications, applic
|
|||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!$scope.application.roles) {
|
||||
$scope.application.roles = [];
|
||||
|
@ -59,11 +61,13 @@ module.controller('ApplicationDetailCtrl', function($scope, applications, applic
|
|||
}
|
||||
|
||||
$scope.removeRole = function(role) {
|
||||
Dialog.confirmDelete(role, 'role', function() {
|
||||
var i = $scope.application.roles.indexOf(role);
|
||||
if (i > -1) {
|
||||
$scope.application.roles.splice(i, 1);
|
||||
}
|
||||
$scope.removeInitialRole(role);
|
||||
});
|
||||
};
|
||||
|
||||
$scope.addInitialRole = function() {
|
||||
|
@ -116,24 +120,11 @@ module.controller('ApplicationDetailCtrl', function($scope, applications, applic
|
|||
};
|
||||
|
||||
$scope.remove = function() {
|
||||
var title = 'Delete ' + $scope.application.name;
|
||||
var msg = 'Are you sure you want to permanently delete this application?';
|
||||
var btns = [ {
|
||||
result : 'cancel',
|
||||
label : 'Cancel'
|
||||
}, {
|
||||
result : 'ok',
|
||||
label : 'Delete this application',
|
||||
cssClass : 'btn-primary'
|
||||
} ];
|
||||
|
||||
$dialog.messageBox(title, msg, btns).open().then(function(result) {
|
||||
if (result == "ok") {
|
||||
Dialog.confirmDelete($scope.application.name, 'application', function() {
|
||||
$scope.application.$remove(function() {
|
||||
$location.url("/applications");
|
||||
Notifications.success("Deleted application");
|
||||
});
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
|
@ -207,7 +198,7 @@ module.controller('UserListCtrl', function($scope, realms, realm, users) {
|
|||
$scope.users = users;
|
||||
});
|
||||
|
||||
module.controller('UserDetailCtrl', function($scope, realms, realm, user, User, $location, $dialog, Notifications) {
|
||||
module.controller('UserDetailCtrl', function($scope, realms, realm, user, User, $location, Dialog, Notifications) {
|
||||
$scope.realms = realms;
|
||||
$scope.realm = realm;
|
||||
$scope.user = angular.copy(user);
|
||||
|
@ -252,19 +243,7 @@ module.controller('UserDetailCtrl', function($scope, realms, realm, user, User,
|
|||
};
|
||||
|
||||
$scope.remove = function() {
|
||||
var title = 'Delete ' + $scope.user.userId;
|
||||
var msg = 'Are you sure you want to permanently delete this user?';
|
||||
var btns = [ {
|
||||
result : 'cancel',
|
||||
label : 'Cancel'
|
||||
}, {
|
||||
result : 'ok',
|
||||
label : 'Delete this user',
|
||||
cssClass : 'btn-primary'
|
||||
} ];
|
||||
|
||||
$dialog.messageBox(title, msg, btns).open().then(function(result) {
|
||||
if (result == "ok") {
|
||||
Dialog.confirmDelete($scope.user.userId, 'user', function() {
|
||||
$scope.user.$remove({
|
||||
realmKey : realm.key,
|
||||
userId : $scope.user.userId
|
||||
|
@ -272,12 +251,11 @@ module.controller('UserDetailCtrl', function($scope, realms, realm, user, User,
|
|||
$location.url("/realms/" + realm.key + "/users");
|
||||
Notifications.success("Deleted user");
|
||||
});
|
||||
}
|
||||
});
|
||||
};
|
||||
});
|
||||
|
||||
module.controller('RealmDetailCtrl', function($scope, Realm, realms, realm, $location, $dialog, Notifications) {
|
||||
module.controller('RealmDetailCtrl', function($scope, Realm, realms, realm, $location, Dialog, Notifications) {
|
||||
$scope.realms = realms;
|
||||
$scope.realm = angular.copy(realm);
|
||||
$scope.create = !realm.name;
|
||||
|
@ -292,6 +270,7 @@ module.controller('RealmDetailCtrl', function($scope, Realm, realms, realm, $loc
|
|||
|
||||
$scope.addRole = function() {
|
||||
if ($scope.newRole) {
|
||||
if ($scope.realm.roles) {
|
||||
for ( var i = 0; i < $scope.realm.roles.length; i++) {
|
||||
if ($scope.realm.roles[i] == $scope.newRole) {
|
||||
Notifications.warn("Role already exists");
|
||||
|
@ -299,6 +278,7 @@ module.controller('RealmDetailCtrl', function($scope, Realm, realms, realm, $loc
|
|||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!$scope.realm.roles) {
|
||||
$scope.realm.roles = [];
|
||||
|
@ -310,11 +290,13 @@ module.controller('RealmDetailCtrl', function($scope, Realm, realms, realm, $loc
|
|||
}
|
||||
|
||||
$scope.removeRole = function(role) {
|
||||
Dialog.confirmDelete(role, 'role', function() {
|
||||
var i = $scope.realm.roles.indexOf(role);
|
||||
if (i > -1) {
|
||||
$scope.realm.roles.splice(i, 1);
|
||||
}
|
||||
$scope.removeInitialRole(role);
|
||||
});
|
||||
};
|
||||
|
||||
$scope.addInitialRole = function() {
|
||||
|
@ -367,24 +349,11 @@ module.controller('RealmDetailCtrl', function($scope, Realm, realms, realm, $loc
|
|||
};
|
||||
|
||||
$scope.remove = function() {
|
||||
var title = 'Delete ' + $scope.realm.name;
|
||||
var msg = 'Are you sure you want to permanently delete this realm?';
|
||||
var btns = [ {
|
||||
result : 'cancel',
|
||||
label : 'Cancel'
|
||||
}, {
|
||||
result : 'ok',
|
||||
label : 'Delete this realm',
|
||||
cssClass : 'btn-primary'
|
||||
} ];
|
||||
|
||||
$dialog.messageBox(title, msg, btns).open().then(function(result) {
|
||||
if (result == "ok") {
|
||||
Dialog.confirmDelete($scope.realm.name, 'realm', function() {
|
||||
Realm.remove($scope.realm, function() {
|
||||
$location.url("/realms");
|
||||
Notifications.success("Deleted realm");
|
||||
});
|
||||
}
|
||||
});
|
||||
};
|
||||
});
|
|
@ -184,6 +184,29 @@ module.factory('UserLoader', function(User, $route, $q) {
|
|||
};
|
||||
});
|
||||
|
||||
module.service('Dialog', function($dialog) {
|
||||
var dialog = {};
|
||||
dialog.confirmDelete = function(name, type, success) {
|
||||
var title = 'Delete ' + name;
|
||||
var msg = 'Are you sure you want to permanently delete this ' + type + '?';
|
||||
var btns = [ {
|
||||
result : 'cancel',
|
||||
label : 'Cancel'
|
||||
}, {
|
||||
result : 'ok',
|
||||
label : 'Delete this ' + type,
|
||||
cssClass : 'btn-primary'
|
||||
} ];
|
||||
|
||||
$dialog.messageBox(title, msg, btns).open().then(function(result) {
|
||||
if (result == "ok") {
|
||||
success();
|
||||
}
|
||||
});
|
||||
}
|
||||
return dialog
|
||||
});
|
||||
|
||||
module.service('Auth', function($resource, $http, $location, $routeParams) {
|
||||
var auth = {
|
||||
loggedIn : true
|
||||
|
|
Loading…
Reference in a new issue