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=========================================================
20 app.controller('baseConfigController', function ($scope, PolicyAppService, modalService, $modal, Notification) {
23 $scope.savebutton = true;
25 PolicyAppService.getData('getDictionary/get_EcompNameDataByName').then(function (data) {
27 $scope.data = JSON.parse(j.data);
28 console.log($scope.data);
29 $scope.ecompNameDictionaryDatas = JSON.parse($scope.data.ecompNameDictionaryDatas);
30 console.log($scope.ecompNameDictionaryDatas);
32 console.log("failed");
35 PolicyAppService.getData('getDictionary/get_AttributeDatabyAttributeName').then(function (data) {
37 $scope.data = JSON.parse(j.data);
38 console.log($scope.data);
39 $scope.attributeDictionaryDatas = JSON.parse($scope.data.attributeDictionaryDatas);
40 console.log($scope.attributeDictionaryDatas);
42 console.log("failed");
45 PolicyAppService.getData('getDictionary/get_RiskTypeDataByName').then(function (data) {
47 $scope.data = JSON.parse(j.data);
48 console.log($scope.data);
49 $scope.riskTypeDictionaryDatas = JSON.parse($scope.data.riskTypeDictionaryDatas);
50 console.log($scope.riskTypeDictionaryDatas);
52 console.log("failed");
56 function extend(obj, src) {
57 for (var key in src) {
58 if (src.hasOwnProperty(key)) obj[key] = src[key];
63 $scope.savePolicy = function(policy){
64 $scope.savebutton = false;
66 var uuu = "policycreation/save_policy";
67 var postData={policyData: policy};
72 contentType: 'application/json',
73 data: JSON.stringify(postData),
74 success : function(data){
75 $scope.$apply(function(){
76 $scope.data=data.policyData;
77 if($scope.data == 'success'){
78 $scope.temp.policy.readOnly = 'true';
79 Notification.success("Policy Saved Successfully.");
80 }else if ($scope.data == 'PolicyExists'){
81 $scope.savebutton = true;
82 Notification.error("Policy Already Exists with Same Name in Scope.");
86 error : function(data){
87 Notification.error("Error Occured while saving Policy.");
88 $scope.savebutton = true;
94 $scope.validatePolicy = function(policy){
96 document.getElementById("validate").innerHTML = "";
97 var uuu = "policyController/validate_policy.htm";
98 var postData={policyData: policy};
103 contentType: 'application/json',
104 data: JSON.stringify(postData),
105 success : function(data){
106 $scope.$apply(function(){
107 $scope.validateData = data.data.replace(/\"/g, "");
108 $scope.data=data.data.substring(1,8);
109 var size = data.data.length;
110 if($scope.data == 'success'){
111 Notification.success("Validation Success.");
112 $scope.savebutton = false;
114 var displayWarning = data.data.substring(19,size);
115 document.getElementById("validate").innerHTML = "Safe Policy Warning Message : "+displayWarning;
116 document.getElementById("validate").style.color = "white";
117 document.getElementById("validate").style.backgroundColor = "skyblue";
120 Notification.error("Validation Failed.");
121 document.getElementById("validate").innerHTML = $scope.validateData;
122 document.getElementById("validate").style.color = "white";
123 document.getElementById("validate").style.backgroundColor = "red";
124 $scope.savebutton = true;
128 error : function(data){
129 Notification.error("Validation Failed.");
130 $scope.savebutton = true;
135 if(!$scope.temp.policy.editPolicy && !$scope.temp.policy.readOnly){
136 $scope.temp.policy.attributes = [];
138 if($scope.temp.policy.attributes.length == 0){
139 $scope.temp.policy.attributes = [];
144 $scope.attributeDatas = [{"attributes" : $scope.temp.policy.attributes}];
145 $scope.addNewChoice = function() {
146 var newItemNo = $scope.temp.policy.attributes .length+1;
147 $scope.temp.policy.attributes.push({'id':'choice'+newItemNo});
149 $scope.removeChoice = function() {
150 var lastItem = $scope.temp.policy.attributes.length-1;
151 $scope.temp.policy.attributes.splice(lastItem);