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 app.controller('baseConfigController', function ($scope, PolicyDictionaryService,modalService, PapUrlService, $modal, Notification) {
26 $scope.savebutton = true;
28 $scope.temp.policy.ttlDate = new Date($scope.temp.policy.ttlDate);
29 PapUrlService.getPapUrl().then(function(data) {
32 papUrl = config.PAP_URL;
35 PolicyDictionaryService.getEcompDictionaryData(papUrl).then(function (data) {
37 $scope.data = JSON.parse(j.data);
38 console.log($scope.data);
39 $scope.ecompNameDictionaryDatas = JSON.parse($scope.data.ecompNameDictionaryDatas);
40 console.log($scope.ecompNameDictionaryDatas);
42 console.log("failed");
45 PolicyDictionaryService.getAttributeDictionaryData(papUrl).then(function (data) {
47 $scope.data = JSON.parse(j.data);
48 console.log($scope.data);
49 $scope.attributeDictionaryDatas = JSON.parse($scope.data.attributeDictionaryDatas);
50 console.log($scope.attributeDictionaryDatas);
52 console.log("failed");
55 PolicyDictionaryService.getRiskTypeDictionaryData(papUrl).then(function (data) {
57 $scope.data = JSON.parse(j.data);
58 console.log($scope.data);
59 $scope.riskTypeDictionaryDatas = JSON.parse($scope.data.riskTypeDictionaryDatas);
60 console.log($scope.riskTypeDictionaryDatas);
62 console.log("failed");
64 PolicyDictionaryService.getRiskLevelValueData().then(function (data) {
66 $scope.data = JSON.parse(j.data);
67 console.log($scope.data);
68 $scope.riskLevelDatas = JSON.parse($scope.data.riskLevelDatas);
69 console.log($scope.riskLevelDatas);
71 console.log("failed");
73 PolicyDictionaryService.getGuardValueData().then(function (data) {
75 $scope.data = JSON.parse(j.data);
76 console.log($scope.data);
77 $scope.guardDatas = JSON.parse($scope.data.guardDatas);
78 console.log($scope.guardDatas);
80 console.log("failed");
85 function extend(obj, src) {
86 for (var key in src) {
87 if (src.hasOwnProperty(key)) obj[key] = src[key];
92 $scope.close = function(){
96 $scope.savePolicy = function(policy){
98 var uuu = "policyController/save_policy.htm";
99 var postData={policyData: policy};
104 contentType: 'application/json',
105 data: JSON.stringify(postData),
106 success : function(data){
107 $scope.$apply(function(){
108 $scope.data=data.data;
109 $scope.temp.policy.readOnly = 'true';
110 Notification.success("Policy Saved Successfully.");
112 console.log($scope.data);
113 $modalInstance.close();
116 error : function(data){
117 Notification.error("Error Occured while saving Policy.");
122 $scope.validatePolicyName = false;
123 $scope.validateEcompName = false;
124 $scope.validateConfigName = false;
125 $scope.validateConfigType = false;
126 $scope.validateConfigTypeNull = false;
127 $scope.validateConfigTypeBody = false;
128 $scope.validateRiskType = false;
129 $scope.validateRiskLevel = false;
130 $scope.validateGuard = false;
131 $scope.policyNameErrorMessage = "";
132 $scope.errorMessage = "";
133 $scope.validatePolicy = function(policy){
135 var uuu = "policyController/validate_policy.htm";
136 var postData={policyData: policy};
141 contentType: 'application/json',
142 data: JSON.stringify(postData),
143 success : function(data){
144 $scope.$apply(function(){
145 $scope.data=data.data.substring(1,8);
146 var size = data.data.length;
147 if($scope.data == 'success'){
148 Notification.success("Validation Success.");
149 $scope.savebutton = false;
151 var displayWarning = data.data.substring(19,size);
152 window.alert(displayWarning);
155 Notification.error("Validation Failed.");
159 error : function(data){
160 Notification.error("Validation Failed.");
161 $scope.savebutton = true;
166 if(!$scope.temp.policy.editPolicy && !$scope.temp.policy.readOnly){
167 $scope.temp.policy.attributes = [];
169 if($scope.temp.policy.attributes.length == 0){
170 $scope.temp.policy.attributes = [];
175 $scope.attributeDatas = [{"attributes" : $scope.temp.policy.attributes}];
176 $scope.addNewChoice = function() {
177 var newItemNo = $scope.temp.policy.attributes .length+1;
178 $scope.temp.policy.attributes.push({'id':'choice'+newItemNo});
180 $scope.removeChoice = function() {
181 var lastItem = $scope.temp.policy.attributes.length-1;
182 $scope.temp.policy.attributes.splice(lastItem);