2 * ============LICENSE_START==========================================
4 * ===================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ===================================================================
8 * Unless otherwise specified, all software contained herein is licensed
9 * under the Apache License, Version 2.0 (the "License");
10 * you may not use this software except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
21 * Unless otherwise specified, all documentation contained herein is licensed
22 * under the Creative Commons License, Attribution 4.0 Intl. (the "License");
23 * you may not use this documentation except in compliance with the License.
24 * You may obtain a copy of the License at
26 * https://creativecommons.org/licenses/by/4.0/
28 * Unless required by applicable law or agreed to in writing, documentation
29 * distributed under the License is distributed on an "AS IS" BASIS,
30 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
31 * See the License for the specific language governing permissions and
32 * limitations under the License.
34 * ============LICENSE_END============================================
36 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
38 app.controller('rolefunctionpopupController',function($scope, confirmBoxService, message, $http, $modalInstance, RoleService, conf, isEditing) {
39 if (message.availableRoleFunction == null) {
40 $scope.label = 'Add Role Function';
42 $scope.selectedAppId = message.appId;
43 $scope.defaultAction = "*";
44 $scope.disableTypeAction = true;
45 $scope.ngRepeatDemo = [
46 {id: 'menuradiobutton1', value: 'menu', labelvalue: 'menu'},
47 {id: 'urlradiobutton2', value: 'url', labelvalue: 'url'},
48 {id: 'otherradiobutton3', value: 'other', labelvalue: 'other'}
50 $scope.selectedvalueradioButtonGroup = {
53 $scope.editRoleFunction = {
57 $scope.ngRepeatDemo = [
58 {id: 'menuradiobutton1', value: 'menu', labelvalue: 'menu'},
59 {id: 'urlradiobutton2', value: 'url', labelvalue: 'url'},
60 {id: 'otherradiobutton3', value: 'other', labelvalue: 'other'}
62 $scope.label = 'Edit Role Function'
63 $scope.disableCd = true;
64 $scope.disableTypeAction = false;
65 var tempText = new String(message.availableRoleFunction.name);
66 $scope.editRoleFunction = angular.copy(message.availableRoleFunction);
67 if($scope.editRoleFunction.type.includes('menu')||$scope.editRoleFunction.type.includes('url')){
68 $scope.selectedvalueradioButtonGroup = {
69 type: $scope.editRoleFunction.type
72 $scope.selectedvalueradioButtonGroup = {
76 $scope.selectedAppId = message.appId;
78 $scope.tempText = tempText;
79 $scope.isEditing = isEditing;
81 $scope.saveRoleFunction = function(availableRoleFunction, type) {
83 if (!availableRoleFunction.hasOwnProperty('type')) {
84 availableRoleFunction['type'] = type ;
86 availableRoleFunction.type = type ;
89 if(/[^a-zA-Z0-9\-\.\_]/.test(availableRoleFunction.type)){
90 confirmBoxService.showInformation('Type can only contain alphanumeric characters, dots(.) and underscores(_)').then(isConfirmed => {});
93 if(availableRoleFunction.action !== '*' && /[^a-zA-Z0-9\-\.\_]/.test(availableRoleFunction.action)){
94 confirmBoxService.showInformation('Action can only contain alphanumeric characters, hyphens(-), dots(.) and underscores(_) and single asterisk character(*)').then(isConfirmed => {});
97 if(/[^a-zA-Z0-9\-\:\_\./*]/.test(availableRoleFunction.code)){
98 confirmBoxService.showInformation('Instance can only contain alphanumeric characters, hyphens(-), dots(.), colons(:), forwardSlash(/) , asterisk(*) and underscores(_)').then(isConfirmed => {});
101 if(/[^a-zA-Z0-9\-\_ \.]/.test(availableRoleFunction.name)){
102 confirmBoxService.showInformation('Name can only contain alphanumeric characters, spaces, hyphens(-), dots(.) and underscores(_)').then(isConfirmed => {});
105 confirmBoxService.confirm(
106 "You are about to Create the role function "+ availableRoleFunction.name+ ". Do you want to continue?")
107 .then(function(confirmed) {
109 var uuu = conf.api.saveRoleFunction.replace(':appId', $scope.selectedAppId);
110 var postData = availableRoleFunction;
111 if (availableRoleFunction == null) {
112 confirmBoxService.showInformation("Please enter valid role function details.");
114 var exists = false, x;
115 for (x in message.availableRoleFunctions) {
116 console.log(message.availableRoleFunctions[x].name);
117 if (message.availableRoleFunctions[x].type == availableRoleFunction.type
118 && message.availableRoleFunctions[x].code == availableRoleFunction.code
119 && message.availableRoleFunctions[x].action == availableRoleFunction.action
120 && message.availableRoleFunctions[x].name == availableRoleFunction.name) {
121 confirmBoxService.showInformation("Role Function already exists.");
123 availableRoleFunction.name = $scope.tempText;
127 if (message.availableRoleFunctions[x].type == availableRoleFunction.type
128 && message.availableRoleFunctions[x].code == availableRoleFunction.code
129 && message.availableRoleFunctions[x].action == availableRoleFunction.action
131 confirmBoxService.showInformation("Please make sure code, type and action is unique. Please create a role function with a different code or type or action to proceed.");
133 availableRoleFunction.name = $scope.tempText;
139 if (!exists&& availableRoleFunction.name.trim() != ''&& availableRoleFunction.code.trim() != '') {
140 $http.post(uuu,JSON.stringify(postData)).then(function(res) {
141 if(res.data.status == 'OK'){
142 confirmBoxService.showInformation(res.data.message).then(isConfirmed => {});
144 confirmBoxService.showInformation('Error:' + res.data.message).then(isConfirmed => {});
146 $scope.availableRoleFunctionsTemp = res.data.availableRoleFunctions;
147 $modalInstance.close(true);
153 $scope.close = function() {
154 this.closeThisDialog(true);