Initial OpenECOMP policy/engine commit
[policy/engine.git] / ecomp-sdk-app / src / main / webapp / app / policyApp / controller / dictionaryController / CLPepOptionsDictController.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 editPEPOptionsController =  function ($scope, $modalInstance, message, PapUrlService, UserInfoService, Notification){
24     if(message.pepOptionsDictionaryData==null)
25         $scope.label='Add PEP Options',
26         $scope.choices = [];
27     else{
28         $scope.label='Edit PEP Options'
29         $scope.disableCd=true;
30         $scope.choices = [];
31         var headers = message.pepOptionsDictionaryData.actions;
32         var SplitChars = ':#@';
33         if (headers.indexOf(SplitChars) >= 0) {
34             var splitHeader = headers.split(SplitChars);
35             var singleHeader  = splitHeader;
36             var splitEqual = '=#@';
37             for(i = 0; i < singleHeader.length; i++){
38                  if (singleHeader[i].indexOf(splitEqual) >= 0) {
39                         var splitValue = singleHeader[i].split(splitEqual);
40                         var key  = splitValue[0];
41                         var value = splitValue[1];
42                         var newItemNo = $scope.choices.length+1;
43                         $scope.choices.push({'id':'choice'+newItemNo, 'option': key , 'number' : value });
44                  }
45             }
46         }else{
47                  var splitEqual = '=#@';
48              if (headers.indexOf(splitEqual) >= 0) {
49                  var splitValue = headers.split(splitEqual);
50                  var key  = splitValue[0];
51                  var value = splitValue[1];
52                  $scope.choices.push({'id':'choice'+1, 'option': key , 'number' : value });
53              }
54         }
55     }
56     
57         var papUrl;
58         PapUrlService.getPapUrl().then(function(data) {
59                 var config = data;
60                 papUrl = config.PAP_URL;
61                 console.log(papUrl);
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.editPEPOptions = message.pepOptionsDictionaryData;
72
73     $scope.saveCLPepOptions = function(pepOptionsDictionaryData) {
74         var finalData = extend(pepOptionsDictionaryData, $scope.actions[0]);
75         var uuu = papUrl + "/ecomp/cl_dictionary/save_pepOptions.htm";
76         var postData={pepOptionsDictionaryData: 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.pepOptionsDictionaryDatas=data.pepOptionsDictionaryDatas;});
86                                         if($scope.pepOptionsDictionaryDatas == "Duplicate"){
87                                                 Notification.error("PEP Options Dictionary exists with Same PEP Name.")
88                                         }else{      
89                                                 console.log($scope.pepOptionsDictionaryDatas);
90                                                 $modalInstance.close({pepOptionsDictionaryDatas:$scope.pepOptionsDictionaryDatas});
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     $scope.actions = [{"attributes" : $scope.choices}];
111     $scope.addNewChoice = function() {
112         var newItemNo = $scope.choices.length+1;
113         $scope.choices.push({'id':'choice'+newItemNo});
114     };
115     $scope.removeChoice = function() {
116         var lastItem = $scope.choices.length-1;
117         $scope.choices.splice(lastItem);
118     };
119
120 }