2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017, 2019 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('actionPolicyController', ['$scope', 'PolicyAppService', 'policyNavigator', 'modalService', '$modal', 'Notification', function ($scope, PolicyAppService, PolicyNavigator, modalService, $modal, Notification) {
23 $scope.policyNavigator;
24 $scope.savebutton = true;
25 $scope.refreshCheck = false;
27 if(!$scope.temp.policy.editPolicy && !$scope.temp.policy.readOnly){
28 $scope.temp.policy = {
33 $scope.refresh = function(){
34 if($scope.refreshCheck){
35 $scope.policyNavigator.refresh();
37 $scope.modal('createNewPolicy', true);
38 $scope.temp.policy = "";
41 $scope.modal = function(id, hide) {
42 return $('#' + id).modal(hide ? 'hide' : 'show');
45 PolicyAppService.getData('getDictionary/get_ActionPolicyDictDataByName').then(function (data) {
47 $scope.data = JSON.parse(j.data);
48 console.log($scope.data);
49 $scope.actionPolicyDictionaryDatas = JSON.parse($scope.data.actionPolicyDictionaryDatas);
50 console.log($scope.actionPolicyDictionaryDatas);
52 console.log("failed");
55 PolicyAppService.getData('getDictionary/get_AttributeDatabyAttributeName').then(function (data) {
57 $scope.data = JSON.parse(j.data);
58 console.log($scope.data);
59 $scope.attributeDictionaryDatas = JSON.parse($scope.data.attributeDictionaryDatas);
60 console.log($scope.attributeDictionaryDatas);
62 console.log("failed");
65 PolicyAppService.getData('get_FunctionDefinitionDataByName').then(function (data) {
67 $scope.data = JSON.parse(j.data);
68 console.log($scope.data);
69 $scope.functionDefinitionDatas = JSON.parse($scope.data.functionDefinitionDatas);
70 console.log($scope.functionDefinitionDatas);
72 console.log("failed");
75 $scope.saveActionPolicy = function(policy){
76 if(policy.itemContent != undefined){
77 $scope.refreshCheck = true;
78 $scope.policyNavigator = policy.itemContent;
79 policy.itemContent = "";
81 $scope.savebutton = false;
82 var uuu = "policycreation/save_policy";
83 var postData={policyData: policy};
88 contentType: 'application/json',
89 data: JSON.stringify(postData),
90 success : function(data){
91 $scope.$apply(function(){
92 $scope.data=data.policyData;
93 if($scope.data == 'success'){
94 $scope.temp.policy.readOnly = 'true';
95 Notification.success("Policy Saved Successfully.");
96 }else if ($scope.data == 'PolicyExists'){
97 $scope.savebutton = true;
98 Notification.error("Policy Already Exists with Same Name in Scope.");
102 error : function(data){
103 Notification.error("Error Occured while saving Policy.");
104 $scope.savebutton = true;
109 $scope.validatePolicy = function(policy){
110 document.getElementById("validate").innerHTML = "";
111 var uuu = "policyController/validate_policy.htm";
112 var postData={policyData: policy};
117 contentType: 'application/json',
118 data: JSON.stringify(postData),
119 success : function(data){
120 $scope.$apply(function(){
121 $scope.validateData = data.data.replace(/\"/g, "");
122 $scope.data=data.data;
123 if($scope.data == '"success"'){
124 Notification.success("Validation Success.");
125 $scope.savebutton = false;
127 Notification.error("Validation Failed.");
128 document.getElementById("validate").innerHTML = $scope.validateData;
129 document.getElementById("validate").style.color = "white";
130 document.getElementById("validate").style.backgroundColor = "red";
131 $scope.savebutton = true;
136 error : function(data){
137 Notification.error("Validation Failed.");
138 $scope.savebutton = true;
143 if(!$scope.temp.policy.editPolicy && !$scope.temp.policy.readOnly){
144 $scope.temp.policy.attributes = [];
145 $scope.temp.policy.attributes.push({'id':'choice'+1});
146 $scope.temp.policy.ruleAlgorithmschoices = [];
148 if($scope.temp.policy.attributes.length == 0){
149 $scope.temp.policy.attributes = [];
151 if($scope.temp.policy.ruleAlgorithmschoices.length == 0){
152 $scope.temp.policy.ruleAlgorithmschoices = [];
156 $scope.attributeDatas = [{"attributes" : $scope.temp.policy.attributes}];
157 $scope.addNewChoice = function() {
158 var newItemNo = $scope.temp.policy.attributes .length+1;
159 $scope.temp.policy.attributes.push({'id':'choice'+newItemNo});
161 $scope.removeChoice = function() {
162 var lastItem = $scope.temp.policy.attributes.length-1;
163 $scope.temp.policy.attributes.splice(lastItem);
168 $scope.ruleAlgorithmDatas = [{"ruleAlgorithms" : $scope.temp.policy.ruleAlgorithmschoices}];
170 $scope.addNewRuleAlgorithm = function(){
171 var newItemNo = $scope.temp.policy.ruleAlgorithmschoices.length+1;
172 $scope.ItemNo = newItemNo;
174 var value = newItemNo-1;
175 $scope.attributeDictionaryDatas.push('A'+value);
177 $scope.temp.policy.ruleAlgorithmschoices.push({'id':'A'+newItemNo});
181 $scope.removeRuleAlgorithm = function() {
182 var lastItem = $scope.temp.policy.ruleAlgorithmschoices.length-1;
183 $scope.ItemNo = lastItem;
184 $scope.temp.policy.ruleAlgorithmschoices.splice(lastItem);