From b54df0ddd0c6a0372327c5aa3668e5a6458fcd64 Mon Sep 17 00:00:00 2001 From: st782s Date: Thu, 4 May 2017 07:48:42 -0400 Subject: [PORTAL-7] Rebase This rebasing includes common libraries and common overlays projects abstraction of components Change-Id: I9a24a338665c7cd058978e8636bc412d9e2fdce8 Signed-off-by: st782s --- .../app/views/role/popup_modal_rolefunction.html | 55 +++++ .../client/app/views/role/role-controller.js | 219 ++++++++++++++++++ .../views/role/role-function-list-controller.js | 160 +++++++++++++ .../client/app/views/role/role-list-controller.js | 147 ++++++++++++ .../client/app/views/role/role.html | 96 ++++++++ .../client/app/views/role/role.less | 50 ++++ .../app/views/role/role_childrole_popup.html | 51 +++++ .../client/app/views/role/role_function_list.html | 107 +++++++++ .../app/views/role/role_functions_popup.html | 49 ++++ .../client/app/views/role/role_list.html | 55 +++++ .../app/views/role/rolefunctionpopupController.js | 95 ++++++++ .../app/views/role/rolepopupmodelController.js | 251 +++++++++++++++++++++ 12 files changed, 1335 insertions(+) create mode 100644 ecomp-portal-FE-common/client/app/views/role/popup_modal_rolefunction.html create mode 100644 ecomp-portal-FE-common/client/app/views/role/role-controller.js create mode 100644 ecomp-portal-FE-common/client/app/views/role/role-function-list-controller.js create mode 100644 ecomp-portal-FE-common/client/app/views/role/role-list-controller.js create mode 100644 ecomp-portal-FE-common/client/app/views/role/role.html create mode 100644 ecomp-portal-FE-common/client/app/views/role/role.less create mode 100644 ecomp-portal-FE-common/client/app/views/role/role_childrole_popup.html create mode 100644 ecomp-portal-FE-common/client/app/views/role/role_function_list.html create mode 100644 ecomp-portal-FE-common/client/app/views/role/role_functions_popup.html create mode 100644 ecomp-portal-FE-common/client/app/views/role/role_list.html create mode 100644 ecomp-portal-FE-common/client/app/views/role/rolefunctionpopupController.js create mode 100644 ecomp-portal-FE-common/client/app/views/role/rolepopupmodelController.js (limited to 'ecomp-portal-FE-common/client/app/views/role') diff --git a/ecomp-portal-FE-common/client/app/views/role/popup_modal_rolefunction.html b/ecomp-portal-FE-common/client/app/views/role/popup_modal_rolefunction.html new file mode 100644 index 00000000..3970960d --- /dev/null +++ b/ecomp-portal-FE-common/client/app/views/role/popup_modal_rolefunction.html @@ -0,0 +1,55 @@ + + +
+
+
+ +
+
+ *Name:
+ +
Name is Required +
+
+
+
+
+ *Code: +
+ +
Code is Required +
+
+ + + +
+ + + +
Cancel
+
+
+
+ + diff --git a/ecomp-portal-FE-common/client/app/views/role/role-controller.js b/ecomp-portal-FE-common/client/app/views/role/role-controller.js new file mode 100644 index 00000000..c5c7c97c --- /dev/null +++ b/ecomp-portal-FE-common/client/app/views/role/role-controller.js @@ -0,0 +1,219 @@ +/*- + * ================================================================================ + * ECOMP Portal + * ================================================================================ + * 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, $http, confirmBoxService, ngDialog, RoleService, conf, $stateParams){ + //$scope.role=${role}; + + $( "#dialogRoleFunction" ).hide(); + $( "#dialogChildRole" ).hide(); + + //$scope.ociavailableRoleFunctions=${availableRoleFunctions}; + $scope.fetchRoles = function() { + + RoleService.getRole($stateParams.roleId).then(function(data){ + + var j = data; + $scope.data = JSON.parse(j.data); + + $scope.role =JSON.parse($scope.data.role); + + $scope.ociavailableRoleFunctions =JSON.parse($scope.data.availableRoleFunctions); + $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); + $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("RoleService.getRole failed", error); + //reloadPageOnce(); + }); + } + + $scope.fetchRoles(); + + $scope.saveRole = function() { + var exists = false,x; + for(x in $scope.availableRoles){ + if($scope.availableRoles[x].name==$scope.role.name){ + exists = true; + //$modalInstance.close({availableRoleFunctions:message.availableRoleFunctions}); + } + } + if (exists) { + confirmBoxService.showInformation( "Role already exists."); + } + else { + var uuu = conf.api.saveRole + "?role_id="+$stateParams.roleId; + var postData = { + role: $scope.role, + childRoles: $scope.role.childRoles, + roleFunctions : $scope.role.roleFunctions + }; + $http.post(uuu, JSON.stringify(postData)).then(function(res) { + // console.log('roleController::saveRole: ' + JSON.stringify(res)); + if (res && res.data && res.data.role) + confirmBoxService.showInformation("Update Successful."); + else + confirmBoxService.showInformation('Failed to create role: ' + res.data.error) + }, + function(res){ + console.log('post failed', res.data); + confirmBoxService.showInformation("Error while saving."); + } + ); + } + }; + + $scope.addNewRoleFunctionModalPopup = function() { + var modalInstance = ngDialog.open({ + templateUrl: 'app/views/role/role_functions_popup.html', + controller: 'rolepopupController', + + resolve: { + roleId: function () { + return $stateParams.roleId; + }, + role: function () { + return $scope.role; + }, + availableRoles: function () { + return $scope.ociavailableRoles; + }, + availableRoleFunctions: function () { + return $scope.ociavailableRoleFunctions; + }, + } + }); + modalInstance.closePromise.then(response => { + if($stateParams.roleId === '0'){ + return $scope.role; + }else{ + $scope.fetchRoles(); + } + // $scope.role=response.role; + }); + }; + + $scope.addNewChildRoleModalPopup = function() { + var modalInstance = ngDialog.open({ + templateUrl: 'app/views/role/role_childrole_popup.html', + controller: 'rolepopupController', + + resolve: { + roleId: function () { + return $stateParams.roleId; + }, + role: function () { + return $scope.role; + }, + availableRoles: function () { + return $scope.ociavailableRoles; + }, + availableRoleFunctions: function () { + return $scope.ociavailableRoleFunctions; + }, + } + }).closePromise.then(function(response){ + if($stateParams.roleId === '0'){ + return $scope.role; + }else{ + $scope.fetchRoles(); + } + //$scope.role=response.role; + }); + }; + + $scope.removeRoleFunction = function(roleFunction) { + confirmBoxService.confirm("You are about to remove the role function "+roleFunction.name+" from the role for "+$scope.role.name+". Do you want to continue?").then( + function(confirmed){ + var uuu = conf.api.toggleRoleRoleFunction + "?role_id=" + $stateParams.roleId; + var postData={roleFunction:roleFunction}; + if(confirmed) { + $http.post(uuu, postData).then( + function(response) { + $scope.role= response.data.role; + $.each($scope.availableRoleFunctions, function(k, c){ + if(c.code === roleFunction.code) { + c.selected = false; + } + }); + }, + function(response) { + confirmBoxService.showInformation("Error while saving."); + } + ); + } + + }); + + }; + + $scope.removeChildRole = function(childRole) { + confirmBoxService.confirm("You are about to remove the child role "+childRole.name+" from the role for "+$scope.role.name+". Do you want to continue?").then( + function(confirmed){ + var uuu = conf.api.toggleRoleChildRole + "?role_id=" + $stateParams.roleId; + var postData={childRole:childRole}; + if(confirmed) { + $http.post(uuu,postData).then( function(response) { + $scope.role=response.data.role; + $.each($scope.availableRoles, function(k, c){ + if(c.id === childRole.id) { + c.selected = false; + } + }); + }, + + function(data) { + confirmBoxService.showInformation("Error while saving."); + }); + } + }); + + }; + +}); diff --git a/ecomp-portal-FE-common/client/app/views/role/role-function-list-controller.js b/ecomp-portal-FE-common/client/app/views/role/role-function-list-controller.js new file mode 100644 index 00000000..c7a1bfd8 --- /dev/null +++ b/ecomp-portal-FE-common/client/app/views/role/role-function-list-controller.js @@ -0,0 +1,160 @@ +/*- + * ================================================================================ + * ECOMP Portal + * ================================================================================ + * 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('roleFunctionListController', function ($scope,RoleService,$http,$state,conf,confirmBoxService, ngDialog){ + $( "#dialog" ).hide(); + + 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(); + }); + + $scope.editRoleFunction = null; + var dialog = null; + $scope.editRoleFunctionPopup = function(availableRoleFunction) { + $scope.editRoleFunction = availableRoleFunction; + $( "#dialog" ).dialog({ + modal: true + }); + }; + + $scope.editRoleFunctionModalPopup = function(availableRoleFunction) { + $scope.editRoleFunction = availableRoleFunction; + $scope.availableRoleFunctionsTemp=$scope.availableRoleFunctions; + //$scope.availableRoleFunctions={}; + var modalInstance = ngDialog.open({ + templateUrl: 'app/views/role/popup_modal_rolefunction.html', + controller: 'rolefunctionpopupController', + resolve: { + message: function () { + var message = { + availableRoleFunction: $scope.editRoleFunction, + availableRoleFunctions: $scope.availableRoleFunctionsTemp + }; + return message; + }, + isEditing: function () { + return true; + } + } + }); + modalInstance.closePromise.then(response =>{ + if(response.value!=null){ + if(response.value.result){ + $scope.availableRoleFunctions=response.value.availableRoleFunctions; + } + } + /*else + $scope.availableRoleFunctions=$scope.availableRoleFunctionsTemp; + */ + }); + }; + + $scope.addNewRoleFunctionModalPopup = function(availableRoleFunction) { + + $scope.editRoleFunction = null; + $scope.availableRoleFunctionsTemp=$scope.availableRoleFunctions; + //$scope.availableRoleFunctions={}; + var modalInstance = ngDialog.open({ + templateUrl: 'app/views/role/popup_modal_rolefunction.html', + controller: 'rolefunctionpopupController', + resolve: { + message: function () { + var message = { + availableRoleFunction: $scope.editRoleFunction, + availableRoleFunctions: $scope.availableRoleFunctionsTemp + }; + return message; + }, + isEditing: function () { + return false; + } + } + }); + modalInstance.closePromise.then(response => { + if(response.value!=null){ + if(response.value.result){ + $scope.availableRoleFunctions=response.value.availableRoleFunctions; + } + } + /* if(response.availableRoleFunctions != undefined) + $scope.availableRoleFunctions=response.availableRoleFunctions; + else + $scope.availableRoleFunctions=$scope.availableRoleFunctionsTemp; + */ + }); + }; + + $scope.addNewRoleFunctionPopup = function() { + $scope.editRoleFunction = null; + $( "#dialog" ).dialog({ + modal: true + }); + }; + + $scope.saveRoleFunction = function(availableRoleFunction) { + var uuu = conf.api.saveRoleFuncion; + var postData={availableRoleFunction: availableRoleFunction}; + $http.post(uuu,postData).then(function(response) { + var data = response.data; + $scope.availableRoleFunctions=data.availableRoleFunctions; + $scope.editRoleFunction = null; + }, + function() { + + confirmBoxService.showInformation("Error while saving"); + } + ); + }; + + + $scope.removeRole = function(availableRoleFunction) { + confirmBoxService.confirm("You are about to delete the role function "+availableRoleFunction.name+". Do you want to continue?").then( + function(confirmed){ + if(confirmed){ + $scope.availableRoleFunctionsTemp=$scope.availableRoleFunctions; + //$scope.availableRoleFunctions={}; + var uuu = conf.api.removeRoleFunction; + var postData={availableRoleFunction: availableRoleFunction}; + $http.post(uuu,postData).then(function(response) { + var data = response.data; + if(data.availableRoleFunctions == undefined) + confirmBoxService.showInformation("Error while deleting: "+ data); + else + $scope.availableRoleFunctions=data.availableRoleFunctions; + }, + function() { + $scope.availableRoleFunctions=$scope.availableRoleFunctionsTemp; + confirmBoxService.showInformation("Error while deleting: "+ data.responseText); + } + ); + } + }); + + }; + +}); diff --git a/ecomp-portal-FE-common/client/app/views/role/role-list-controller.js b/ecomp-portal-FE-common/client/app/views/role/role-list-controller.js new file mode 100644 index 00000000..5ef37165 --- /dev/null +++ b/ecomp-portal-FE-common/client/app/views/role/role-list-controller.js @@ -0,0 +1,147 @@ +/*- + * ================================================================================ + * ECOMP Portal + * ================================================================================ + * 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('roleListController', function ($scope,RoleService,confirmBoxService,conf,$state,$http){ + $scope.showSpinner = true; + + RoleService.getRoles().then(function(data){ + $scope.showSpinner = true; + var j = data; + $scope.data = JSON.parse(j.data); + $scope.availableRoles =JSON.parse($scope.data.availableRoles); + $scope.showSpinner = false; + //$scope.resetMenu(); + + },function(error){ + console.log("failed"); + //reloadPageOnce(); + }); + + + $scope.goToUrl = function(roleIdVal) { + $state.go("root.role", {"roleId":roleIdVal}); + } + //console.log($scope.availableRoles); + $scope.toggleRole = function(selected,availableRole) { + //alert('toggleRole: '+selected); + var toggleType = null; + if(selected) { + toggleType = "activate"; + } else { + toggleType = "inactivate"; + } + + confirmBoxService.confirm("You are about to "+toggleType+" the role "+availableRole.name+". Do you want to continue?").then( + function(confirmed){ + + if(confirmed) { + var uuu = conf.api.toggleRole; + + var postData={role:availableRole}; + $http.post(uuu, postData).then(function(response) { + var data = response.data; + if (typeof data === 'object') { + console.log(data); + $scope.availableRoles=data.availableRoles; + console.log($scope.availableRoles); + } else { + // + } + + }, function(response) { + console.log(response.data); + availableRole.active=!availableRole.active; + confirmBoxService.showInformation("Error while saving."); + }); + + /* + $.ajax({ + type : 'POST', + url : uuu, + dataType: 'json', + contentType: 'application/json', + data: JSON.stringify(postData), + success : function(data){ + console.log(data); + $scope.$apply(function(){$scope.availableRoles=data.availableRoles;}); + console.log($scope.availableRoles); + }, + error : function(data){ + console.log(data); + availableRole.active=!availableRole.active; + confirmBoxService.showInformation("Error while saving."); + } + }); + */ + } + else { + availableRole.active=!availableRole.active; + } + + }); + //, + //function(){ + // availableRole.active=!availableRole.active; + //}) + + + }; + + $scope.removeRole = function(role) { + + confirmBoxService.confirm("You are about to delete the role "+role.name+". Do you want to continue?").then( + function(confirmed){ + var uuu = conf.api.removeRole; + var postData={role:role}; + /* $.ajax({ + type : 'POST', + url : uuu, + dataType: 'json', + contentType: 'application/json', + data: JSON.stringify(postData), + success : function(data){ + $scope.$apply(function(){$scope.availableRoles=data.availableRoles;}); + }, + error : function(data){ + console.log(data); + confirmBoxService.showInformation("Error while deleting: "+ data.responseText); + } + }); */ + + + $http.post(uuu, postData).then(function(response) { + var data = response.data; + if (typeof data === 'object') { + $scope.availableRoles=data.availableRoles; + } else { + // + } + + }, function(response) { + console.log(response.data); + confirmBoxService.showInformation("Error while deleting: "+ data.responseText); + }); + + }); + + + }; + + +}); diff --git a/ecomp-portal-FE-common/client/app/views/role/role.html b/ecomp-portal-FE-common/client/app/views/role/role.html new file mode 100644 index 00000000..42793eee --- /dev/null +++ b/ecomp-portal-FE-common/client/app/views/role/role.html @@ -0,0 +1,96 @@ + +
+
+
+

Role

+
+
+
+
+

Please edit the role details below: 


+ +
+ + +
+ + +
+
+
+ +
+ +
+
+ + +
+ +
+ + + + + + + + + + + + + +
NameRemove
+
+
+
+ + Manage Role Functions

+ +
+ + +
+ +
+ + + + + + + + + + + + + +
NameRemove
+
+
+
+
+ +
+
+
diff --git a/ecomp-portal-FE-common/client/app/views/role/role.less b/ecomp-portal-FE-common/client/app/views/role/role.less new file mode 100644 index 00000000..42311e64 --- /dev/null +++ b/ecomp-portal-FE-common/client/app/views/role/role.less @@ -0,0 +1,50 @@ +.p-info { + font-size: 18px; +} + +.input-field { + width: 250px !important; +} + +.scrolling-table { + width: 548px; + margin-left: 16px; + height:575px; + overflow:auto; +} + +.scrolling-table .scroll-viewport { + height: 200px !important; + width: 99.5% !important; + background-color: white; +} + +.scrolling-table .scroll-overview { + margin-top: -14px !important; +} + +.scrolling-table .scroll-viewport:hover { + background-color: white; +} + +.scrolling-table #portal-scroll-table-content { + height: 200px; + position: absolute !important; + width: 548px; + padding-left: 0px; + padding-top: 0px; + padding-bottom: 0px; + padding-right: 5px; +} + +.vertical .scroll-thumb { + width: 13px !important; +} + +.vertical .scroll-bar { + width: 15px !important; +} + +.scroll-bar { + border-radius: 0px !important; +} \ No newline at end of file diff --git a/ecomp-portal-FE-common/client/app/views/role/role_childrole_popup.html b/ecomp-portal-FE-common/client/app/views/role/role_childrole_popup.html new file mode 100644 index 00000000..278ef2cd --- /dev/null +++ b/ecomp-portal-FE-common/client/app/views/role/role_childrole_popup.html @@ -0,0 +1,51 @@ + + +
+
Select Role Functions
+
+ +
+ + + + + + + + + + + + + + +
Name
+ +
+
+
+
+ +
+
+ diff --git a/ecomp-portal-FE-common/client/app/views/role/role_function_list.html b/ecomp-portal-FE-common/client/app/views/role/role_function_list.html new file mode 100644 index 00000000..c015ee56 --- /dev/null +++ b/ecomp-portal-FE-common/client/app/views/role/role_function_list.html @@ -0,0 +1,107 @@ + + +
+
+
+

Role Functions

+
+ + +
+ +
+ + +
+ +
+ +
+ +
+ +
+ + + + + + + + + + + + + + + + + +
NameCodeEdit?Delete?
+ +
+
+ +
+
+
+ + + +
+ + +
+ +
+
+ +
+
+
+
+ +
+
+ + +
+ +
+
diff --git a/ecomp-portal-FE-common/client/app/views/role/role_functions_popup.html b/ecomp-portal-FE-common/client/app/views/role/role_functions_popup.html new file mode 100644 index 00000000..7d80d81e --- /dev/null +++ b/ecomp-portal-FE-common/client/app/views/role/role_functions_popup.html @@ -0,0 +1,49 @@ + + +
+
Select Role Functions
+
+
+ + + + + + + + + + + + + + +
Name
+ +
+
+
+
+ +
+
diff --git a/ecomp-portal-FE-common/client/app/views/role/role_list.html b/ecomp-portal-FE-common/client/app/views/role/role_list.html new file mode 100644 index 00000000..e8d56cab --- /dev/null +++ b/ecomp-portal-FE-common/client/app/views/role/role_list.html @@ -0,0 +1,55 @@ + +
+
+
+

Roles

+
+
+
+ +
+
+ + + + + + + + + + + + + + + +
NamePriorityActive
+
+ +
+
+
+
+
+
diff --git a/ecomp-portal-FE-common/client/app/views/role/rolefunctionpopupController.js b/ecomp-portal-FE-common/client/app/views/role/rolefunctionpopupController.js new file mode 100644 index 00000000..6275c760 --- /dev/null +++ b/ecomp-portal-FE-common/client/app/views/role/rolefunctionpopupController.js @@ -0,0 +1,95 @@ +/*- + * ================================================================================ + * ECOMP Portal + * ================================================================================ + * 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('rolefunctionpopupController', function ($scope, confirmBoxService, message, $http,RoleService, conf, isEditing){ + if(message.availableRoleFunction==null) { + $scope.label='Add Role Function'; + var tempText = ""; + } + else{ + $scope.label='Edit Role Function' + $scope.disableCd=true; + var tempText = new String(message.availableRoleFunction.name); + $scope.editRoleFunction = angular.copy(message.availableRoleFunction); + } + + $scope.tempText = tempText; + $scope.isEditing = isEditing; + + $scope.saveRoleFunction = function(availableRoleFunction) { + var uuu = conf.api.saveRoleFunction; + var postData={availableRoleFunction: availableRoleFunction}; + + if(availableRoleFunction==null){ + confirmBoxService.showInformation("Please enter valid role function details."); + } + var exists = false,x; + for(x in message.availableRoleFunctions){ + console.log(message.availableRoleFunctions[x].name); + if(message.availableRoleFunctions[x].name==availableRoleFunction.name){ + confirmBoxService.showInformation("Role Function already exists."); + exists = true; + availableRoleFunction.name = $scope.tempText; + break; + } + if(!isEditing){ + if (message.availableRoleFunctions[x].code == availableRoleFunction.code) { + confirmBoxService.showInformation("Code already exists. Please create a role function with a different code to proceed."); + exists = true; + availableRoleFunction.name = $scope.tempText; + break; + } + } + } + + if(!exists && availableRoleFunction.name.trim() != '' && availableRoleFunction.code.trim() != ''){ + $http.post(uuu, JSON.stringify(postData)).then(function(res){ + console.log("data"); +// console.log(res.data); +// $scope.availableRoleFunctionsTemp = res.data.availableRoleFunctions; + RoleService.getRoleFunctionList().then(function(data){ + + var j = data; + $scope.data = JSON.parse(j.data); + $scope.availableRoleFunctions =JSON.parse($scope.data.availableRoleFunctions); + + //$scope.resetMenu(); + $scope.closeThisDialog({result: true, availableRoleFunctions: $scope.availableRoleFunctions }); + },function(error){ + console.log("failed"); + //reloadPageOnce(); + $scope.closeThisDialog(true); + }); + + + }); + + + + + } + }; + + + + $scope.close = function() { + this.closeThisDialog(true); + }; +} +); diff --git a/ecomp-portal-FE-common/client/app/views/role/rolepopupmodelController.js b/ecomp-portal-FE-common/client/app/views/role/rolepopupmodelController.js new file mode 100644 index 00000000..7feb7f2f --- /dev/null +++ b/ecomp-portal-FE-common/client/app/views/role/rolepopupmodelController.js @@ -0,0 +1,251 @@ +/*- + * ================================================================================ + * ECOMP Portal + * ================================================================================ + * 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('rolepopupController', function ($scope, role, roleId, confirmBoxService, $http, $state, availableRoles, conf, availableRoleFunctions,ngDialog){ + + $scope.role = role; + console.log($scope.role); + if($scope.role.childRoles==null){ + $scope.role.childRoles=[]; + } + + $scope.ociavailableRoles=availableRoles; + console.log($scope.ociavailableRoles); + + $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); + }); + + $scope.ociavailableRoleFunctions = 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.resetMenu(); + + $scope.toggleRoleFunction = function(selected,availableRoleFunction) { + //alert('toggleRole: '+selected); + + if(!selected) { + //remove role function + if(role.id==null){ + var index = $scope.role.roleFunctions.indexOf(availableRoleFunction); + if(index>=0) + $scope.role.roleFunctions.splice(index, 1); + return; + } + var uuu = conf.api.toggleRoleRoleFunction + "?role_id=" + roleId; + confirmBoxService.confirm("You are about to remove the role function "+availableRoleFunction.name+" from the role for "+$scope.role.name+". Do you want to continue?").then( + function(confirmed){ + if(confirmed) { + var postData={roleFunction:availableRoleFunction}; + $http.post(uuu, postData).then( + function(response) { + $scope.role= response.data.role; + }, + function(response) { + confirmBoxService.showInformation("Error while saving."); + } + ); + + + + + } + else { + availableRoleFunction.selected=!availableRoleFunction.selected; + } + /* + $.ajax({ + type : 'POST', + url : uuu, + dataType: 'json', + contentType: 'application/json', + data: JSON.stringify(postData), + success : function(data){ + $scope.$apply(function(){$scope.role=data.role;}); + }, + error : function(data){ + modalService.showFailure("Fail","Error while saving."); + } + }); + */ + }); + + } else { + //add role function + if(role.id==null){ + $scope.role.roleFunctions.push(availableRoleFunction); + return; + } + var uuu = conf.api.addRoleRoleFunction + "?role_id=" + roleId; + + confirmBoxService.confirm("You are about to add the role function "+availableRoleFunction.name+" to the role for "+$scope.role.name+". Do you want to continue?").then( + function(confirmed){ + if(confirmed) { + var postData={roleFunction:availableRoleFunction}; + $http.post(uuu,postData).then( function(response) { + $scope.role=response.data.role; + }, + + function(data) { + confirmBoxService.showInformation("Error while saving."); + }); + } else { + availableRoleFunction.selected=!availableRoleFunction.selected; + } + /* + $.ajax({ + type : 'POST', + url : uuu, + dataType: 'json', + contentType: 'application/json', + data: JSON.stringify(postData), + success : function(data){ + $scope.$apply(function(){$scope.role=data.role;}); + }, + error : function(data){ + modalService.showFailure("Fail","Error while saving."); + } + }); + + + }, + function(){ + availableRoleFunction.selected=!availableRoleFunction.selected; + })*/ + }); + + + } + }; + + $scope.toggleChildRole = function(selected,availableRole) { + //alert('toggleRole: '+selected); + + if(!selected) { + //remove role + if(role.id==null){ + var index = $scope.role.childRoles.indexOf(availableRole); + if(index>=0) + $scope.role.childRoles.splice(index, 1); + return; + } + var uuu = conf.api.toggleRoleChildRole +"?role_id=" + roleId; + + confirmBoxService.confirm("You are about to remove the child role "+availableRole.name+" from the role for "+$scope.role.name+". Do you want to continue?").then( + function(confirmed){ + if(confirmed) { + + var postData={childRole:availableRole}; + $http.post(uuu,postData).then(function(response) { + $scope.role=response.data.role; + }, + function(data) { + confirmBoxService.showInformation("Error while saving."); + }); + } else { + availableRole.selected=false; + } + }); + /* $.ajax({ + type : 'POST', + url : uuu, + dataType: 'json', + contentType: 'application/json', + data: JSON.stringify(postData), + success : function(data){ + console.log('role',data.role); + $scope.$apply(function(){$scope.role=data.role;}); + }, + error : function(data){ + modalService.showFailure("Fail","Error while saving."); + } + }); + */ + + + } else { + //add role + if(role.id==null){ + $scope.role.childRoles.push(availableRole); + return; + } + var uuu = conf.api.addRoleChildRole +"?role_id=" + roleId; + + confirmBoxService.confirm("You are about to add the child role "+availableRole.name+" to the role for "+$scope.role.name+". Do you want to continue?").then( + function(confirmed){ + if(confirmed) { + var postData={childRole:availableRole}; + $http.post(uuu,postData).then(function(response) { + $scope.role=response.data.role; + }, + function(data) { + confirmBoxService.showInformation("Error while saving."); + }); + } else { + availableRole.selected=false; + } + /* $.ajax({ + type : 'POST', + url : uuu, + dataType: 'json', + contentType: 'application/json', + data: JSON.stringify(postData), + success : function(data){ + $scope.$apply(function(){$scope.role=data.role;}); + }, + error : function(data){ + modalService.showFailure("Fail","Error while saving."); + } + });*/ + + }); + + + } + }; + + $scope.close = function() { + console.log('role', $scope.role); + //$modalInstance.close({role:$scope.role}); + this.closeThisDialog(true); + }; + +}); -- cgit 1.2.3-korg