-/*-\r
- * ================================================================================\r
- * ECOMP Portal\r
- * ================================================================================\r
- * Copyright (C) 2017 AT&T Intellectual Property\r
- * ================================================================================\r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- * \r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- * \r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- * ================================================================================\r
- */\r
-app.controller('rolepopupController', function ($scope, role, roleId, confirmBoxService, $http, $state, availableRoles, conf, availableRoleFunctions,ngDialog){\r
- \r
- $scope.role = role;\r
- console.log($scope.role);\r
- if($scope.role.childRoles==null){\r
- $scope.role.childRoles=[];\r
- }\r
- \r
- $scope.ociavailableRoles=availableRoles;\r
- console.log($scope.ociavailableRoles);\r
- \r
- $scope.availableRoles=[];\r
- if($scope.ociavailableRoles)\r
- $.each($scope.ociavailableRoles, function(i, a){ \r
- var availableRole = a;\r
- availableRole.selected = false;\r
- if($scope.role.childRoles){\r
- $.each($scope.role.childRoles, function(j, b){ \r
- if(a.id === b.id) {\r
- availableRole.selected = true;\r
- }\r
- });\r
- };\r
- $scope.availableRoles.push(availableRole); \r
- }); \r
- \r
- $scope.ociavailableRoleFunctions = availableRoleFunctions; \r
- console.log($scope.ociavailableRoleFunctions);\r
- $scope.availableRoleFunctions = []; \r
- if($scope.ociavailableRoleFunctions)\r
- $.each($scope.ociavailableRoleFunctions, function(i, a){ \r
- var availableRoleFunction = a;\r
- availableRoleFunction.selected = false;\r
- $.each($scope.role.roleFunctions, function(j, b){ \r
- if(a.code === b.code) {\r
- availableRoleFunction.selected = true;\r
- }\r
- });\r
- $scope.availableRoleFunctions.push(availableRoleFunction); \r
- });\r
- //$scope.resetMenu();\r
- \r
- $scope.toggleRoleFunction = function(selected,availableRoleFunction) {\r
- //alert('toggleRole: '+selected);\r
- \r
- if(!selected) {\r
- //remove role function\r
- if(role.id==null){\r
- var index = $scope.role.roleFunctions.indexOf(availableRoleFunction);\r
- if(index>=0)\r
- $scope.role.roleFunctions.splice(index, 1);\r
- return;\r
- }\r
- var uuu = conf.api.toggleRoleRoleFunction + "?role_id=" + roleId;\r
- 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(\r
- function(confirmed){\r
- if(confirmed) { \r
- var postData={roleFunction:availableRoleFunction};\r
- $http.post(uuu, postData).then(\r
- function(response) {\r
- $scope.role= response.data.role;\r
- }, \r
- function(response) {\r
- confirmBoxService.showInformation("Error while saving.");\r
- }\r
- );\r
- \r
- \r
- \r
- \r
- }\r
- else {\r
- availableRoleFunction.selected=!availableRoleFunction.selected;\r
- }\r
- /*\r
- $.ajax({\r
- type : 'POST',\r
- url : uuu,\r
- dataType: 'json',\r
- contentType: 'application/json',\r
- data: JSON.stringify(postData),\r
- success : function(data){\r
- $scope.$apply(function(){$scope.role=data.role;}); \r
- },\r
- error : function(data){\r
- modalService.showFailure("Fail","Error while saving.");\r
- }\r
- });\r
- */\r
- });\r
- \r
- } else {\r
- //add role function\r
- if(role.id==null){\r
- $scope.role.roleFunctions.push(availableRoleFunction);\r
- return;\r
- }\r
- var uuu = conf.api.addRoleRoleFunction + "?role_id=" + roleId;\r
- \r
- 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(\r
- function(confirmed){\r
- if(confirmed) {\r
- var postData={roleFunction:availableRoleFunction};\r
- $http.post(uuu,postData).then( function(response) {\r
- $scope.role=response.data.role;\r
- },\r
- \r
- function(data) {\r
- confirmBoxService.showInformation("Error while saving.");\r
- });\r
- } else {\r
- availableRoleFunction.selected=!availableRoleFunction.selected;\r
- }\r
- /* \r
- $.ajax({\r
- type : 'POST',\r
- url : uuu,\r
- dataType: 'json',\r
- contentType: 'application/json',\r
- data: JSON.stringify(postData),\r
- success : function(data){\r
- $scope.$apply(function(){$scope.role=data.role;}); \r
- },\r
- error : function(data){\r
- modalService.showFailure("Fail","Error while saving.");\r
- }\r
- });\r
- \r
- \r
- },\r
- function(){\r
- availableRoleFunction.selected=!availableRoleFunction.selected;\r
- })*/\r
- });\r
- \r
- \r
- }\r
- };\r
- \r
- $scope.toggleChildRole = function(selected,availableRole) {\r
- //alert('toggleRole: '+selected);\r
-\r
- if(!selected) {\r
- //remove role\r
- if(role.id==null){\r
- var index = $scope.role.childRoles.indexOf(availableRole);\r
- if(index>=0)\r
- $scope.role.childRoles.splice(index, 1);\r
- return;\r
- }\r
- var uuu = conf.api.toggleRoleChildRole +"?role_id=" + roleId;\r
- \r
- 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(\r
- function(confirmed){\r
- if(confirmed) {\r
- \r
- var postData={childRole:availableRole};\r
- $http.post(uuu,postData).then(function(response) {\r
- $scope.role=response.data.role;\r
- },\r
- function(data) {\r
- confirmBoxService.showInformation("Error while saving.");\r
- });\r
- } else {\r
- availableRole.selected=false;\r
- }\r
- });\r
- /* $.ajax({\r
- type : 'POST',\r
- url : uuu,\r
- dataType: 'json',\r
- contentType: 'application/json',\r
- data: JSON.stringify(postData),\r
- success : function(data){\r
- console.log('role',data.role);\r
- $scope.$apply(function(){$scope.role=data.role;}); \r
- },\r
- error : function(data){\r
- modalService.showFailure("Fail","Error while saving.");\r
- }\r
- });\r
- */\r
- \r
- \r
- } else {\r
- //add role\r
- if(role.id==null){\r
- $scope.role.childRoles.push(availableRole);\r
- return;\r
- }\r
- var uuu = conf.api.addRoleChildRole +"?role_id=" + roleId;\r
- \r
- 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(\r
- function(confirmed){\r
- if(confirmed) {\r
- var postData={childRole:availableRole};\r
- $http.post(uuu,postData).then(function(response) {\r
- $scope.role=response.data.role;\r
- },\r
- function(data) {\r
- confirmBoxService.showInformation("Error while saving.");\r
- });\r
- } else {\r
- availableRole.selected=false;\r
- }\r
- /* $.ajax({\r
- type : 'POST',\r
- url : uuu,\r
- dataType: 'json',\r
- contentType: 'application/json',\r
- data: JSON.stringify(postData),\r
- success : function(data){\r
- $scope.$apply(function(){$scope.role=data.role;}); \r
- },\r
- error : function(data){\r
- modalService.showFailure("Fail","Error while saving.");\r
- }\r
- });*/\r
- \r
- });\r
- \r
- \r
- }\r
- };\r
- \r
- $scope.close = function() {\r
- console.log('role', $scope.role);\r
- //$modalInstance.close({role:$scope.role});\r
- this.closeThisDialog(true);\r
- };\r
- \r
-});\r
+/*-
+ * ================================================================================
+ * 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);
+ };
+
+});