-app.controller('roleFunctionListController', function ($scope,RoleService,$http,$state,conf,confirmBoxService, ngDialog,$modal){
- $( "#dialog" ).hide();
- $scope.isLoadingRoleFunctions = true;
- RoleService.getRoleFunctionList().then(function(data){
-
- var j = data;
- $scope.data = JSON.parse(j.data);
- $scope.availableRoleFunctions =JSON.parse($scope.data.availableRoleFunctions);
- //$scope.resetMenu();
-
- },function(error){
- console.log("failed");
- //reloadPageOnce();
- }) .finally(function(){
- $scope.isLoadingRoleFunctions = false;
- });
+"use strict";
+
+app.controller('roleFunctionListController', function ($scope, RoleService, applicationsService, $http, $state, conf, confirmBoxService, ngDialog, $modal) {
+ $("#dialog").hide();
+ $scope.centralizedApps = RoleService.getManageRoleDetails().apps;
+ $scope.apps = {
+ selectedCentralizedApp: RoleService.getManageRoleDetails().id
+ };
+
+ $scope.getRoleFunctions = function (id) {
+ $scope.isLoadingRoleFunctions = true;
+ RoleService.getRoleFunctionList(id).then(function (data) {
+ var j = data;
+ $scope.data = JSON.parse(j.data);
+ $scope.availableRoleFunctions = $scope.data.availableRoleFunctions;
+ }, function (error) {
+ confirmBoxService.showInformation("Failed to get role functions. Please try again!");
+ console.log("failed");
+ }).finally(function(){
+ $scope.isLoadingRoleFunctions = false;
+ });
+ };
+
+ function init() {
+ if($scope.apps.selectedCentralizedApp){
+ $scope.getRoleFunctions($scope.apps.selectedCentralizedApp);
+ }
+ if($scope.apps.selectedCentralizedApp == undefined){
+ $scope.getCentralizedApps(sessionStorage.userId);
+ }
+ }
+
+ //getCentalizedApps
+ $scope.getCentralizedApps = function(userId) {
+ RoleService.getCentralizedApps(userId).then(res=> {
+ if (res.length>0) {
+ $scope.centralizedApps = res;
+ for(var i = 0; i<res.length; i++){
+ if(res[i].appId == 1){
+ $scope.apps.selectedCentralizedApp = res[i].appId;
+ return;
+ }
+ $scope.apps.selectedCentralizedApp = res[0].appId;
+ }
+ }
+ }).catch(err=> {
+ $log.error('RoleListCtrl::centralizedApps retrieval error: ', err);
+ }).finally(() => {
+ // this.isLoadingTable = false;
+ });
+
+ }