groups.js 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625
  1. module.controller('GroupListCtrl', function($scope, $route, $q, realm, Groups, GroupsCount, Group, GroupChildren, Notifications, $location, Dialog, ComponentUtils, $translate) {
  2. $scope.realm = realm;
  3. $scope.groupList = [
  4. {
  5. "id" : "realm",
  6. "name": $translate.instant('groups'),
  7. "subGroups" : []
  8. }
  9. ];
  10. $scope.searchCriteria = '';
  11. $scope.currentPage = 1;
  12. $scope.currentPageInput = $scope.currentPage;
  13. $scope.pageSize = 20;
  14. $scope.numberOfPages = 1;
  15. $scope.tree = [];
  16. var refreshGroups = function (search) {
  17. console.log('refreshGroups');
  18. $scope.currentPageInput = $scope.currentPage;
  19. var first = ($scope.currentPage * $scope.pageSize) - $scope.pageSize;
  20. console.log('first:' + first);
  21. var queryParams = {
  22. realm : realm.realm,
  23. first : first,
  24. max : $scope.pageSize
  25. };
  26. var countParams = {
  27. realm : realm.realm,
  28. top : 'true'
  29. };
  30. if(angular.isDefined(search) && search !== '') {
  31. queryParams.search = search;
  32. countParams.search = search;
  33. }
  34. var promiseGetGroups = $q.defer();
  35. Groups.query(queryParams, function(entry) {
  36. promiseGetGroups.resolve(entry);
  37. }, function() {
  38. promiseGetGroups.reject($translate.instant('group.fetch.fail', {params: queryParams}));
  39. });
  40. promiseGetGroups.promise.then(function(groups) {
  41. $scope.groupList = [
  42. {
  43. "id" : "realm",
  44. "name": $translate.instant('groups'),
  45. "subGroups": ComponentUtils.sortGroups('name', groups)
  46. }
  47. ];
  48. if (angular.isDefined(search) && search !== '') {
  49. // Add highlight for concrete text match
  50. setTimeout(function () {
  51. document.querySelectorAll('span').forEach(function (element) {
  52. if (element.textContent.indexOf(search) != -1) {
  53. angular.element(element).addClass('highlight');
  54. }
  55. });
  56. }, 500);
  57. }
  58. }, function (failed) {
  59. Notifications.error(failed);
  60. });
  61. var promiseCount = $q.defer();
  62. console.log('countParams: realm[' + countParams.realm);
  63. GroupsCount.query(countParams, function(entry) {
  64. promiseCount.resolve(entry);
  65. }, function() {
  66. promiseCount.reject($translate.instant('group.fetch.fail', {params: countParams}));
  67. });
  68. promiseCount.promise.then(function(entry) {
  69. if(angular.isDefined(entry.count) && entry.count > $scope.pageSize) {
  70. $scope.numberOfPages = Math.ceil(entry.count/$scope.pageSize);
  71. } else {
  72. $scope.numberOfPages = 1;
  73. }
  74. }, function (failed) {
  75. Notifications.error(failed);
  76. });
  77. };
  78. refreshGroups();
  79. $scope.$watch('currentPage', function(newValue, oldValue) {
  80. if(parseInt(newValue, 10) !== oldValue) {
  81. refreshGroups($scope.searchCriteria);
  82. }
  83. });
  84. $scope.clearSearch = function() {
  85. $scope.searchCriteria = '';
  86. if (parseInt($scope.currentPage, 10) === 1) {
  87. refreshGroups();
  88. } else {
  89. $scope.currentPage = 1;
  90. }
  91. };
  92. $scope.searchGroup = function() {
  93. if (parseInt($scope.currentPage, 10) === 1) {
  94. refreshGroups($scope.searchCriteria);
  95. } else {
  96. $scope.currentPage = 1;
  97. }
  98. };
  99. $scope.edit = function(selected) {
  100. if (selected.id === 'realm') return;
  101. $location.url("/realms/" + realm.realm + "/groups/" + selected.id);
  102. };
  103. $scope.cut = function(selected) {
  104. $scope.cutNode = selected;
  105. };
  106. $scope.isDisabled = function() {
  107. if (!$scope.tree.currentNode) return true;
  108. return $scope.tree.currentNode.id === 'realm';
  109. };
  110. $scope.paste = function(selected) {
  111. if (selected === null) return;
  112. if ($scope.cutNode === null) return;
  113. if (selected.id === $scope.cutNode.id) return;
  114. if (selected.id === 'realm') {
  115. Groups.save({realm: realm.realm}, {id:$scope.cutNode.id, name: $scope.cutNode.name}, function() {
  116. $route.reload();
  117. Notifications.success($translate.instant('group.move.success'));
  118. });
  119. } else {
  120. GroupChildren.save({realm: realm.realm, groupId: selected.id}, {id:$scope.cutNode.id, name: $scope.cutNode.name}, function() {
  121. $route.reload();
  122. Notifications.success($translate.instant('group.move.success'));
  123. });
  124. }
  125. };
  126. $scope.remove = function(selected) {
  127. if (selected === null) return;
  128. Dialog.confirmWithButtonText(
  129. $translate.instant('group.remove.confirm.title', {name: selected.name}),
  130. $translate.instant('group.remove.confirm.message', {name: selected.name}),
  131. $translate.instant('dialogs.delete.confirm'),
  132. function() {
  133. Group.remove({ realm: realm.realm, groupId : selected.id }, function() {
  134. $route.reload();
  135. Notifications.success($translate.instant('group.remove.success'));
  136. });
  137. }
  138. );
  139. };
  140. $scope.createGroup = function(selected) {
  141. var parent = 'realm';
  142. if (selected) {
  143. parent = selected.id;
  144. }
  145. $location.url("/create/group/" + realm.realm + '/parent/' + parent);
  146. };
  147. var isLeaf = function(node) {
  148. return node.id !== "realm" && (!node.subGroups || node.subGroups.length === 0);
  149. };
  150. $scope.getGroupClass = function(node) {
  151. if (node.id === "realm") {
  152. return 'pficon pficon-users';
  153. }
  154. if (isLeaf(node)) {
  155. return 'normal';
  156. }
  157. if (node.subGroups.length && node.collapsed) return 'collapsed';
  158. if (node.subGroups.length && !node.collapsed) return 'expanded';
  159. return 'collapsed';
  160. };
  161. $scope.getSelectedClass = function(node) {
  162. if (node.selected) {
  163. return 'selected';
  164. } else if ($scope.cutNode && $scope.cutNode.id === node.id) {
  165. return 'cut';
  166. }
  167. return undefined;
  168. }
  169. });
  170. module.controller('GroupCreateCtrl', function($scope, $route, realm, parentId, Groups, Group, GroupChildren, Notifications, $location, $translate) {
  171. $scope.realm = realm;
  172. $scope.group = {};
  173. $scope.save = function() {
  174. console.log('save!!!');
  175. if (parentId === 'realm') {
  176. console.log('realm');
  177. Groups.save({realm: realm.realm}, $scope.group, function(data, headers) {
  178. var l = headers().location;
  179. var id = l.substring(l.lastIndexOf("/") + 1);
  180. $location.url("/realms/" + realm.realm + "/groups/" + id);
  181. Notifications.success($translate.instant('group.create.success'));
  182. })
  183. } else {
  184. GroupChildren.save({realm: realm.realm, groupId: parentId}, $scope.group, function(data, headers) {
  185. var l = headers().location;
  186. var id = l.substring(l.lastIndexOf("/") + 1);
  187. $location.url("/realms/" + realm.realm + "/groups/" + id);
  188. Notifications.success($translate.instant('group.create.success'));
  189. })
  190. }
  191. };
  192. $scope.cancel = function() {
  193. $location.url("/realms/" + realm.realm + "/groups");
  194. };
  195. });
  196. module.controller('GroupTabCtrl', function(Dialog, $scope, Current, Group, Notifications, $location, $translate) {
  197. $scope.removeGroup = function() {
  198. Dialog.confirmWithButtonText(
  199. $translate.instant('group.remove.confirm.title', {name: $scope.group.name}),
  200. $translate.instant('group.remove.confirm.message', {name: $scope.group.name}),
  201. $translate.instant('dialogs.delete.confirm'),
  202. function() {
  203. Group.remove({
  204. realm : Current.realm.realm,
  205. groupId : $scope.group.id
  206. }, function() {
  207. $location.url("/realms/" + Current.realm.realm + "/groups");
  208. Notifications.success($translate.instant('group.remove.success'));
  209. });
  210. }
  211. );
  212. };
  213. });
  214. module.controller('GroupDetailCtrl', function(Dialog, $scope, realm, group, Group, Notifications, $location, $translate) {
  215. $scope.realm = realm;
  216. if (!group.attributes) {
  217. group.attributes = {}
  218. }
  219. convertAttributeValuesToString(group);
  220. $scope.group = angular.copy(group);
  221. $scope.changed = false; // $scope.create;
  222. $scope.$watch('group', function() {
  223. if (!angular.equals($scope.group, group)) {
  224. $scope.changed = true;
  225. }
  226. }, true);
  227. $scope.save = function() {
  228. convertAttributeValuesToLists();
  229. Group.update({
  230. realm: realm.realm,
  231. groupId: $scope.group.id
  232. }, $scope.group, function () {
  233. $scope.changed = false;
  234. convertAttributeValuesToString($scope.group);
  235. group = angular.copy($scope.group);
  236. Notifications.success($translate.instant('group.edit.success'));
  237. });
  238. };
  239. function convertAttributeValuesToLists() {
  240. var attrs = $scope.group.attributes;
  241. for (var attribute in attrs) {
  242. if (typeof attrs[attribute] === "string") {
  243. attrs[attribute] = attrs[attribute].split("##");
  244. }
  245. }
  246. }
  247. function convertAttributeValuesToString(group) {
  248. var attrs = group.attributes;
  249. for (var attribute in attrs) {
  250. if (typeof attrs[attribute] === "object") {
  251. attrs[attribute] = attrs[attribute].join("##");
  252. }
  253. }
  254. }
  255. $scope.reset = function() {
  256. $scope.group = angular.copy(group);
  257. $scope.changed = false;
  258. };
  259. $scope.cancel = function() {
  260. $location.url("/realms/" + realm.realm + "/groups");
  261. };
  262. $scope.addAttribute = function() {
  263. $scope.group.attributes[$scope.newAttribute.key] = $scope.newAttribute.value;
  264. delete $scope.newAttribute;
  265. }
  266. $scope.removeAttribute = function(key) {
  267. delete $scope.group.attributes[key];
  268. }
  269. });
  270. module.controller('GroupRoleMappingCtrl', function($scope, $http, $route, realm, group, clients, client, Client, Notifications, GroupRealmRoleMapping,
  271. GroupClientRoleMapping, GroupAvailableRealmRoleMapping, GroupAvailableClientRoleMapping,
  272. GroupCompositeRealmRoleMapping, GroupCompositeClientRoleMapping, $translate) {
  273. $scope.realm = realm;
  274. $scope.group = group;
  275. $scope.selectedRealmRoles = [];
  276. $scope.selectedRealmMappings = [];
  277. $scope.realmMappings = [];
  278. $scope.clients = clients;
  279. $scope.client = client;
  280. $scope.clientRoles = [];
  281. $scope.clientComposite = [];
  282. $scope.selectedClientRoles = [];
  283. $scope.selectedClientMappings = [];
  284. $scope.clientMappings = [];
  285. $scope.dummymodel = [];
  286. $scope.realmMappings = GroupRealmRoleMapping.query({realm : realm.realm, groupId : group.id});
  287. $scope.realmRoles = GroupAvailableRealmRoleMapping.query({realm : realm.realm, groupId : group.id});
  288. $scope.realmComposite = GroupCompositeRealmRoleMapping.query({realm : realm.realm, groupId : group.id});
  289. $scope.addRealmRole = function() {
  290. $scope.selectedRealmRolesToAdd = JSON.parse('[' + $scope.selectedRealmRoles + ']');
  291. $scope.selectedRealmRoles = [];
  292. $http.post(authUrl + '/admin/realms/' + realm.realm + '/groups/' + group.id + '/role-mappings/realm',
  293. $scope.selectedRealmRolesToAdd).then(function() {
  294. $scope.realmMappings = GroupRealmRoleMapping.query({realm : realm.realm, groupId : group.id});
  295. $scope.realmRoles = GroupAvailableRealmRoleMapping.query({realm : realm.realm, groupId : group.id});
  296. $scope.realmComposite = GroupCompositeRealmRoleMapping.query({realm : realm.realm, groupId : group.id});
  297. $scope.selectedRealmMappings = [];
  298. $scope.selectRealmRoles = [];
  299. if ($scope.selectedClient) {
  300. console.log('load available');
  301. $scope.clientComposite = GroupCompositeClientRoleMapping.query({realm : realm.realm, groupId : group.id, client : $scope.selectedClient.id});
  302. $scope.clientRoles = GroupAvailableClientRoleMapping.query({realm : realm.realm, groupId : group.id, client : $scope.selectedClient.id});
  303. $scope.clientMappings = GroupClientRoleMapping.query({realm : realm.realm, groupId : group.id, client : $scope.selectedClient.id});
  304. $scope.selectedClientRoles = [];
  305. $scope.selectedClientMappings = [];
  306. }
  307. $scope.selectedRealmRolesToAdd = [];
  308. Notifications.success($translate.instant('group.roles.add.success'));
  309. });
  310. };
  311. $scope.deleteRealmRole = function() {
  312. $scope.selectedRealmMappingsToRemove = JSON.parse('[' + $scope.selectedRealmMappings + ']');
  313. $http.delete(authUrl + '/admin/realms/' + realm.realm + '/groups/' + group.id + '/role-mappings/realm',
  314. {data : $scope.selectedRealmMappingsToRemove, headers : {"content-type" : "application/json"}}).then(function() {
  315. $scope.realmMappings = GroupRealmRoleMapping.query({realm : realm.realm, groupId : group.id});
  316. $scope.realmRoles = GroupAvailableRealmRoleMapping.query({realm : realm.realm, groupId : group.id});
  317. $scope.realmComposite = GroupCompositeRealmRoleMapping.query({realm : realm.realm, groupId : group.id});
  318. $scope.selectedRealmMappings = [];
  319. $scope.selectRealmRoles = [];
  320. if ($scope.selectedClient) {
  321. console.log('load available');
  322. $scope.clientComposite = GroupCompositeClientRoleMapping.query({realm : realm.realm, groupId : group.id, client : $scope.selectedClient.id});
  323. $scope.clientRoles = GroupAvailableClientRoleMapping.query({realm : realm.realm, groupId : group.id, client : $scope.selectedClient.id});
  324. $scope.clientMappings = GroupClientRoleMapping.query({realm : realm.realm, groupId : group.id, client : $scope.selectedClient.id});
  325. $scope.selectedClientRoles = [];
  326. $scope.selectedClientMappings = [];
  327. }
  328. $scope.selectedRealmMappingsToRemove = [];
  329. Notifications.success($translate.instant('group.roles.remove.success'));
  330. });
  331. };
  332. $scope.addClientRole = function() {
  333. $scope.selectedClientRolesToAdd = JSON.parse('[' + $scope.selectedClientRoles + ']');
  334. $http.post(authUrl + '/admin/realms/' + realm.realm + '/groups/' + group.id + '/role-mappings/clients/' + $scope.selectedClient.id,
  335. $scope.selectedClientRolesToAdd).then(function() {
  336. $scope.clientMappings = GroupClientRoleMapping.query({realm : realm.realm, groupId : group.id, client : $scope.selectedClient.id});
  337. $scope.clientRoles = GroupAvailableClientRoleMapping.query({realm : realm.realm, groupId : group.id, client : $scope.selectedClient.id});
  338. $scope.clientComposite = GroupCompositeClientRoleMapping.query({realm : realm.realm, groupId : group.id, client : $scope.selectedClient.id});
  339. $scope.selectedClientRoles = [];
  340. $scope.selectedClientMappings = [];
  341. $scope.realmComposite = GroupCompositeRealmRoleMapping.query({realm : realm.realm, groupId : group.id});
  342. $scope.realmRoles = GroupAvailableRealmRoleMapping.query({realm : realm.realm, groupId : group.id});
  343. $scope.selectedClientRolesToAdd = [];
  344. Notifications.success($translate.instant('group.roles.add.success'));
  345. });
  346. };
  347. $scope.deleteClientRole = function() {
  348. $scope.selectedClientMappingsToRemove = JSON.parse('[' + $scope.selectedClientMappings + ']');
  349. $http.delete(authUrl + '/admin/realms/' + realm.realm + '/groups/' + group.id + '/role-mappings/clients/' + $scope.selectedClient.id,
  350. {data : $scope.selectedClientMappingsToRemove, headers : {"content-type" : "application/json"}}).then(function() {
  351. $scope.clientMappings = GroupClientRoleMapping.query({realm : realm.realm, groupId : group.id, client : $scope.selectedClient.id});
  352. $scope.clientRoles = GroupAvailableClientRoleMapping.query({realm : realm.realm, groupId : group.id, client : $scope.selectedClient.id});
  353. $scope.clientComposite = GroupCompositeClientRoleMapping.query({realm : realm.realm, groupId : group.id, client : $scope.selectedClient.id});
  354. $scope.selectedClientRoles = [];
  355. $scope.selectedClientMappings = [];
  356. $scope.realmComposite = GroupCompositeRealmRoleMapping.query({realm : realm.realm, groupId : group.id});
  357. $scope.realmRoles = GroupAvailableRealmRoleMapping.query({realm : realm.realm, groupId : group.id});
  358. $scope.selectedClientMappingsToRemove = [];
  359. Notifications.success($translate.instant('group.roles.remove.success'));
  360. });
  361. };
  362. $scope.changeClient = function(client) {
  363. $scope.selectedClient = client;
  364. if (!client || !client.id) {
  365. $scope.selectedClient = null;
  366. $scope.clientRoles = null;
  367. $scope.clientMappings = null;
  368. $scope.clientComposite = null;
  369. return;
  370. }
  371. if ($scope.selectedClient) {
  372. $scope.clientComposite = GroupCompositeClientRoleMapping.query({realm : realm.realm, groupId : group.id, client : $scope.selectedClient.id});
  373. $scope.clientRoles = GroupAvailableClientRoleMapping.query({realm : realm.realm, groupId : group.id, client : $scope.selectedClient.id});
  374. $scope.clientMappings = GroupClientRoleMapping.query({realm : realm.realm, groupId : group.id, client : $scope.selectedClient.id});
  375. }
  376. $scope.selectedClientRoles = [];
  377. $scope.selectedClientMappings = [];
  378. };
  379. clientSelectControl($scope, $route.current.params.realm, Client);
  380. });
  381. module.controller('GroupMembersCtrl', function($scope, realm, group, GroupMembership) {
  382. $scope.realm = realm;
  383. $scope.page = 0;
  384. $scope.group = group;
  385. $scope.query = {
  386. realm: realm.realm,
  387. groupId: group.id,
  388. max : 5,
  389. first : 0
  390. };
  391. $scope.firstPage = function() {
  392. $scope.query.first = 0;
  393. $scope.searchQuery();
  394. };
  395. $scope.previousPage = function() {
  396. $scope.query.first -= parseInt($scope.query.max);
  397. if ($scope.query.first < 0) {
  398. $scope.query.first = 0;
  399. }
  400. $scope.searchQuery();
  401. };
  402. $scope.nextPage = function() {
  403. $scope.query.first += parseInt($scope.query.max);
  404. $scope.searchQuery();
  405. };
  406. $scope.searchQuery = function() {
  407. console.log("query.search: " + $scope.query.search);
  408. $scope.searchLoaded = false;
  409. $scope.users = GroupMembership.query($scope.query, function() {
  410. console.log('search loaded');
  411. $scope.searchLoaded = true;
  412. $scope.lastSearch = $scope.query.search;
  413. });
  414. };
  415. $scope.searchQuery();
  416. });
  417. module.controller('DefaultGroupsCtrl', function($scope, $q, realm, Groups, GroupsCount, DefaultGroups, Notifications, $translate) {
  418. $scope.realm = realm;
  419. $scope.groupList = [];
  420. $scope.selectedGroup = null;
  421. $scope.tree = [];
  422. $scope.searchCriteria = '';
  423. $scope.currentPage = 1;
  424. $scope.currentPageInput = $scope.currentPage;
  425. $scope.pageSize = 20;
  426. $scope.numberOfPages = 1;
  427. var refreshDefaultGroups = function () {
  428. DefaultGroups.query({realm: realm.realm}, function(data) {
  429. $scope.defaultGroups = data;
  430. });
  431. }
  432. var refreshAvailableGroups = function (search) {
  433. var first = ($scope.currentPage * $scope.pageSize) - $scope.pageSize;
  434. $scope.currentPageInput = $scope.currentPage;
  435. var queryParams = {
  436. realm : realm.realm,
  437. first : first,
  438. max : $scope.pageSize
  439. };
  440. var countParams = {
  441. realm : realm.realm,
  442. top : 'true'
  443. };
  444. if(angular.isDefined(search) && search !== '') {
  445. queryParams.search = search;
  446. countParams.search = search;
  447. }
  448. var promiseGetGroups = $q.defer();
  449. Groups.query(queryParams, function(entry) {
  450. promiseGetGroups.resolve(entry);
  451. }, function() {
  452. promiseGetGroups.reject($translate.instant('group.fetch.fail', {params: queryParams}));
  453. });
  454. promiseGetGroups.promise.then(function(groups) {
  455. $scope.groupList = groups;
  456. }, function (failed) {
  457. Notifications.success(failed);
  458. });
  459. var promiseCount = $q.defer();
  460. GroupsCount.query(countParams, function(entry) {
  461. promiseCount.resolve(entry);
  462. }, function() {
  463. promiseCount.reject($translate.instant('group.fetch.fail', {params: countParams}));
  464. });
  465. promiseCount.promise.then(function(entry) {
  466. if(angular.isDefined(entry.count) && entry.count > $scope.pageSize) {
  467. $scope.numberOfPages = Math.ceil(entry.count/$scope.pageSize);
  468. }
  469. }, function (failed) {
  470. Notifications.success(failed);
  471. });
  472. };
  473. refreshAvailableGroups();
  474. $scope.$watch('currentPage', function(newValue, oldValue) {
  475. if(parseInt(newValue, 10) !== parseInt(oldValue, 10)) {
  476. refreshAvailableGroups($scope.searchCriteria);
  477. }
  478. });
  479. $scope.clearSearch = function() {
  480. $scope.searchCriteria = '';
  481. if (parseInt($scope.currentPage, 10) === 1) {
  482. refreshAvailableGroups();
  483. } else {
  484. $scope.currentPage = 1;
  485. }
  486. };
  487. $scope.searchGroup = function() {
  488. if (parseInt($scope.currentPage, 10) === 1) {
  489. refreshAvailableGroups($scope.searchCriteria);
  490. } else {
  491. $scope.currentPage = 1;
  492. }
  493. };
  494. refreshDefaultGroups();
  495. $scope.addDefaultGroup = function() {
  496. if (!$scope.tree.currentNode) {
  497. Notifications.error($translate.instant('group.default.add.error'));
  498. return;
  499. }
  500. DefaultGroups.update({realm: realm.realm, groupId: $scope.tree.currentNode.id}, function() {
  501. refreshDefaultGroups();
  502. Notifications.success($translate.instant('group.default.add.success'));
  503. });
  504. };
  505. $scope.removeDefaultGroup = function() {
  506. DefaultGroups.remove({realm: realm.realm, groupId: $scope.selectedGroup.id}, function() {
  507. refreshDefaultGroups();
  508. Notifications.success($translate.instant('group.default.remove.success'));
  509. });
  510. };
  511. var isLeaf = function(node) {
  512. return node.id !== "realm" && (!node.subGroups || node.subGroups.length === 0);
  513. };
  514. $scope.getGroupClass = function(node) {
  515. if (node.id === "realm") {
  516. return 'pficon pficon-users';
  517. }
  518. if (isLeaf(node)) {
  519. return 'normal';
  520. }
  521. if (node.subGroups.length && node.collapsed) return 'collapsed';
  522. if (node.subGroups.length && !node.collapsed) return 'expanded';
  523. return 'collapsed';
  524. };
  525. $scope.getSelectedClass = function(node) {
  526. if (node.selected) {
  527. return 'selected';
  528. } else if ($scope.cutNode && $scope.cutNode.id === node.id) {
  529. return 'cut';
  530. }
  531. return undefined;
  532. }
  533. });