Initial OpenECOMP policy/engine commit
[policy/engine.git] / ecomp-sdk-app / src / main / webapp / app / policyApp / controller / dictionaryController / FWParentListDictController.js
1 /*-
2  * ============LICENSE_START=======================================================
3  * ECOMP Policy Engine
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
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
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=========================================================
19  */
20
21 /**
22  */
23 var editFWParentListController =  function ($scope, $modalInstance, message, PapUrlService, UserInfoService, FWDictionaryService, Notification){
24     if(message.fwDictListDictionaryData==null){
25         $scope.slchoices = [];
26         $scope.alchoices = [];
27         $scope.label='Add Parent List'
28     }else{
29         $scope.label='Edit Parent List'
30         $scope.disableCd=true;
31         $scope.slchoices = [];
32         $scope.alchoices = [];
33         var slList = message.fwDictListDictionaryData.serviceList;
34         var alList = message.fwDictListDictionaryData.addressList;    
35         var splitEqual = ',';
36         if(slList != null){
37                 if (slList.indexOf(splitEqual) >= 0) {
38                         var splitValue = slList.split(splitEqual);
39                         for(i = 0; i < splitValue.length; i++){
40                                 var key  = splitValue[i];
41                                 $scope.slchoices.push({'id':'choice'+i+1, 'option': key});
42                         }
43                 }else{
44                         var key  = slList;
45                         $scope.slchoices.push({'id':'choice'+1, 'option': key});
46                 }
47         }
48         if(alList != null){
49                 if (alList.indexOf(splitEqual) >= 0) {
50                         var splitALValue = alList.split(splitEqual);
51                         for(i = 0; i < splitALValue.length; i++){
52                                 var key  = splitALValue[i];
53                                 $scope.alchoices.push({'id':'choice'+i+1, 'option': key});
54                         }
55                 }else{
56                         var key  = alList;
57                         $scope.alchoices.push({'id':'choice'+1, 'option': key});
58                 }
59         }
60     }
61     
62         var papUrl;
63         PapUrlService.getPapUrl().then(function(data) {
64                 var config = data;
65                 papUrl = config.PAP_URL;
66                 console.log(papUrl);
67
68                 FWDictionaryService.getServiceListDictionaryDataByName(papUrl).then(function (data) {
69                         var j = data;
70                         $scope.data = JSON.parse(j.data);
71                         console.log($scope.data);
72                         $scope.serviceListDictionaryDatas = JSON.parse($scope.data.serviceListDictionaryDatas);
73                         console.log($scope.serviceListDictionaryDatas);
74                 }, function (error) {
75                         console.log("failed");
76                 });
77
78                 FWDictionaryService.getAddressGroupDictionaryDataByName(papUrl).then(function (data) {
79                         var j = data;
80                         $scope.data = JSON.parse(j.data);
81                         console.log($scope.data);
82                         $scope.addressGroupDictionaryDatas = JSON.parse($scope.data.addressGroupDictionaryDatas);
83                         console.log($scope.addressGroupDictionaryDatas);
84                 }, function (error) {
85                         console.log("failed");
86                 });
87         });
88         
89         /*getting user info from session*/
90         var loginId = null;
91         UserInfoService.getFunctionalMenuStaticDetailSession()
92                 .then(function (response) {                     
93                         loginId = response.userid;              
94          });
95         
96     $scope.editParentList = message.fwDictListDictionaryData;
97
98     $scope.saveFWParentList = function(fwDictListDictionaryData) {
99         var addSLData = extend(fwDictListDictionaryData, $scope.attributeDatas[0]);
100         var finalData = extend(addSLData, $scope.attributeALDatas[0]);
101         var uuu = papUrl + "/ecomp/fw_dictionary/save_FWDictionaryList.htm";
102         var postData={fwDictListDictionaryData: finalData, loginId: loginId};
103         $.ajax({
104             type : 'POST',
105             url : uuu,
106             dataType: 'json',
107             contentType: 'application/json',
108             data: JSON.stringify(postData),
109             success : function(data){
110                 $scope.$apply(function(){
111                     $scope.fwDictListDictionaryDatas=data.fwDictListDictionaryDatas;});
112                 if($scope.fwDictListDictionaryDatas == "Duplicate"){
113                         Notification.error("FW DictionaryList Dictionary exists with Same  Name.")
114                 }else{      
115                         console.log($scope.fwDictListDictionaryDatas);
116                     $modalInstance.close({fwDictListDictionaryDatas:$scope.fwDictListDictionaryDatas});
117                 }
118             },
119             error : function(data){
120                 alert("Error while saving.");
121             }
122         });
123     };
124
125     $scope.close = function() {
126         $modalInstance.close();
127     };
128     
129     function extend(obj, src) {
130         for (var key in src) {
131             if (src.hasOwnProperty(key)) obj[key] = src[key];
132         }
133         return obj;
134     }
135     
136  
137     $scope.attributeDatas = [{"attributes" : $scope.slchoices}];
138     $scope.addServiceGroupNewChoice = function() {
139         var newItemNo = $scope.slchoices.length+1;
140         $scope.slchoices.push({'id':'choice'+newItemNo});
141     };
142     $scope.removeServiceGroupChoice = function() {
143         var lastItem = $scope.slchoices.length-1;
144         $scope.slchoices.splice(lastItem);
145     };
146     
147     $scope.attributeALDatas = [{"alAttributes" : $scope.alchoices}];
148     $scope.addAddressGroupNewChoice = function() {
149         var newItemNo = $scope.alchoices.length+1;
150         $scope.alchoices.push({'id':'choice'+newItemNo});
151     };
152     $scope.removeAddressGroupChoice = function() {
153         var lastItem = $scope.alchoices.length-1;
154         $scope.alchoices.splice(lastItem);
155     };
156 }