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('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 $scope.refresh = function(){
28 if($scope.refreshCheck){
29 $scope.policyNavigator.refresh();
31 $scope.modal('createNewPolicy', true);
32 $scope.temp.policy = "";
35 $scope.modal = function(id, hide) {
36 return $('#' + id).modal(hide ? 'hide' : 'show');
39 PolicyAppService.getData('getDictionary/get_ActionPolicyDictDataByName').then(function (data) {
41 $scope.data = JSON.parse(j.data);
42 console.log($scope.data);
43 $scope.actionPolicyDictionaryDatas = JSON.parse($scope.data.actionPolicyDictionaryDatas);
44 console.log($scope.actionPolicyDictionaryDatas);
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('get_FunctionDefinitionDataByName').then(function (data) {
61 $scope.data = JSON.parse(j.data);
62 console.log($scope.data);
63 $scope.functionDefinitionDatas = JSON.parse($scope.data.functionDefinitionDatas);
64 console.log($scope.functionDefinitionDatas);
66 console.log("failed");
69 function extend(obj, src) {
70 for (var key in src) {
71 if (src.hasOwnProperty(key)) obj[key] = src[key];
76 $scope.saveActionPolicy = function(policy){
77 if(policy.itemContent != undefined){
78 $scope.refreshCheck = true;
79 $scope.policyNavigator = policy.itemContent;
80 policy.itemContent = "";
82 $scope.savebutton = false;
83 var uuu = "policycreation/save_policy";
84 var postData={policyData: policy};
89 contentType: 'application/json',
90 data: JSON.stringify(postData),
91 success : function(data){
92 $scope.$apply(function(){
93 $scope.data=data.policyData;
94 if($scope.data == 'success'){
95 $scope.temp.policy.readOnly = 'true';
96 Notification.success("Policy Saved Successfully.");
97 }else if ($scope.data == 'PolicyExists'){
98 $scope.savebutton = true;
99 Notification.error("Policy Already Exists with Same Name in Scope.");
103 error : function(data){
104 Notification.error("Error Occured while saving Policy.");
105 $scope.savebutton = true;
110 $scope.validatePolicy = function(policy){
111 document.getElementById("validate").innerHTML = "";
112 var uuu = "policyController/validate_policy.htm";
113 var postData={policyData: policy};
118 contentType: 'application/json',
119 data: JSON.stringify(postData),
120 success : function(data){
121 $scope.$apply(function(){
122 $scope.validateData = data.data.replace(/\"/g, "");
123 $scope.data=data.data;
124 if($scope.data == '"success"'){
125 Notification.success("Validation Success.");
126 $scope.savebutton = false;
128 Notification.error("Validation Failed.");
129 document.getElementById("validate").innerHTML = $scope.validateData;
130 document.getElementById("validate").style.color = "white";
131 document.getElementById("validate").style.backgroundColor = "red";
132 $scope.savebutton = true;
137 error : function(data){
138 Notification.error("Validation Failed.");
139 $scope.savebutton = true;
144 if(!$scope.temp.policy.editPolicy && !$scope.temp.policy.readOnly){
145 $scope.temp.policy.attributes = [];
146 $scope.temp.policy.attributes.push({'id':'choice'+1});
147 $scope.temp.policy.ruleAlgorithmschoices = [];
149 if($scope.temp.policy.attributes.length == 0){
150 $scope.temp.policy.attributes = [];
152 if($scope.temp.policy.ruleAlgorithmschoices.length == 0){
153 $scope.temp.policy.ruleAlgorithmschoices = [];
157 $scope.attributeDatas = [{"attributes" : $scope.temp.policy.attributes}];
158 $scope.addNewChoice = function() {
159 var newItemNo = $scope.temp.policy.attributes .length+1;
160 $scope.temp.policy.attributes.push({'id':'choice'+newItemNo});
162 $scope.removeChoice = function() {
163 var lastItem = $scope.temp.policy.attributes.length-1;
164 $scope.temp.policy.attributes.splice(lastItem);
169 $scope.ruleAlgorithmDatas = [{"ruleAlgorithms" : $scope.temp.policy.ruleAlgorithmschoices}];
171 $scope.addNewRuleAlgorithm = function(){
172 var newItemNo = $scope.temp.policy.ruleAlgorithmschoices.length+1;
173 $scope.ItemNo = newItemNo;
175 var value = newItemNo-1;
176 $scope.attributeDictionaryDatas.push('A'+value);
178 $scope.temp.policy.ruleAlgorithmschoices.push({'id':'A'+newItemNo});
182 $scope.removeRuleAlgorithm = function() {
183 var lastItem = $scope.temp.policy.ruleAlgorithmschoices.length-1;
184 $scope.ItemNo = lastItem;
185 $scope.temp.policy.ruleAlgorithmschoices.splice(lastItem);