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");
87 function extend(obj, src) {
88 for (var key in src) {
89 if (src.hasOwnProperty(key)) obj[key] = src[key];
94 $scope.savePolicy = function(policy){
95 if(policy.itemContent != undefined){
96 $scope.refreshCheck = true;
97 $scope.policyNavigator = policy.itemContent;
98 policy.itemContent = "";
100 $scope.savebutton = false;
101 var uuu = "policycreation/save_policy";
102 var postData={policyData: policy};
107 contentType: 'application/json',
108 data: JSON.stringify(postData),
109 success : function(data){
110 $scope.$apply(function(){
111 $scope.data=data.policyData;
112 if($scope.data == 'success'){
113 $scope.temp.policy.readOnly = 'true';
114 Notification.success("Policy Saved Successfully.");
115 }else if ($scope.data == 'PolicyExists'){
116 $scope.savebutton = true;
117 Notification.error("Policy Already Exists with Same Name in Scope.");
121 error : function(data){
122 Notification.error("Error Occured while saving Policy.");
123 $scope.savebutton = true;
129 $scope.validatePolicy = function(policy){
130 $scope.scope = policy.domain;
131 document.getElementById("validate").innerHTML = "";
132 var uuu = "policyController/validate_policy.htm";
133 var postData={policyData: policy};
138 contentType: 'application/json',
139 data: JSON.stringify(postData),
140 success : function(data){
141 $scope.$apply(function(){
142 $scope.validateData = data.data.replace(/\"/g, "");
143 $scope.data=data.data.substring(1,8);
144 var size = data.data.length;
145 if($scope.data == 'success'){
146 Notification.success("Validation Success.");
147 $scope.savebutton = false;
149 var displayWarning = data.data.substring(19,size);
150 document.getElementById("validate").innerHTML = "Safe Policy Warning Message : "+displayWarning;
151 document.getElementById("validate").style.color = "white";
152 document.getElementById("validate").style.backgroundColor = "skyblue";
155 Notification.error("Validation Failed.");
156 document.getElementById("validate").innerHTML = $scope.validateData;
157 document.getElementById("validate").style.color = "white";
158 document.getElementById("validate").style.backgroundColor = "red";
159 $scope.savebutton = true;
163 error : function(data){
164 Notification.error("Validation Failed.");
165 $scope.savebutton = true;
170 if(!$scope.temp.policy.editPolicy && !$scope.temp.policy.readOnly){
171 $scope.temp.policy.attributes = [];
173 if($scope.temp.policy.attributes.length == 0){
174 $scope.temp.policy.attributes = [];
179 $scope.attributeDatas = [{"attributes" : $scope.temp.policy.attributes}];
180 $scope.addNewChoice = function() {
181 var newItemNo = $scope.temp.policy.attributes .length+1;
182 $scope.temp.policy.attributes.push({'id':'choice'+newItemNo});
184 $scope.removeChoice = function() {
185 var lastItem = $scope.temp.policy.attributes.length-1;
186 $scope.temp.policy.attributes.splice(lastItem);