2 * ================================================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property
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 * ================================================================================
20 var fn_menu_popupController = function ($scope, $modalInstance, message, $http){ /// examine the LeftMenuService
21 if(message.availableFnMenuItem==null)
22 $scope.label='Add New Menu Item'
25 $scope.label='Edit Menu Item'
26 //$scope.disableParentId=true;
29 $scope.getParentData = function(){
30 var uuu = "admin_fn_menu/get_parent_list"
34 dataType: 'json', // data type expected from server
35 contentType: 'application/json',
36 //data: JSON.stringify(postData), // data type sent to server
37 success : function(data){
38 $scope.$apply(function(){
39 //$scope.availableRoleFunctions=[];$scope.$apply();
40 $scope.parentListSelectData=data; // data from server
41 menuItems = $scope.parentListSelectData;
42 var heirarchicalMenuItems = [];
44 for ( var i=0; i<menuItems.length; i++){
45 for(var j=0; j<menuItems.length; j++){
46 if(menuItems[j][2]==menuItems[i][0])
49 menuId: menuItems[j][0],
50 label: menuItems[j][1]
54 if(children.length!=0){
55 heirarchicalMenuItems.push(
58 menuId: menuItems[i][0],
59 label: menuItems[i][1],
60 children: children.sort($scope.sortItems("label"))
68 heirarchicalMenuItems.sort($scope.sortItems("label"));
69 $scope.childListSelectData = heirarchicalMenuItems;
72 //$scope.editRoleFunction = null;
73 ///$modalInstance.close({functionCDselectData:$scope.functionCDselectData});
75 error : function(data){
76 alert("Parent Data not available !");
82 $scope.sortItems = function(prop){
83 return function(a, b) {
84 if (a[prop] > b[prop]) {
86 } else if (a[prop] < b[prop]) {
94 $scope.getParentLabel = function(parentId, parentListSelectData){
96 element = parentListSelectData[0];
97 for (var i=0; i<parentListSelectData.length; i++){
99 element = parentListSelectData[i];
100 if (element[0] == parentId)
107 $scope.getFunctionCDselectData = function(){
108 var uuu = "admin_fn_menu/get_function_cd_list"
112 dataType: 'json', // data type expected from server
113 contentType: 'application/json',
114 //data: JSON.stringify(postData), // data type sent to server
115 success : function(data){
116 $scope.$apply(function(){
117 //$scope.availableRoleFunctions=[];$scope.$apply();
118 $scope.functionCDselectData=data;
120 //alert("Update Successful.") ;
121 //$scope.editRoleFunction = null;
122 ///$modalInstance.close({functionCDselectData:$scope.functionCDselectData});
124 error : function(data){
125 alert("Function Code Data not available !");
131 if(message.availableFnMenuItem){
132 $scope.addFnMenuItem = message.availableFnMenuItem;
134 $scope.addFnMenuItem = {};
136 $scope.addFnMenuItem.menuSetCode = "APP";
138 $scope.statusOptions = [
139 {index: 0, value: 'true', title: 'Y'},
140 {index: 1, value: 'false', title: 'N'}
142 $scope.selectedValue = $scope.statusOptions[0];
146 {value: 'true', name: 'Y'},
147 {value: 'false', name: 'N'}
150 selectedOption: {value: 'true', name: 'Y'}
155 $scope.activeStatusOptions = [
156 {index: 0, value: 'true', title: 'Y'},
157 {index: 1, value: 'false', title: 'N'}
159 $scope.activeSelectedValue = $scope.activeStatusOptions[0];
161 $scope.separatorStatusOptions = [
162 {index: 0, value: 'true', title: 'Y'},
163 {index: 1, value: 'false', title: 'N'}
165 $scope.separatorSelectedValue = $scope.separatorStatusOptions[1];
169 {value: 'true', name: 'Y'},
170 {value: 'false', name: 'N'}
173 selectedOption: {value: 'true', name: 'Y'}
178 $scope.updateFnMenu = function(availableFnMenuItem) {
180 if( document.getElementById("popupAddMenuItemImageSrc").value == "" ) availableFnMenuItem.imageSrc = "N/A";
181 if( document.getElementById("popupAddMenuItemTarget").value == "" ) availableFnMenuItem.target = "N/A";
182 if( document.getElementById("popupAddMenuItemExternalUrl").value == "" ) availableFnMenuItem.externalUrl = "N/A";
183 if( document.getElementById("popupAddMenuItemQueryString").value == "" ) availableFnMenuItem.queryString = "N/A";
184 if( document.getElementById("popupAddMenuItemServlet").value == "" ) availableFnMenuItem.servlet = "N/A";
186 validationRule = /^\S{3,}$/;
187 var selectedFunction = document.getElementById("repeatSelect");
188 var selectedFunctionText = selectedFunction.options[selectedFunction.selectedIndex].text;
190 (document.getElementById("popupAddMenuItemLabel").value == "" || document.getElementById("popupAddMenuItemLabel").value.replace(" ", "").length == 0 ) ||//!validationRule.test(document.getElementById("popupAddMenuItemLabel").value)) ||
191 document.getElementById("popupAddMenuItemParentId").value == "" ||
192 document.getElementById("popupAddMenuItemAction").value == "" ||
193 selectedFunctionText == "" ||
194 document.getElementById("popupAddMenuItemSortOrder").value == "" ||
195 document.getElementById("popupAddMenuItemMenuSetCode").value == ""
198 alert("please provide valid entries !");
202 var uuu = "admin_fn_menu/updateFnMenu.htm";
203 var postData={availableFnMenuItem: availableFnMenuItem};
208 //dataType: 'json', // data type expected from server
209 contentType: 'application/json',
210 data: JSON.stringify(postData), // data type sent to server
211 success : function(data){
212 $scope.$apply(function(){
213 $scope.availableFnMenuItems=data.availableFnMenuItems;
216 $modalInstance.close({availableFnMenuItems:$scope.availableRoleFunctions});
218 error : function(data){
219 alert("Error while saving.");
224 $scope.getLeftMenuItems(); // get left menu items again from database
228 $scope.getLeftMenuItems = function() {
229 return $http.get('get_menu')
230 .then(function(response) {
231 if (typeof response.data === 'object') {
232 var leftChildData=[];
233 var leftParentData=[];
234 var leftMenuItems = [];
237 if(j && j !== "null" && j!== "undefined"){
238 leftParentData = JSON.parse(j.data);
239 leftChildData = JSON.parse(j.data2);
241 throw "Get Left Menu respsone is not an object/is empty";
244 var leftChildItemList = leftChildData;
245 var pageUrl = window.location.href.split('/')[window.location.href.split('/').length-1];
246 var leftParentList = leftParentData;
247 for (var i = 0; i < leftParentList.length; i++) {
249 parentLabel : leftParentList[i].label,
250 parentAction : leftParentList[i].action,
251 parentImageSrc : leftParentList[i].imageSrc,
252 open:pageUrl==leftParentList[i].action?true:false,
253 childItemList : leftChildItemList[i]==null?'x':leftChildItemList[i]
255 leftMenuItems.push($scope.item);
258 $scope.leftMenuItems = leftMenuItems;
261 console.log("error happened while trying to set left menu structure: "+err);
264 console.log("error happened while trying to get left menu items: "+e);
268 return response.data;
270 return $q.reject(response.data);
272 }, function(response) {
273 // something went wrong
274 return $q.reject(response.data);
278 $scope.close = function() {
279 $modalInstance.close();