2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
20 app.controller('editAttributeController' ,function ($scope, $modalInstance, message, UserInfoServiceDS2, Notification){
21 if(message.attributeDictionaryData==null)
22 $scope.label='Add New Attribute',
23 $scope.attributes = [];
25 $scope.attributes = [];
26 $scope.label='Edit Attribute'
27 $scope.disableCd=true;
28 var headers = message.attributeDictionaryData.attributeValue;
30 if(headers != null && headers != ""){
31 if (headers.indexOf(splitEqual) >= 0) {
32 var splitValue = headers.split(splitEqual);
33 for(i = 0; i < splitValue.length; i++){
34 var key = splitValue[i];
35 $scope.attributes.push({'id':'choice'+i+1, 'attributeValues': key});
39 $scope.attributes.push({'id':'choice'+1, 'attributeValues': key});
44 /*getting user info from session*/
46 UserInfoServiceDS2.getFunctionalMenuStaticDetailSession()
47 .then(function (response) {
48 userid = response.userid;
51 $scope.editAttributeName = message.attributeDictionaryData;
53 $scope.saveAttributeName = function(attributeDictionaryData) {
54 var regex = new RegExp("^[a-zA-Z0-9_]*$");
55 if(!regex.test(attributeDictionaryData.xacmlId)) {
56 Notification.error("Enter Valid Attribute Name without spaces or special characters");
58 var finalData = extend(attributeDictionaryData, $scope.attributeDatas[0]);
59 var uuu = "saveDictionary/attribute_dictionary/save_attribute";
60 var postData={attributeDictionaryData: attributeDictionaryData, userid: userid};
65 contentType: 'application/json',
66 data: JSON.stringify(postData),
67 success : function(data){
68 $scope.$apply(function(){
69 $scope.attributeDictionaryDatas=data.attributeDictionaryDatas;});
70 if($scope.attributeDictionaryDatas == "Duplicate"){
71 Notification.error("Attribute Dictionary exists with Same Attribute Name.")
73 console.log($scope.attributeDictionaryDatas);
74 $modalInstance.close({attributeDictionaryDatas:$scope.attributeDictionaryDatas});
77 error : function(data){
78 alert("Error while saving.");
84 function extend(obj, src) {
85 for (var key in src) {
86 if (src.hasOwnProperty(key)) obj[key] = src[key];
91 $scope.attributeDatas = [{"userDataTypeValues" : $scope.attributes}];
92 $scope.addNewChoice = function() {
93 var newItemNo = $scope.attributes.length+1;
94 $scope.attributes.push({'id':'choice'+newItemNo});
96 $scope.removeChoice = function() {
97 var lastItem = $scope.attributes.length-1;
98 $scope.attributes.splice(lastItem);
101 $scope.close = function() {
102 $modalInstance.close();