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('editFWTagPickerController' , function ($scope, $modalInstance, message, UserInfoServiceDS2, Notification, PolicyAppService){
21 if(message.fwTagPickerDictionaryData==null)
22 $scope.label='Add TagPicker',
25 $scope.label='Edit TagPicker'
26 $scope.disableCd=true;
28 var headers = message.fwTagPickerDictionaryData.tagValues;
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 });
55 PolicyAppService.getData('getDictionary/get_TagListData').then(function (data) {
57 $scope.data = JSON.parse(j.data);
58 console.log($scope.data);
59 $scope.fwTagDictionaryDatas = JSON.parse($scope.data.fwTagDictionaryDatas);
60 console.log($scope.fwTagDictionaryDatas);
62 console.log("failed");
65 PolicyAppService.getData('getDictionary/get_TagNameByName').then(function (data) {
67 $scope.data = JSON.parse(j.data);
68 console.log($scope.data);
69 $scope.fwTagDictionaryKeyDatas = JSON.parse($scope.data.fwTagDictionaryDatas);
70 console.log($scope.fwTagDictionaryKeyDatas);
72 console.log("failed");
76 $scope.fwTagDictionaryDataValues = [];
77 $scope.getTagListValues = function(key){
78 for (var i = 0; i < $scope.fwTagDictionaryDatas.length; ++i) {
79 var obj = $scope.fwTagDictionaryDatas[i];
80 if (obj.fwTagName == key){
81 var splitValue = obj.tagValues.split(',');
82 for (var j = 0; j < splitValue.length; ++j) {
83 $scope.fwTagDictionaryDataValues.push(splitValue[j].split(',')[0]);
89 /*getting user info from session*/
91 UserInfoServiceDS2.getFunctionalMenuStaticDetailSession()
92 .then(function (response) {
93 userid = response.userid;
96 $scope.editFWTagPicker = message.fwTagPickerDictionaryData;
98 $scope.saveFWTagPicker = function(fwTagPickerDictionaryData) {
99 var regex = new RegExp("^[a-zA-Z0-9_]*$");
100 if(!regex.test(fwTagPickerDictionaryData.tagPickerName)) {
101 Notification.error("Enter Valid TagPicker Name without spaces or special characters");
103 var finalData = extend(fwTagPickerDictionaryData, $scope.actions[0]);
104 var uuu = "saveDictionary/fw_dictionary/save_fwTagPicker";
105 var postData={fwTagPickerDictionaryData: finalData, userid: userid};
110 contentType: 'application/json',
111 data: JSON.stringify(postData),
112 success : function(data){
113 $scope.$apply(function(){
114 $scope.fwTagPickerDictionaryDatas=data.fwTagPickerDictionaryDatas;});
115 if($scope.fwTagPickerDictionaryDatas == "Duplicate"){
116 Notification.error("TagPicker Dictionary exists with TagPicker Name.")
118 console.log($scope.fwTagPickerDictionaryDatas);
119 $modalInstance.close({fwTagPickerDictionaryDatas:$scope.fwTagPickerDictionaryDatas});
123 error : function(data){
124 alert("Error while saving.");
130 $scope.close = function() {
131 $modalInstance.close();
134 function extend(obj, src) {
135 for (var key in src) {
136 if (src.hasOwnProperty(key)) obj[key] = src[key];
141 $scope.actions = [{"tags" : $scope.choices}];
142 $scope.addNewChoice = function() {
143 var newItemNo = $scope.choices.length+1;
144 $scope.choices.push({'id':'choice'+newItemNo});
146 $scope.removeChoice = function() {
147 var lastItem = $scope.choices.length-1;
148 $scope.choices.splice(lastItem);