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('editActionPolicyDictController', function ($scope, $modalInstance, message, UserInfoServiceDS2, Notification){
21 if(message.actionPolicyDictionaryData==null)
22 $scope.label='Add Action Dictionary',
26 $scope.label='Edit Action Dictionary'
27 $scope.disableCd=true;
28 var headers = message.actionPolicyDictionaryData.header;
30 if (headers.indexOf(SplitChars) >= 0) {
31 var splitHeader = headers.split(SplitChars);
32 var singleHeader = splitHeader;
34 for(i = 0; i < singleHeader.length; i++){
35 if (singleHeader[i].indexOf(splitEqual) >= 0) {
36 var splitValue = singleHeader[i].split(splitEqual);
37 var key = splitValue[0];
38 var value = splitValue[1];
39 var newItemNo = $scope.choices.length+1;
40 $scope.choices.push({'id':'choice'+newItemNo, 'option': key , 'number' : value });
45 if (headers.indexOf(splitEqual) >= 0) {
46 var splitValue = headers.split(splitEqual);
47 var key = splitValue[0];
48 var value = splitValue[1];
49 $scope.choices.push({'id':'choice'+1, 'option': key , 'number' : value });
54 /*getting user info from session*/
56 UserInfoServiceDS2.getFunctionalMenuStaticDetailSession()
57 .then(function (response) {
58 userid = response.userid;
61 $scope.editActionDict = message.actionPolicyDictionaryData;
62 $scope.saveActionDict = function(actionPolicyDictionaryData) {
63 var regex = new RegExp("^[a-zA-Z0-9_]*$");
64 if(!regex.test(actionPolicyDictionaryData.attributeName)) {
65 Notification.error("Enter Valid Attribute Name without spaces or special characters");
67 var finalData = extend(actionPolicyDictionaryData, $scope.headerDatas[0]);
68 var uuu = "saveDictionary/action_dictionary/save_ActionDict";
69 var postData={actionPolicyDictionaryData: finalData, userid: userid};
74 contentType: 'application/json',
75 data: JSON.stringify(postData),
76 success : function(data){
77 $scope.$apply(function(){
78 $scope.actionPolicyDictionaryDatas=data.actionPolicyDictionaryDatas;});
79 if($scope.actionPolicyDictionaryDatas == "Duplicate"){
80 Notification.error("ActionPolicy Dictionary exists with Same Attribute Name.")
82 console.log($scope.actionPolicyDictionaryDatas);
83 $modalInstance.close({actionPolicyDictionaryDatas:$scope.actionPolicyDictionaryDatas});
86 error : function(data){
87 Notification.error("Error while saving.");
93 $scope.close = function() {
94 $modalInstance.close();
97 function extend(obj, src) {
98 for (var key in src) {
99 if (src.hasOwnProperty(key)) obj[key] = src[key];
104 $scope.headerDatas = [{"headers" : $scope.choices}];
105 $scope.addNewChoice = function() {
106 var newItemNo = $scope.choices.length+1;
107 $scope.choices.push({'id':'choice'+newItemNo});
109 $scope.removeChoice = function() {
110 var lastItem = $scope.choices.length-1;
111 $scope.choices.splice(lastItem);