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);
33 $scope.temp.policy = "";
36 $scope.modal = function(id, hide) {
37 return $('#' + id).modal(hide ? 'hide' : 'show');
40 $('#ttlDate').datepicker({
41 dateFormat: 'dd/mm/yy',
44 onSelect: function(date) {
45 angular.element($('#ttlDate')).triggerHandler('input');
49 PolicyAppService.getData('getDictionary/get_OnapNameDataByName').then(function (data) {
51 $scope.data = JSON.parse(j.data);
52 console.log($scope.data);
53 $scope.onapNameDictionaryDatas = JSON.parse($scope.data.onapNameDictionaryDatas);
54 console.log($scope.onapNameDictionaryDatas);
56 console.log("failed");
59 PolicyAppService.getData('getDictionary/get_AttributeDatabyAttributeName').then(function (data) {
61 $scope.data = JSON.parse(j.data);
62 console.log($scope.data);
63 $scope.attributeDictionaryDatas = JSON.parse($scope.data.attributeDictionaryDatas);
64 console.log($scope.attributeDictionaryDatas);
66 console.log("failed");
69 PolicyAppService.getData('getDictionary/get_RiskTypeDataByName').then(function (data) {
71 $scope.data = JSON.parse(j.data);
72 console.log($scope.data);
73 $scope.riskTypeDictionaryDatas = JSON.parse($scope.data.riskTypeDictionaryDatas);
74 console.log($scope.riskTypeDictionaryDatas);
76 console.log("failed");
80 function extend(obj, src) {
81 for (var key in src) {
82 if (src.hasOwnProperty(key)) obj[key] = src[key];
87 $scope.savePolicy = function(policy){
88 if(policy.itemContent != undefined){
89 $scope.refreshCheck = true;
90 $scope.policyNavigator = policy.itemContent;
91 policy.itemContent = "";
93 $scope.savebutton = false;
94 var uuu = "policycreation/save_policy";
95 var postData={policyData: policy};
100 contentType: 'application/json',
101 data: JSON.stringify(postData),
102 success : function(data){
103 $scope.$apply(function(){
104 $scope.data=data.policyData;
105 if($scope.data == 'success'){
106 $scope.temp.policy.readOnly = 'true';
107 Notification.success("Policy Saved Successfully.");
108 }else if ($scope.data == 'PolicyExists'){
109 $scope.savebutton = true;
110 Notification.error("Policy Already Exists with Same Name in Scope.");
114 error : function(data){
115 Notification.error("Error Occured while saving Policy.");
116 $scope.savebutton = true;
122 $scope.validatePolicy = function(policy){
123 $scope.scope = policy.domain;
124 document.getElementById("validate").innerHTML = "";
125 var uuu = "policyController/validate_policy.htm";
126 var postData={policyData: policy};
131 contentType: 'application/json',
132 data: JSON.stringify(postData),
133 success : function(data){
134 $scope.$apply(function(){
135 $scope.validateData = data.data.replace(/\"/g, "");
136 $scope.data=data.data.substring(1,8);
137 var size = data.data.length;
138 if($scope.data == 'success'){
139 Notification.success("Validation Success.");
140 $scope.savebutton = false;
142 var displayWarning = data.data.substring(19,size);
143 document.getElementById("validate").innerHTML = "Safe Policy Warning Message : "+displayWarning;
144 document.getElementById("validate").style.color = "white";
145 document.getElementById("validate").style.backgroundColor = "skyblue";
148 Notification.error("Validation Failed.");
149 document.getElementById("validate").innerHTML = $scope.validateData;
150 document.getElementById("validate").style.color = "white";
151 document.getElementById("validate").style.backgroundColor = "red";
152 $scope.savebutton = true;
156 error : function(data){
157 Notification.error("Validation Failed.");
158 $scope.savebutton = true;
163 if(!$scope.temp.policy.editPolicy && !$scope.temp.policy.readOnly){
164 $scope.temp.policy.attributes = [];
166 if($scope.temp.policy.attributes.length == 0){
167 $scope.temp.policy.attributes = [];
172 $scope.attributeDatas = [{"attributes" : $scope.temp.policy.attributes}];
173 $scope.addNewChoice = function() {
174 var newItemNo = $scope.temp.policy.attributes .length+1;
175 $scope.temp.policy.attributes.push({'id':'choice'+newItemNo});
177 $scope.removeChoice = function() {
178 var lastItem = $scope.temp.policy.attributes.length-1;
179 $scope.temp.policy.attributes.splice(lastItem);