Tweaked adding/removing roles to realm and applications

This commit is contained in:
Stian Thorgersen 2013-07-25 15:25:39 +01:00
parent 4952849526
commit 2c8ea5d368
5 changed files with 231 additions and 174 deletions

View file

@ -200,3 +200,15 @@ module.directive('kcEnter', function() {
});
};
});
module.filter('remove', function() {
return function(input, remove) {
var out = [];
for (var i = 0; i < input.length; i++) {
if (remove.indexOf(input[i]) == -1) {
out.push(input[i]);
}
}
return out;
};
});

View file

@ -39,9 +39,16 @@ module.controller('ApplicationDetailCtrl', function($scope, applications, applic
}
}, true);
$scope.addRole = function() {
if ($scope.newRole) {
for (var i = 0; i < $scope.application.roles.length; i++) {
if ($scope.application.roles[i] == $scope.newRole) {
Notifications.warn("Role already exists");
$scope.newRole = null;
return;
}
}
if (!$scope.application.roles) {
$scope.application.roles = [];
}
@ -51,8 +58,12 @@ module.controller('ApplicationDetailCtrl', function($scope, applications, applic
}
}
$scope.removeRole = function(i) {
$scope.removeRole = function(role) {
var i = $scope.application.roles.indexOf(role);
if (i > -1) {
$scope.application.roles.splice(i, 1);
}
$scope.removeInitialRole(role);
};
$scope.addInitialRole = function() {
@ -66,8 +77,11 @@ module.controller('ApplicationDetailCtrl', function($scope, applications, applic
}
}
$scope.removeInitialRole = function(i) {
$scope.removeInitialRole = function(role) {
var i = $scope.application.initialRoles.indexOf(role);
if (i > -1) {
$scope.application.initialRoles.splice(i, 1);
}
};
$scope.save = function() {
@ -278,6 +292,14 @@ module.controller('RealmDetailCtrl', function($scope, Realm, realms, realm, $loc
$scope.addRole = function() {
if ($scope.newRole) {
for (var i = 0; i < $scope.realm.roles.length; i++) {
if ($scope.realm.roles[i] == $scope.newRole) {
Notifications.warn("Role already exists");
$scope.newRole = null;
return;
}
}
if (!$scope.realm.roles) {
$scope.realm.roles = [];
}
@ -287,8 +309,12 @@ module.controller('RealmDetailCtrl', function($scope, Realm, realms, realm, $loc
}
}
$scope.removeRole = function(i) {
$scope.removeRole = function(role) {
var i = $scope.realm.roles.indexOf(role);
if (i > -1) {
$scope.realm.roles.splice(i, 1);
}
$scope.removeInitialRole(role);
};
$scope.addInitialRole = function() {
@ -302,8 +328,11 @@ module.controller('RealmDetailCtrl', function($scope, Realm, realms, realm, $loc
}
}
$scope.removeInitialRole = function(i) {
$scope.removeInitialRole = function(role) {
var i = $scope.realm.initialRoles.indexOf(role);
if (i > -1) {
$scope.realm.initialRoles.splice(i, 1);
}
};
$scope.save = function() {

View file

@ -21,13 +21,29 @@ module.factory('Notifications', function($rootScope, $timeout) {
$rootScope.notifications = [];
}
notifications.success = function(message) {
notifications.message = function(type, message) {
$rootScope.notification = {
type : "success",
type : type,
message : message
};
schedulePop();
}
notifications.info = function(message) {
notifications.message("info", message);
};
notifications.success = function(message) {
notifications.message("success", message);
};
notifications.error = function(message) {
notifications.message("error", message);
};
notifications.warn = function(message) {
notifications.message("warn", message);
};
return notifications;

View file

@ -42,7 +42,7 @@
<div class="control-group">
<label class="control-label">Roles</label>
<div class="controls">
<span style="margin-right: 1em;" data-ng-repeat="r in application.roles">{{r}} <button data-ng-click="removeRole($index)"><i class="icon-remove"></i></button></span>
<span class="label" style="margin-right: 1em;" data-ng-repeat="r in (application.roles|orderBy:'toString()')">{{r}} <button data-ng-click="removeRole(r)"><i class="icon-remove icon-white"></i></button></span>
<div class="input-append">
<input class="input-small" type="text" data-ng-model="newRole" placeHolder="Role" data-kc-enter="addRole()" />
@ -54,11 +54,11 @@
<div class="control-group">
<label class="control-label">Initial Roles</label>
<div class="controls">
<span style="margin-right: 1em;" data-ng-repeat="r in application.initialRoles">{{r}} <button data-ng-click="removeInitialRole($index)"><i class="icon-remove"></i></button></span>
<span class="label" style="margin-right: 1em;" data-ng-repeat="r in (application.initialRoles|orderBy:'toString()')">{{r}} <button data-ng-click="removeInitialRole(r)"><i class="icon-remove icon-white"></i></button></span>
<div class="input-append">
<select style="width: auto;" data-ng-model="newInitialRole" data-ng-click="addInitialRole()">
<option data-ng-repeat="r in application.roles" value="{{r}}">{{r}}</option>
<option data-ng-repeat="r in (application.roles|remove:application.initialRoles|orderBy:'toString()')" value="{{r}}">{{r}}</option>
</select>
</div>
</div>

View file

@ -56,7 +56,7 @@
<div class="control-group">
<label class="control-label">Roles</label>
<div class="controls">
<span style="margin-right: 1em;" data-ng-repeat="r in realm.roles">{{r}} <button data-ng-click="removeRole($index)"><i class="icon-remove"></i></button></span>
<span class="label" style="margin-right: 1em;" data-ng-repeat="r in (realm.roles|orderBy:'toString()')">{{r}} <button data-ng-click="removeRole(r)"><i class="icon-remove icon-white"></i></button></span>
<div class="input-append">
<input class="input-small" type="text" data-ng-model="newRole" placeHolder="Role" data-kc-enter="addRole()" />
@ -68,11 +68,11 @@
<div class="control-group">
<label class="control-label">Initial Roles</label>
<div class="controls">
<span style="margin-right: 1em;" data-ng-repeat="r in realm.initialRoles">{{r}} <button data-ng-click="removeInitialRole($index)"><i class="icon-remove"></i></button></span>
<span class="label" style="margin-right: 1em;" data-ng-repeat="r in (realm.initialRoles|orderBy:'toString()')">{{r}} <button data-ng-click="removeInitialRole(r)"><i class="icon-remove icon-white"></i></button></span>
<div class="input-append">
<select style="width: auto;" data-ng-model="newInitialRole" data-ng-click="addInitialRole()">
<option data-ng-repeat="r in realm.roles" value="{{r}}">{{r}}</option>
<option data-ng-repeat="r in (realm.roles|remove:realm.initialRoles|orderBy:'toString()')" value="{{r}}">{{r}}</option>
</select>
</div>
</div>