KEYCLOAK-1252

This commit is contained in:
Stian Thorgersen 2015-05-05 07:00:15 +02:00
parent f388c3d385
commit 4a82ed73a4

View file

@ -201,7 +201,6 @@ module.controller('RealmCreateCtrl', function($scope, Current, Realm, $upload, $
$scope.save = function() { $scope.save = function() {
var realmCopy = angular.copy($scope.realm); var realmCopy = angular.copy($scope.realm);
console.log('creating new realm **');
Realm.create(realmCopy, function() { Realm.create(realmCopy, function() {
Realm.query(function(data) { Realm.query(function(data) {
Current.realms = data; Current.realms = data;
@ -217,55 +216,32 @@ module.controller('RealmCreateCtrl', function($scope, Current, Realm, $upload, $
}; };
$scope.cancel = function() { $scope.cancel = function() {
//$location.url("/realms");
window.history.back(); window.history.back();
}; };
}); });
module.controller('RealmDetailCtrl', function($scope, Current, Realm, realm, serverInfo, $http, $location, Dialog, Notifications) { module.controller('RealmDetailCtrl', function($scope, Current, Realm, realm, serverInfo, $http, $location, Dialog, Notifications, WhoAmI, Auth) {
$scope.createRealm = !realm.realm; $scope.createRealm = !realm.realm;
$scope.serverInfo = serverInfo; $scope.serverInfo = serverInfo;
console.log('RealmDetailCtrl'); if (Current.realm == null || Current.realm.realm != realm.realm) {
if ($scope.createRealm) {
$scope.realm = {
enabled: true,
sslRequired: 'external'
};
} else {
if (Current.realm == null || Current.realm.realm != realm.realm) {
for (var i = 0; i < Current.realms.length; i++) {
if (realm.realm == Current.realms[i].realm) {
Current.realm = Current.realms[i];
break;
}
}
}
console.log('realm name: ' + realm.realm);
for (var i = 0; i < Current.realms.length; i++) { for (var i = 0; i < Current.realms.length; i++) {
console.log('checking Current.realm:' + Current.realms[i].realm); if (realm.realm == Current.realms[i].realm) {
if (Current.realms[i].realm == realm.realm) {
Current.realm = Current.realms[i]; Current.realm = Current.realms[i];
break;
} }
} }
/*
if (Current.realm == null || Current.realm.realm != realm.realm) {
console.log('should be unreachable');
console.log('Why? ' + Current.realms.length + ' ' + Current.realm);
return;
}
*/
$scope.realm = angular.copy(realm);
} }
for (var i = 0; i < Current.realms.length; i++) {
$scope.registrationAllowed = $scope.realm.registrationAllowed; if (Current.realms[i].realm == realm.realm) {
Current.realm = Current.realms[i];
}
}
$scope.realm = angular.copy(realm);
var oldCopy = angular.copy($scope.realm); var oldCopy = angular.copy($scope.realm);
$scope.changed = $scope.create; $scope.changed = $scope.create;
$scope.$watch('realm', function() { $scope.$watch('realm', function() {
@ -276,40 +252,31 @@ module.controller('RealmDetailCtrl', function($scope, Current, Realm, realm, ser
$scope.save = function() { $scope.save = function() {
var realmCopy = angular.copy($scope.realm); var realmCopy = angular.copy($scope.realm);
if ($scope.createRealm) { $scope.changed = false;
Realm.save(realmCopy, function(data, headers) { var nameChanged = !angular.equals($scope.realm.realm, oldCopy.realm)
console.log('creating new realm'); Realm.update({ id : oldCopy.realm}, realmCopy, function () {
var data = Realm.query(function() { var data = Realm.query(function () {
Current.realms = data; Current.realms = data;
for (var i = 0; i < Current.realms.length; i++) { for (var i = 0; i < Current.realms.length; i++) {
if (Current.realms[i].realm == realmCopy.realm) { if (Current.realms[i].realm == realmCopy.realm) {
Current.realm = Current.realms[i]; Current.realm = Current.realms[i];
} oldCopy = angular.copy($scope.realm);
} }
$location.url("/realms/" + realmCopy.realm); }
Notifications.success("The realm has been created.");
$scope.registrationAllowed = $scope.realm.registrationAllowed;
});
}); });
} else {
console.log('updating realm...'); if (nameChanged) {
$scope.changed = false; WhoAmI.get(function(user) {
console.log('oldCopy.realm - ' + oldCopy.realm); Auth.user = user;
Realm.update({ id : oldCopy.realm}, realmCopy, function () {
var data = Realm.query(function () { $location.url("/realms/" + realmCopy.realm);
Current.realms = data; Notifications.success("Your changes have been saved to the realm.");
for (var i = 0; i < Current.realms.length; i++) {
if (Current.realms[i].realm == realmCopy.realm) {
Current.realm = Current.realms[i];
oldCopy = angular.copy($scope.realm);
}
}
}); });
} else {
$location.url("/realms/" + realmCopy.realm); $location.url("/realms/" + realmCopy.realm);
Notifications.success("Your changes have been saved to the realm."); Notifications.success("Your changes have been saved to the realm.");
$scope.registrationAllowed = $scope.realm.registrationAllowed; }
}); });
}
}; };
$scope.reset = function() { $scope.reset = function() {
@ -318,7 +285,6 @@ module.controller('RealmDetailCtrl', function($scope, Current, Realm, realm, ser
}; };
$scope.cancel = function() { $scope.cancel = function() {
//$location.url("/realms");
window.history.back(); window.history.back();
}; };