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('editFWTagListController' , function ($scope, $modalInstance, message, UserInfoServiceDS2, Notification){
22 if(message.fwTagDictionaryDatas==null)
23 $scope.label='Add Tag',
26 $scope.label='Edit Tag'
27 $scope.disableCd=true;
29 var headers = message.fwTagDictionaryDatas.tagValues;
31 if (headers.indexOf(SplitChars) >= 0) {
32 var splitHeader = headers.split(SplitChars);
33 var singleHeader = splitHeader;
34 for(i = 0; i < singleHeader.length; i++){
35 var splitValue = singleHeader[i];
36 var newItemNo = $scope.choices.length+1;
37 $scope.choices.push({'id':'choice'+newItemNo, 'tags': splitValue });
40 $scope.choices.push({'id':'choice'+1, 'tags': headers });
44 /*getting user info from session*/
46 UserInfoServiceDS2.getFunctionalMenuStaticDetailSession()
47 .then(function (response) {
48 userid = response.userid;
51 $scope.editFWTag = message.fwTagDictionaryDatas;
53 $scope.saveFWTag = function(fwTagDictionaryData) {
54 var regex = new RegExp("^[a-zA-Z0-9_]*$");
55 if(!regex.test(fwTagDictionaryData.fwTagName)) {
56 Notification.error("Enter Valid Tag Name without spaces or special characters");
58 var finalData = extend(fwTagDictionaryData, $scope.attributeDatas[0]);
59 var uuu = "saveDictionary/fw_dictionary/save_fwTag";
60 var postData={fwTagDictionaryData: finalData, userid: userid};
65 contentType: 'application/json',
66 data: JSON.stringify(postData),
67 success : function(data){
68 $scope.$apply(function(){
69 $scope.fwTagDictionaryDatas=data.fwTagDictionaryDatas;});
70 if($scope.fwTagDictionaryDatas == "Duplicate"){
71 Notification.error("Tag Dictionary exists with Same Tag Name.")
73 console.log($scope.fwTagDictionaryDatas);
74 $modalInstance.close({fwTagDictionaryDatas:$scope.fwTagDictionaryDatas});
77 error : function(data){
78 alert("Error while saving.");
84 function extend(obj, src) {
85 for (var key in src) {
86 if (src.hasOwnProperty(key)) obj[key] = src[key];
91 $scope.attributeDatas = [{"tags" : $scope.choices}];
92 $scope.addNewChoice = function() {
93 var newItemNo = $scope.choices.length+1;
94 $scope.choices.push({'id':'choice'+newItemNo});
96 $scope.removeChoice = function() {
97 var lastItem = $scope.choices.length-1;
98 $scope.choices.splice(lastItem);
102 $scope.close = function() {
103 $modalInstance.close();