Initial OpenECOMP policy/engine commit
[policy/engine.git] / ecomp-sdk-app / src / main / webapp / app / policyApp / controller / dictionaryController / FWServiceGroupDictController.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 editFWServiceGroupController =  function ($scope, $modalInstance, message, PapUrlService, UserInfoService, FWDictionaryService, Notification){
24     if(message.serviceGroupDictionaryData==null){
25         $scope.slchoices = [];
26         $scope.label='Add Service Group'
27     }else{
28         $scope.label='Edit Service Group'
29         $scope.disableCd=true;
30         $scope.slchoices = [];
31         var headers = message.serviceGroupDictionaryData.serviceList;
32         var splitEqual = ',';
33         if(headers != null){
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.slchoices.push({'id':'choice'+i+1, 'option': key});
39                         }
40                 }else{
41                         var key  = headers;
42                         $scope.slchoices.push({'id':'choice'+1, 'option': key});
43                 }
44         }
45     }
46     
47         var papUrl;
48         PapUrlService.getPapUrl().then(function(data) {
49                 var config = data;
50                 papUrl = config.PAP_URL;
51                 console.log(papUrl);
52                 
53                 FWDictionaryService.getServiceListDictionaryDataByName(papUrl).then(function (data) {
54                         var j = data;
55                         $scope.data = JSON.parse(j.data);
56                         console.log($scope.data);
57                         $scope.serviceListDictionaryDatas = JSON.parse($scope.data.serviceListDictionaryDatas);
58                         console.log($scope.serviceListDictionaryDatas);
59                 }, function (error) {
60                         console.log("failed");
61                 });
62         });
63         
64         /*getting user info from session*/
65         var loginId = null;
66         UserInfoService.getFunctionalMenuStaticDetailSession()
67                 .then(function (response) {                     
68                         loginId = response.userid;              
69          });
70         
71     $scope.editServiceGroup = message.serviceGroupDictionaryData;
72
73     $scope.saveFWServiceGroup = function(serviceGroupDictionaryData) {
74         var finalData = extend(serviceGroupDictionaryData, $scope.attributeDatas[0]);
75         var uuu = papUrl + "/ecomp/fw_dictionary/save_serviceGroup.htm";
76         var postData={serviceGroupDictionaryData: finalData, loginId: loginId};
77         $.ajax({
78             type : 'POST',
79             url : uuu,
80             dataType: 'json',
81             contentType: 'application/json',
82             data: JSON.stringify(postData),
83             success : function(data){
84                 $scope.$apply(function(){
85                     $scope.serviceGroupDictionaryDatas=data.serviceGroupDictionaryDatas;});
86                 if($scope.serviceGroupDictionaryDatas == "Duplicate"){
87                         Notification.error("FW Service Group Dictionary exists with Same Group Name.")
88                 }else{      
89                         console.log($scope.serviceGroupDictionaryDatas);
90                     $modalInstance.close({serviceGroupDictionaryDatas:$scope.serviceGroupDictionaryDatas});
91                 }
92             },
93             error : function(data){
94                 alert("Error while saving.");
95             }
96         });
97     };
98
99     $scope.close = function() {
100         $modalInstance.close();
101     };
102     
103     function extend(obj, src) {
104         for (var key in src) {
105             if (src.hasOwnProperty(key)) obj[key] = src[key];
106         }
107         return obj;
108     }
109     
110    
111     
112     $scope.attributeDatas = [{"attributes" : $scope.slchoices}];
113     $scope.addServiceGroupNewChoice = function() {
114         var newItemNo = $scope.slchoices.length+1;
115         $scope.slchoices.push({'id':'choice'+newItemNo});
116     };
117     $scope.removeServiceGroupChoice = function() {
118         var lastItem = $scope.slchoices.length-1;
119         $scope.slchoices.splice(lastItem);
120     };
121 }