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 if(!$scope.temp.policy.editPolicy && !$scope.temp.policy.readOnly){
29 $scope.temp.policy = {
30 policyType : "Config",
31 configPolicyType : "Base"
35 $scope.refresh = function(){
36 if($scope.refreshCheck){
37 $scope.policyNavigator.refresh();
39 $scope.modal('createNewPolicy', true);
40 $scope.temp.policy = "";
43 $scope.modal = function(id, hide) {
44 return $('#' + id).modal(hide ? 'hide' : 'show');
47 $('#ttlDate').datepicker({
48 dateFormat: 'dd/mm/yy',
51 onSelect: function(date) {
52 angular.element($('#ttlDate')).triggerHandler('input');
56 PolicyAppService.getData('getDictionary/get_OnapNameDataByName').then(function (data) {
58 $scope.data = JSON.parse(j.data);
59 console.log($scope.data);
60 $scope.onapNameDictionaryDatas = JSON.parse($scope.data.onapNameDictionaryDatas);
61 console.log($scope.onapNameDictionaryDatas);
63 console.log("failed");
66 PolicyAppService.getData('getDictionary/get_AttributeDatabyAttributeName').then(function (data) {
68 $scope.data = JSON.parse(j.data);
69 console.log($scope.data);
70 $scope.attributeDictionaryDatas = JSON.parse($scope.data.attributeDictionaryDatas);
71 console.log($scope.attributeDictionaryDatas);
73 console.log("failed");
76 PolicyAppService.getData('getDictionary/get_RiskTypeDataByName').then(function (data) {
78 $scope.data = JSON.parse(j.data);
79 console.log($scope.data);
80 $scope.riskTypeDictionaryDatas = JSON.parse($scope.data.riskTypeDictionaryDatas);
81 console.log($scope.riskTypeDictionaryDatas);
83 console.log("failed");
86 $scope.savePolicy = function(policy){
87 if(policy.itemContent != undefined){
88 $scope.refreshCheck = true;
89 $scope.policyNavigator = policy.itemContent;
90 policy.itemContent = "";
92 $scope.savebutton = false;
93 var uuu = "policycreation/save_policy";
94 var postData={policyData: policy};
99 contentType: 'application/json',
100 data: JSON.stringify(postData),
101 success : function(data){
102 $scope.$apply(function(){
103 $scope.data=data.policyData;
104 if($scope.data == 'success'){
105 $scope.temp.policy.readOnly = 'true';
106 Notification.success("Policy Saved Successfully.");
107 }else if ($scope.data == 'PolicyExists'){
108 $scope.savebutton = true;
109 Notification.error("Policy Already Exists with Same Name in Scope.");
113 error : function(data){
114 Notification.error("Error Occured while saving Policy.");
115 $scope.savebutton = true;
121 $scope.validatePolicy = function(policy){
122 $scope.scope = policy.domain;
123 document.getElementById("validate").innerHTML = "";
124 var uuu = "policyController/validate_policy.htm";
125 var postData={policyData: policy};
130 contentType: 'application/json',
131 data: JSON.stringify(postData),
132 success : function(data){
133 $scope.$apply(function(){
134 $scope.validateData = data.data.replace(/\"/g, "");
135 $scope.data=data.data.substring(1,8);
136 var size = data.data.length;
137 if($scope.data == 'success'){
138 Notification.success("Validation Success.");
139 $scope.savebutton = false;
141 var displayWarning = data.data.substring(19,size);
142 document.getElementById("validate").innerHTML = "Safe Policy Warning Message : "+displayWarning;
143 document.getElementById("validate").style.color = "white";
144 document.getElementById("validate").style.backgroundColor = "skyblue";
147 Notification.error("Validation Failed.");
148 document.getElementById("validate").innerHTML = $scope.validateData;
149 document.getElementById("validate").style.color = "white";
150 document.getElementById("validate").style.backgroundColor = "red";
151 $scope.savebutton = true;
155 error : function(data){
156 Notification.error("Validation Failed.");
157 $scope.savebutton = true;
162 if(!$scope.temp.policy.editPolicy && !$scope.temp.policy.readOnly){
163 $scope.temp.policy.attributes = [];
165 if($scope.temp.policy.attributes.length == 0){
166 $scope.temp.policy.attributes = [];
171 $scope.attributeDatas = [{"attributes" : $scope.temp.policy.attributes}];
172 $scope.addNewChoice = function() {
173 var newItemNo = $scope.temp.policy.attributes .length+1;
174 $scope.temp.policy.attributes.push({'id':'choice'+newItemNo});
176 $scope.removeChoice = function() {
177 var lastItem = $scope.temp.policy.attributes.length-1;
178 $scope.temp.policy.attributes.splice(lastItem);