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 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 function extend(obj, src) {
76 for (var key in src) {
77 if (src.hasOwnProperty(key)) obj[key] = src[key];
82 $scope.saveActionPolicy = function(policy){
83 if(policy.itemContent != undefined){
84 $scope.refreshCheck = true;
85 $scope.policyNavigator = policy.itemContent;
86 policy.itemContent = "";
88 $scope.savebutton = false;
89 var uuu = "policycreation/save_policy";
90 var postData={policyData: policy};
95 contentType: 'application/json',
96 data: JSON.stringify(postData),
97 success : function(data){
98 $scope.$apply(function(){
99 $scope.data=data.policyData;
100 if($scope.data == 'success'){
101 $scope.temp.policy.readOnly = 'true';
102 Notification.success("Policy Saved Successfully.");
103 }else if ($scope.data == 'PolicyExists'){
104 $scope.savebutton = true;
105 Notification.error("Policy Already Exists with Same Name in Scope.");
109 error : function(data){
110 Notification.error("Error Occured while saving Policy.");
111 $scope.savebutton = true;
116 $scope.validatePolicy = function(policy){
117 document.getElementById("validate").innerHTML = "";
118 var uuu = "policyController/validate_policy.htm";
119 var postData={policyData: policy};
124 contentType: 'application/json',
125 data: JSON.stringify(postData),
126 success : function(data){
127 $scope.$apply(function(){
128 $scope.validateData = data.data.replace(/\"/g, "");
129 $scope.data=data.data;
130 if($scope.data == '"success"'){
131 Notification.success("Validation Success.");
132 $scope.savebutton = false;
134 Notification.error("Validation Failed.");
135 document.getElementById("validate").innerHTML = $scope.validateData;
136 document.getElementById("validate").style.color = "white";
137 document.getElementById("validate").style.backgroundColor = "red";
138 $scope.savebutton = true;
143 error : function(data){
144 Notification.error("Validation Failed.");
145 $scope.savebutton = true;
150 if(!$scope.temp.policy.editPolicy && !$scope.temp.policy.readOnly){
151 $scope.temp.policy.attributes = [];
152 $scope.temp.policy.attributes.push({'id':'choice'+1});
153 $scope.temp.policy.ruleAlgorithmschoices = [];
155 if($scope.temp.policy.attributes.length == 0){
156 $scope.temp.policy.attributes = [];
158 if($scope.temp.policy.ruleAlgorithmschoices.length == 0){
159 $scope.temp.policy.ruleAlgorithmschoices = [];
163 $scope.attributeDatas = [{"attributes" : $scope.temp.policy.attributes}];
164 $scope.addNewChoice = function() {
165 var newItemNo = $scope.temp.policy.attributes .length+1;
166 $scope.temp.policy.attributes.push({'id':'choice'+newItemNo});
168 $scope.removeChoice = function() {
169 var lastItem = $scope.temp.policy.attributes.length-1;
170 $scope.temp.policy.attributes.splice(lastItem);
175 $scope.ruleAlgorithmDatas = [{"ruleAlgorithms" : $scope.temp.policy.ruleAlgorithmschoices}];
177 $scope.addNewRuleAlgorithm = function(){
178 var newItemNo = $scope.temp.policy.ruleAlgorithmschoices.length+1;
179 $scope.ItemNo = newItemNo;
181 var value = newItemNo-1;
182 $scope.attributeDictionaryDatas.push('A'+value);
184 $scope.temp.policy.ruleAlgorithmschoices.push({'id':'A'+newItemNo});
188 $scope.removeRuleAlgorithm = function() {
189 var lastItem = $scope.temp.policy.ruleAlgorithmschoices.length-1;
190 $scope.ItemNo = lastItem;
191 $scope.temp.policy.ruleAlgorithmschoices.splice(lastItem);