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=========================================================
23 var editAttributeController = function ($scope, $modalInstance, message, PapUrlService, UserInfoService, Notification){
24 if(message.attributeDictionaryData==null)
25 $scope.label='Add New Attribute',
26 $scope.attributes = [];
28 $scope.attributes = [];
29 $scope.label='Edit Attribute'
30 $scope.disableCd=true;
31 var headers = message.attributeDictionaryData.attributeValue;
34 if (headers.indexOf(splitEqual) >= 0) {
35 var splitValue = headers.split(splitEqual);
36 for(i = 0; i < splitValue.length; i++){
37 var key = splitValue[i];
38 $scope.attributes.push({'id':'choice'+i+1, 'attributeValues': key});
42 $scope.attributes.push({'id':'choice'+1, 'attributeValues': key});
48 PapUrlService.getPapUrl().then(function(data) {
50 papUrl = config.PAP_URL;
54 /*getting user info from session*/
56 UserInfoService.getFunctionalMenuStaticDetailSession()
57 .then(function (response) {
58 loginId = response.userid;
61 $scope.editAttributeName = message.attributeDictionaryData;
63 $scope.saveAttributeName = function(attributeDictionaryData) {
64 var finalData = extend(attributeDictionaryData, $scope.attributeDatas[0]);
65 var uuu = papUrl + "/ecomp/attribute_dictionary/save_attribute.htm";
66 var postData={attributeDictionaryData: attributeDictionaryData, loginId: loginId};
71 contentType: 'application/json',
72 data: JSON.stringify(postData),
73 success : function(data){
74 $scope.$apply(function(){
75 $scope.attributeDictionaryDatas=data.attributeDictionaryDatas;});
76 if($scope.attributeDictionaryDatas == "Duplicate"){
77 Notification.error("Attribute Dictionary exists with Same Attribute Name.")
79 console.log($scope.attributeDictionaryDatas);
80 $modalInstance.close({attributeDictionaryDatas:$scope.attributeDictionaryDatas});
83 error : function(data){
84 alert("Error while saving.");
89 function extend(obj, src) {
90 for (var key in src) {
91 if (src.hasOwnProperty(key)) obj[key] = src[key];
96 $scope.attributeDatas = [{"userDataTypeValues" : $scope.attributes}];
97 $scope.addNewChoice = function() {
98 var newItemNo = $scope.attributes.length+1;
99 $scope.attributes.push({'id':'choice'+newItemNo});
101 $scope.removeChoice = function() {
102 var lastItem = $scope.attributes.length-1;
103 $scope.attributes.splice(lastItem);
106 $scope.close = function() {
107 $modalInstance.close();