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() {
|
module.filter('remove', function() {
|
||||||
return function(input, remove) {
|
return function(input, remove) {
|
||||||
|
if (!input || !remove) {
|
||||||
|
return input;
|
||||||
|
}
|
||||||
|
|
||||||
var out = [];
|
var out = [];
|
||||||
for (var i = 0; i < input.length; i++) {
|
for (var i = 0; i < input.length; i++) {
|
||||||
if (remove.indexOf(input[i]) == -1) {
|
if (remove.indexOf(input[i]) == -1) {
|
||||||
|
|
|
@ -20,7 +20,7 @@ module.controller('ApplicationListCtrl', function($scope, applications) {
|
||||||
$scope.applications = 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) {
|
Notifications) {
|
||||||
$scope.application = angular.copy(application);
|
$scope.application = angular.copy(application);
|
||||||
$scope.applications = applications;
|
$scope.applications = applications;
|
||||||
|
@ -41,6 +41,7 @@ module.controller('ApplicationDetailCtrl', function($scope, applications, applic
|
||||||
|
|
||||||
$scope.addRole = function() {
|
$scope.addRole = function() {
|
||||||
if ($scope.newRole) {
|
if ($scope.newRole) {
|
||||||
|
if ($scope.application.roles) {
|
||||||
for ( var i = 0; i < $scope.application.roles.length; i++) {
|
for ( var i = 0; i < $scope.application.roles.length; i++) {
|
||||||
if ($scope.application.roles[i] == $scope.newRole) {
|
if ($scope.application.roles[i] == $scope.newRole) {
|
||||||
Notifications.warn("Role already exists");
|
Notifications.warn("Role already exists");
|
||||||
|
@ -48,6 +49,7 @@ module.controller('ApplicationDetailCtrl', function($scope, applications, applic
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (!$scope.application.roles) {
|
if (!$scope.application.roles) {
|
||||||
$scope.application.roles = [];
|
$scope.application.roles = [];
|
||||||
|
@ -59,11 +61,13 @@ module.controller('ApplicationDetailCtrl', function($scope, applications, applic
|
||||||
}
|
}
|
||||||
|
|
||||||
$scope.removeRole = function(role) {
|
$scope.removeRole = function(role) {
|
||||||
|
Dialog.confirmDelete(role, 'role', function() {
|
||||||
var i = $scope.application.roles.indexOf(role);
|
var i = $scope.application.roles.indexOf(role);
|
||||||
if (i > -1) {
|
if (i > -1) {
|
||||||
$scope.application.roles.splice(i, 1);
|
$scope.application.roles.splice(i, 1);
|
||||||
}
|
}
|
||||||
$scope.removeInitialRole(role);
|
$scope.removeInitialRole(role);
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
$scope.addInitialRole = function() {
|
$scope.addInitialRole = function() {
|
||||||
|
@ -116,24 +120,11 @@ module.controller('ApplicationDetailCtrl', function($scope, applications, applic
|
||||||
};
|
};
|
||||||
|
|
||||||
$scope.remove = function() {
|
$scope.remove = function() {
|
||||||
var title = 'Delete ' + $scope.application.name;
|
Dialog.confirmDelete($scope.application.name, 'application', function() {
|
||||||
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") {
|
|
||||||
$scope.application.$remove(function() {
|
$scope.application.$remove(function() {
|
||||||
$location.url("/applications");
|
$location.url("/applications");
|
||||||
Notifications.success("Deleted application");
|
Notifications.success("Deleted application");
|
||||||
});
|
});
|
||||||
}
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -207,7 +198,7 @@ module.controller('UserListCtrl', function($scope, realms, realm, users) {
|
||||||
$scope.users = 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.realms = realms;
|
||||||
$scope.realm = realm;
|
$scope.realm = realm;
|
||||||
$scope.user = angular.copy(user);
|
$scope.user = angular.copy(user);
|
||||||
|
@ -252,19 +243,7 @@ module.controller('UserDetailCtrl', function($scope, realms, realm, user, User,
|
||||||
};
|
};
|
||||||
|
|
||||||
$scope.remove = function() {
|
$scope.remove = function() {
|
||||||
var title = 'Delete ' + $scope.user.userId;
|
Dialog.confirmDelete($scope.user.userId, 'user', function() {
|
||||||
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") {
|
|
||||||
$scope.user.$remove({
|
$scope.user.$remove({
|
||||||
realmKey : realm.key,
|
realmKey : realm.key,
|
||||||
userId : $scope.user.userId
|
userId : $scope.user.userId
|
||||||
|
@ -272,12 +251,11 @@ module.controller('UserDetailCtrl', function($scope, realms, realm, user, User,
|
||||||
$location.url("/realms/" + realm.key + "/users");
|
$location.url("/realms/" + realm.key + "/users");
|
||||||
Notifications.success("Deleted user");
|
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.realms = realms;
|
||||||
$scope.realm = angular.copy(realm);
|
$scope.realm = angular.copy(realm);
|
||||||
$scope.create = !realm.name;
|
$scope.create = !realm.name;
|
||||||
|
@ -292,6 +270,7 @@ module.controller('RealmDetailCtrl', function($scope, Realm, realms, realm, $loc
|
||||||
|
|
||||||
$scope.addRole = function() {
|
$scope.addRole = function() {
|
||||||
if ($scope.newRole) {
|
if ($scope.newRole) {
|
||||||
|
if ($scope.realm.roles) {
|
||||||
for ( var i = 0; i < $scope.realm.roles.length; i++) {
|
for ( var i = 0; i < $scope.realm.roles.length; i++) {
|
||||||
if ($scope.realm.roles[i] == $scope.newRole) {
|
if ($scope.realm.roles[i] == $scope.newRole) {
|
||||||
Notifications.warn("Role already exists");
|
Notifications.warn("Role already exists");
|
||||||
|
@ -299,6 +278,7 @@ module.controller('RealmDetailCtrl', function($scope, Realm, realms, realm, $loc
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (!$scope.realm.roles) {
|
if (!$scope.realm.roles) {
|
||||||
$scope.realm.roles = [];
|
$scope.realm.roles = [];
|
||||||
|
@ -310,11 +290,13 @@ module.controller('RealmDetailCtrl', function($scope, Realm, realms, realm, $loc
|
||||||
}
|
}
|
||||||
|
|
||||||
$scope.removeRole = function(role) {
|
$scope.removeRole = function(role) {
|
||||||
|
Dialog.confirmDelete(role, 'role', function() {
|
||||||
var i = $scope.realm.roles.indexOf(role);
|
var i = $scope.realm.roles.indexOf(role);
|
||||||
if (i > -1) {
|
if (i > -1) {
|
||||||
$scope.realm.roles.splice(i, 1);
|
$scope.realm.roles.splice(i, 1);
|
||||||
}
|
}
|
||||||
$scope.removeInitialRole(role);
|
$scope.removeInitialRole(role);
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
$scope.addInitialRole = function() {
|
$scope.addInitialRole = function() {
|
||||||
|
@ -367,24 +349,11 @@ module.controller('RealmDetailCtrl', function($scope, Realm, realms, realm, $loc
|
||||||
};
|
};
|
||||||
|
|
||||||
$scope.remove = function() {
|
$scope.remove = function() {
|
||||||
var title = 'Delete ' + $scope.realm.name;
|
Dialog.confirmDelete($scope.realm.name, 'realm', function() {
|
||||||
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") {
|
|
||||||
Realm.remove($scope.realm, function() {
|
Realm.remove($scope.realm, function() {
|
||||||
$location.url("/realms");
|
$location.url("/realms");
|
||||||
Notifications.success("Deleted realm");
|
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) {
|
module.service('Auth', function($resource, $http, $location, $routeParams) {
|
||||||
var auth = {
|
var auth = {
|
||||||
loggedIn : true
|
loggedIn : true
|
||||||
|
|
Loading…
Reference in a new issue