Initial OpenECOMP policy/engine commit
[policy/engine.git] / ecomp-sdk-app / src / main / webapp / app / policyApp / controller / dictionaryController / PSGroupPolicyScopeDictController.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 editPSGroupPolicyScopeController =  function ($scope, $modalInstance, message, PolicyScopeService, PapUrlService, UserInfoService, Notification){
24         $scope.edit = false;
25     if(message.groupPolicyScopeListData==null)
26         $scope.label='Add New Group Policy Scope'
27     else{
28         $scope.label='Edit Group Policy Scope'
29         $scope.disableCd=true;
30         $scope.edit = true;
31     }
32     
33         var papUrl;
34         PapUrlService.getPapUrl().then(function(data) {
35                 var config = data;
36                 papUrl = config.PAP_URL;
37                 console.log(papUrl);
38                 
39             PolicyScopeService.getPSServiceDictionaryDataByName(papUrl).then(function (data) {
40                 var j = data;
41                 $scope.data = JSON.parse(j.data);
42                 console.log($scope.data);
43                 $scope.psServiceDictionaryDatas = JSON.parse($scope.data.psServiceDictionaryDatas);
44                 console.log($scope.psServiceDictionaryDatas);
45             }, function (error) {
46                 console.log("failed");
47             });
48             
49             PolicyScopeService.getPSTypeDictionaryDataByName(papUrl).then(function (data) {
50                 var j = data;
51                 $scope.data = JSON.parse(j.data);
52                 console.log($scope.data);
53                 $scope.psTypeDictionaryDatas = JSON.parse($scope.data.psTypeDictionaryDatas);
54                 console.log($scope.psTypeDictionaryDatas);
55             }, function (error) {
56                 console.log("failed");
57             });
58             
59             PolicyScopeService.getPSResourceDictionaryDataByName(papUrl).then(function (data) {
60                 var j = data;
61                 $scope.data = JSON.parse(j.data);
62                 console.log($scope.data);
63                 $scope.psResourceDictionaryDatas = JSON.parse($scope.data.psResourceDictionaryDatas);
64                 console.log($scope.psResourceDictionaryDatas);
65             }, function (error) {
66                 console.log("failed");
67             });
68
69             PolicyScopeService.getPSClosedLoopDictionaryDataByName(papUrl).then(function (data) {
70                 var j = data;
71                 $scope.data = JSON.parse(j.data);
72                 console.log($scope.data);
73                 $scope.psClosedLoopDictionaryDatas = JSON.parse($scope.data.psClosedLoopDictionaryDatas);
74                 console.log($scope.psClosedLoopDictionaryDatas);
75             }, function (error) {
76                 console.log("failed");
77             });
78         });
79         
80         /*getting user info from session*/
81         var loginId = null;
82         UserInfoService.getFunctionalMenuStaticDetailSession()
83                 .then(function (response) {                     
84                         loginId = response.userid;              
85          });
86    
87     $scope.editPSGroupPolicyScope = message.groupPolicyScopeListData;
88     $scope.editPSGroupPolicyScope1 = {resource: [], type:[], service: [], closedloop: []};
89     if($scope.edit){
90         if(message.groupPolicyScopeListData.groupList != null){
91                 var splitValue = message.groupPolicyScopeListData.groupList.split(",");
92                 console.log(splitValue);
93                 $scope.splittedGroupListValues = [];
94                 var splitResource = splitValue[0].split("=");
95                 $scope.editPSGroupPolicyScope1.resource.push(splitResource[1]);
96                 var splitType = splitValue[1].split("=");
97                 $scope.editPSGroupPolicyScope1.type.push(splitType[1]);
98                 var splitService = splitValue[2].split("=");
99                 $scope.editPSGroupPolicyScope1.service.push(splitService[1]);
100                 var splitCloop = splitValue[3].split("=");
101                 $scope.editPSGroupPolicyScope1.closedloop.push(splitCloop[1]);
102         }       
103     }
104     
105     $scope.savePSGroupPolicyScope = function(groupPolicyScopeListData, groupPolicyScopeListData1) {
106         console.log(groupPolicyScopeListData1);
107         var uuu = papUrl + "/ecomp/ps_dictionary/save_psGroupPolicyScope.htm";
108         var postData={groupPolicyScopeListData: groupPolicyScopeListData,
109                         groupPolicyScopeListData1: groupPolicyScopeListData1, loginId: loginId};
110         $.ajax({
111             type : 'POST',
112             url : uuu,
113             dataType: 'json',
114             contentType: 'application/json',
115             data: JSON.stringify(postData),
116             success : function(data){
117                 $scope.$apply(function(){
118                         $scope.groupPolicyScopeListDatas=data.groupPolicyScopeListDatas;});
119                 if($scope.groupPolicyScopeListDatas == "Duplicate"){
120                         Notification.error("GroupPolicyScope Dictionary exists with Same Group Name.")
121                 }else if($scope.groupPolicyScopeListDatas == "DuplicateGroup"){
122                         Notification.error("GroupPolicyScope Dictionary exists with Same Group List.")
123                 }else{      
124                         console.log($scope.groupPolicyScopeListDatas);
125                         $modalInstance.close({groupPolicyScopeListDatas:$scope.groupPolicyScopeListDatas});
126                 }
127             },
128             error : function(data){
129                 alert("Error while saving.");
130             }
131         });
132     };
133
134     $scope.close = function() {
135         $modalInstance.close();
136     };
137 }