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', ['$scope', 'PolicyAppService', 'policyNavigator', 'modalService', '$modal', 'Notification', function ($scope, PolicyAppService, PolicyNavigator, modalService, $modal, Notification) {
24 $scope.policyNavigator;
25 $scope.savebutton = true;
26 $scope.refreshCheck = false;
28 $scope.refresh = function(){
29 if($scope.refreshCheck){
30 $scope.policyNavigator.refresh();
32 $scope.modal('createNewPolicy', true);
35 $scope.modal = function(id, hide) {
36 return $('#' + id).modal(hide ? 'hide' : 'show');
39 PolicyAppService.getData('getDictionary/get_EcompNameDataByName').then(function (data) {
41 $scope.data = JSON.parse(j.data);
42 console.log($scope.data);
43 $scope.ecompNameDictionaryDatas = JSON.parse($scope.data.ecompNameDictionaryDatas);
44 console.log($scope.ecompNameDictionaryDatas);
46 console.log("failed");
49 PolicyAppService.getData('getDictionary/get_AttributeDatabyAttributeName').then(function (data) {
51 $scope.data = JSON.parse(j.data);
52 console.log($scope.data);
53 $scope.attributeDictionaryDatas = JSON.parse($scope.data.attributeDictionaryDatas);
54 console.log($scope.attributeDictionaryDatas);
56 console.log("failed");
59 PolicyAppService.getData('getDictionary/get_RiskTypeDataByName').then(function (data) {
61 $scope.data = JSON.parse(j.data);
62 console.log($scope.data);
63 $scope.riskTypeDictionaryDatas = JSON.parse($scope.data.riskTypeDictionaryDatas);
64 console.log($scope.riskTypeDictionaryDatas);
66 console.log("failed");
70 function extend(obj, src) {
71 for (var key in src) {
72 if (src.hasOwnProperty(key)) obj[key] = src[key];
77 $scope.savePolicy = function(policy){
78 if(policy.itemContent != undefined){
79 $scope.refreshCheck = true;
80 $scope.policyNavigator = policy.itemContent;
81 policy.itemContent = "";
83 $scope.savebutton = false;
84 var uuu = "policycreation/save_policy";
85 var postData={policyData: policy};
90 contentType: 'application/json',
91 data: JSON.stringify(postData),
92 success : function(data){
93 $scope.$apply(function(){
94 $scope.data=data.policyData;
95 if($scope.data == 'success'){
96 $scope.temp.policy.readOnly = 'true';
97 Notification.success("Policy Saved Successfully.");
98 }else if ($scope.data == 'PolicyExists'){
99 $scope.savebutton = true;
100 Notification.error("Policy Already Exists with Same Name in Scope.");
104 error : function(data){
105 Notification.error("Error Occured while saving Policy.");
106 $scope.savebutton = true;
112 $scope.validatePolicy = function(policy){
113 $scope.scope = policy.domain;
114 document.getElementById("validate").innerHTML = "";
115 var uuu = "policyController/validate_policy.htm";
116 var postData={policyData: policy};
121 contentType: 'application/json',
122 data: JSON.stringify(postData),
123 success : function(data){
124 $scope.$apply(function(){
125 $scope.validateData = data.data.replace(/\"/g, "");
126 $scope.data=data.data.substring(1,8);
127 var size = data.data.length;
128 if($scope.data == 'success'){
129 Notification.success("Validation Success.");
130 $scope.savebutton = false;
132 var displayWarning = data.data.substring(19,size);
133 document.getElementById("validate").innerHTML = "Safe Policy Warning Message : "+displayWarning;
134 document.getElementById("validate").style.color = "white";
135 document.getElementById("validate").style.backgroundColor = "skyblue";
138 Notification.error("Validation Failed.");
139 document.getElementById("validate").innerHTML = $scope.validateData;
140 document.getElementById("validate").style.color = "white";
141 document.getElementById("validate").style.backgroundColor = "red";
142 $scope.savebutton = true;
146 error : function(data){
147 Notification.error("Validation Failed.");
148 $scope.savebutton = true;
153 if(!$scope.temp.policy.editPolicy && !$scope.temp.policy.readOnly){
154 $scope.temp.policy.attributes = [];
156 if($scope.temp.policy.attributes.length == 0){
157 $scope.temp.policy.attributes = [];
162 $scope.attributeDatas = [{"attributes" : $scope.temp.policy.attributes}];
163 $scope.addNewChoice = function() {
164 var newItemNo = $scope.temp.policy.attributes .length+1;
165 $scope.temp.policy.attributes.push({'id':'choice'+newItemNo});
167 $scope.removeChoice = function() {
168 var lastItem = $scope.temp.policy.attributes.length-1;
169 $scope.temp.policy.attributes.splice(lastItem);