diff options
author | 2017-02-08 10:13:29 -0500 | |
---|---|---|
committer | 2017-02-08 10:15:00 -0500 | |
commit | f8a8d5192b1e5013d9e2f699be54b072ef39d5f0 (patch) | |
tree | b7a65bb0a7d70a9dc24c064113868e5f3b8e6a09 /dcae_dmaapbc_webapp/src/main/webapp/app/fusion/scripts/controllers/role-controller.js | |
parent | 72a80fbff7120630576ccd5aa67c20818c2943c7 (diff) |
Initial OpenECOMP UI/DMaapBC commit
Change-Id: Ia492e1b88311b9bed4c31f593b28deaaad73b7e4
Signed-off-by: talasila <talasila@research.att.com>
Diffstat (limited to 'dcae_dmaapbc_webapp/src/main/webapp/app/fusion/scripts/controllers/role-controller.js')
-rw-r--r-- | dcae_dmaapbc_webapp/src/main/webapp/app/fusion/scripts/controllers/role-controller.js | 226 |
1 files changed, 226 insertions, 0 deletions
diff --git a/dcae_dmaapbc_webapp/src/main/webapp/app/fusion/scripts/controllers/role-controller.js b/dcae_dmaapbc_webapp/src/main/webapp/app/fusion/scripts/controllers/role-controller.js new file mode 100644 index 0000000..d588fbb --- /dev/null +++ b/dcae_dmaapbc_webapp/src/main/webapp/app/fusion/scripts/controllers/role-controller.js @@ -0,0 +1,226 @@ +/*- + * ================================================================================ + * DCAE DMaaP Bus Controller Web Application + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ================================================================================ + */ +app.controller('roleController', function ($scope, modalService, $modal, AdminService,$routeParams){ + //$scope.role=${role}; + //console.log($scope.role.roleFunctions); + + $( "#dialogRoleFunction" ).hide(); + $( "#dialogChildRole" ).hide(); + + //$scope.ociavailableRoleFunctions=${availableRoleFunctions}; + + AdminService.getRole($routeParams.roleId).then(function(data){ + + var j = data; + $scope.data = JSON.parse(j.data); + + $scope.role =JSON.parse($scope.data.role); + console.log($scope.role); + + $scope.ociavailableRoleFunctions =JSON.parse($scope.data.availableRoleFunctions); + console.log($scope.ociavailableRoleFunctions); + $scope.availableRoleFunctions=[]; + + if($scope.ociavailableRoleFunctions) + $.each($scope.ociavailableRoleFunctions, function(i, a){ + var availableRoleFunction = a; + availableRoleFunction.selected = false; + $.each($scope.role.roleFunctions, function(j, b){ + if(a.code === b.code) { + availableRoleFunction.selected = true; + } + }); + $scope.availableRoleFunctions.push(availableRoleFunction); + }); + + + $scope.ociavailableRoles=JSON.parse($scope.data.availableRoles); + console.log($scope.ociavailableRoles); + console.log("testing roles if exist"); + $scope.availableRoles=[]; + + if($scope.ociavailableRoles) + $.each($scope.ociavailableRoles, function(i, a){ + var availableRole = a; + availableRole.selected = false; + if($scope.role.childRoles){ + $.each($scope.role.childRoles, function(j, b){ + if(a.id === b.id) { + availableRole.selected = true; + } + }); + }; + $scope.availableRoles.push(availableRole); + }); + + + },function(error){ + console.log("failed"); + reloadPageOnce(); + }); + + $scope.saveRole = function() { + var exists = false; + for(x in $scope.availableRoles){ + console.log($scope.availableRoles[x].name); + if($scope.availableRoles[x].name==$scope.role.name){ + modalService.showFailure("Warning", "Role already exists."); + exists = true; + //$modalInstance.close({availableRoleFunctions:message.availableRoleFunctions}); + } + } + if(!exists){ + var uuu = "role/saveRole.htm?role_id="+$routeParams.roleId; + var postData={role: $scope.role, childRoles: $scope.role.childRoles, roleFunctions : $scope.role.roleFunctions}; + $.ajax({ + type : 'POST', + url : uuu, + dataType: 'json', + contentType: 'application/json', + data: JSON.stringify(postData), + success : function(data){ + modalService.showSuccess("Success","Update Successful."); + }, + error : function(data){ + console.log(data); + modalService.showFailure("Fail","Error while saving."); + } + }); + } + + }; + + $scope.addNewRoleFunctionModalPopup = function() { + var modalInstance = $modal.open({ + templateUrl: 'role_functions_popup.html', + controller: 'rolepopupController', + backdrop: 'static', + resolve: { + roleId: function () { + return $routeParams.roleId; + }, + role: function () { + return $scope.role; + }, + availableRoles: function () { + return $scope.ociavailableRoles; + }, + availableRoleFunctions: function () { + return $scope.ociavailableRoleFunctions; + } + } + }); + modalInstance.result.then(function(response){ + console.log('response', response); + $scope.role=response.role; + }); + }; + + $scope.addNewChildRoleModalPopup = function() { + var modalInstance = $modal.open({ + templateUrl: 'child_roles_popup.html', + controller: 'rolepopupController', + backdrop: 'static', + resolve: { + roleId: function () { + return $routeParams.roleId; + }, + role: function () { + return $scope.role; + }, + availableRoles: function () { + return $scope.ociavailableRoles; + }, + availableRoleFunctions: function () { + return $scope.ociavailableRoleFunctions; + } + } + }); + modalInstance.result.then(function(response){ + console.log('response', response); + $scope.role=response.role; + }); + }; + + + + $scope.removeRoleFunction = function(roleFunction) { + modalService.popupConfirmWin("Confirm","You are about to remove the role function "+roleFunction.name+" from the role for "+$scope.role.name+". Do you want to continue?", + function(){ + var uuu = "role/removeRoleFunction.htm?role_id=" + $routeParams.roleId; + var postData={roleFunction:roleFunction}; + $.ajax({ + type : 'POST', + url : uuu, + dataType: 'json', + contentType: 'application/json', + data: JSON.stringify(postData), + success : function(data){ + $scope.$apply(function(){ + $scope.role=data.role; + $.each($scope.availableRoleFunctions, function(k, c){ + if(c.code === roleFunction.code) { + c.selected = false; + } + }); + }); + + }, + error : function(data){ + modalService.showFailure("Fail","Error while saving."); + } + }); + + }) + + }; + + $scope.removeChildRole = function(childRole) { + modalService.popupConfirmWin("Confirm","You are about to remove the child role "+childRole.name+" from the role for "+$scope.role.name+". Do you want to continue?", + function(){ + var uuu = "role/removeChildRole.htm?role_id=" + $routeParams.roleId; + var postData={childRole:childRole}; + $.ajax({ + type : 'POST', + url : uuu, + dataType: 'json', + contentType: 'application/json', + data: JSON.stringify(postData), + success : function(data){ + $scope.$apply(function(){ + $scope.role=data.role; + $.each($scope.availableRoles, function(k, c){ + if(c.id === childRole.id) { + c.selected = false; + } + }); + }); + + }, + error : function(data){ + modalService.showFailure("Fail","Error while saving."); + } + }); + + }) + + }; + +}); |