1 var deletefn_menu_popupController = function ($scope,$modal, items,$modalInstance, $http){
2 $scope.fnMenuItem=items;
3 console.log("fnMenuItems",$scope.fnMenuItem);
4 var ModalInstanceCtrl = function ($scope, $modalInstance, items,AdminMenuService,$http,$modal) {
5 $scope.fnMenuItem=items;
6 $scope.save = function (data) {
7 $modalInstance.close(data);
10 $scope.cancel = function () {
11 $modalInstance.dismiss('cancel');
14 $scope.deleteFun = function(data){
15 $modalInstance.close(data);
18 $scope.successPopUp = function () {
19 var modalInstance = $modal.open({
20 templateUrl: 'app/fusion/scripts/DS2-modal/success_modal.html',
21 controller: ModalInstanceCtrl,
22 sizeClass: 'modal-small',
30 $scope.successModelPopUp = function () {
31 var modalInstance = $modal.open({
32 templateUrl: 'app/fusion/scripts/DS2-modal/success_modalpopup.html',
33 controller: ModalInstanceCtrl,
34 //sizeClass: 'modal-small',
42 $scope.errorPopUp = function () {
43 var modalInstance = $modal.open({
44 templateUrl: 'app/fusion/scripts/DS2-modal/error_modal.html',
45 controller: ModalInstanceCtrl,
46 sizeClass: 'modal-small',
54 $scope.deleteMenuItem= function(fnMenuItem){
55 var uuu = "admin_fn_menu/removeMenuItem.htm";
56 var postData={fnMenuItem: fnMenuItem};
61 contentType: 'application/json',
62 data: JSON.stringify(postData)
64 }).then(function(data){
65 $scope.successPopUp();
66 // $scope.$apply(function(){$scope.fnMenuItem=data.data.fnMenuItem;});
71 // modalService.showFailure("Fail","Error while deleting: "+ data.responseText);
73 }/// examine the LeftMenuService
75 var fn_menu_popupController = function ($scope, $modalInstance, message, $http){ /// examine the LeftMenuService
77 if(message.availableFnMenuItem==null)
78 $scope.label='Add New Menu Item'
81 $scope.label='Edit Menu Item'
82 //$scope.disableParentId=true;
85 $scope.getParentData = function(){
86 var uuu = "admin_fn_menu/get_parent_list"
90 dataType: 'json', // data type expected from server
91 contentType: 'application/json',
92 //data: JSON.stringify(postData), // data type sent to server
94 }).then(function(data){
95 //$scope.$apply(function(){
96 //$scope.availableRoleFunctions=[];$scope.$apply();
97 $scope.parentListSelectData=data.data; // data from server
98 menuItems = $scope.parentListSelectData;
99 var heirarchicalMenuItems = [];
101 for ( var i=0; i<menuItems.length; i++){
102 for(var j=0; j<menuItems.length; j++){
103 if(menuItems[j][2]==menuItems[i][0])
106 menuId: menuItems[j][0],
107 label: menuItems[j][1]
111 if(children.length!=0){
112 heirarchicalMenuItems.push(
115 menuId: menuItems[i][0],
116 label: menuItems[i][1],
117 children: children.sort($scope.sortItems("label"))
125 heirarchicalMenuItems.sort($scope.sortItems("label"));
126 $scope.childListSelectData = heirarchicalMenuItems;
129 //$scope.editRoleFunction = null;
130 ///$modalInstance.close({functionCDselectData:$scope.functionCDselectData});
132 alert("Parent Data not available !");
137 $scope.sortItems = function(prop){
138 return function(a, b) {
139 if (a[prop] > b[prop]) {
141 } else if (a[prop] < b[prop]) {
149 $scope.getParentLabel = function(parentId, parentListSelectData){
151 element = parentListSelectData[0];
152 for (var i=0; i<parentListSelectData.length; i++){
154 element = parentListSelectData[i];
155 if (element[0] == parentId)
162 $scope.getFunctionCDselectData = function(){
163 var uuu = "admin_fn_menu/get_function_cd_list"
167 dataType: 'json', // data type expected from server
168 contentType: 'application/json',
169 //data: JSON.stringify(postData), // data type sent to server
171 }).then(function(data){
172 //$scope.$apply(function(){
173 //$scope.availableRoleFunctions=[];$scope.$apply();
174 $scope.functionCDselectData=data.data;
176 //alert("Update Successful.") ;
177 //$scope.editRoleFunction = null;
178 ///$modalInstance.close({functionCDselectData:$scope.functionCDselectData});
180 alert("Function Code Data not available !");
185 if(message.availableFnMenuItem){
186 $scope.addFnMenuItem = message.availableFnMenuItem;
188 $scope.addFnMenuItem = {};
190 $scope.addFnMenuItem.menuSetCode = "APP";
192 $scope.statusOptions = [
193 {index: 0, value: 'true', title: 'Y'},
194 {index: 1, value: 'false', title: 'N'}
196 $scope.selectedValue = $scope.statusOptions[0];
200 {value: 'true', name: 'Y'},
201 {value: 'false', name: 'N'}
204 selectedOption: {value: 'true', name: 'Y'}
209 $scope.activeStatusOptions = [
210 {index: 0, value: 'true', title: 'Y'},
211 {index: 1, value: 'false', title: 'N'}
213 $scope.activeSelectedValue = $scope.activeStatusOptions[0];
215 $scope.separatorStatusOptions = [
216 {index: 0, value: 'true', title: 'Y'},
217 {index: 1, value: 'false', title: 'N'}
219 $scope.separatorSelectedValue = $scope.separatorStatusOptions[1];
223 {value: 'true', name: 'Y'},
224 {value: 'false', name: 'N'}
227 selectedOption: {value: 'true', name: 'Y'}
232 $scope.updateFnMenu = function(availableFnMenuItem) {
234 if( document.getElementById("popupAddMenuItemImageSrc").value == "" ) availableFnMenuItem.imageSrc = "N/A";
235 if( document.getElementById("popupAddMenuItemTarget").value == "" ) availableFnMenuItem.target = "N/A";
236 if( document.getElementById("popupAddMenuItemExternalUrl").value == "" ) availableFnMenuItem.externalUrl = "N/A";
237 if( document.getElementById("popupAddMenuItemQueryString").value == "" ) availableFnMenuItem.queryString = "N/A";
238 if( document.getElementById("popupAddMenuItemServlet").value == "" ) availableFnMenuItem.servlet = "N/A";
240 validationRule = /^\S{3,}$/;
241 var selectedFunction = document.getElementById("repeatSelect");
242 var selectedFunctionText = selectedFunction.options[selectedFunction.selectedIndex].text;
244 (document.getElementById("popupAddMenuItemLabel").value == "" || document.getElementById("popupAddMenuItemLabel").value.replace(" ", "").length == 0 ) ||//!validationRule.test(document.getElementById("popupAddMenuItemLabel").value)) ||
245 $scope.addFnMenuItem.parentIdAsString == "" ||
246 document.getElementById("popupAddMenuItemAction").value == "" ||
247 selectedFunctionText == "" ||
248 document.getElementById("popupAddMenuItemSortOrder").value == "" ||
249 document.getElementById("popupAddMenuItemMenuSetCode").value == ""
252 alert("please provide valid entries !");
256 var uuu = "admin_fn_menu/updateFnMenu.htm";
257 availableFnMenuItem.parentId=parseFloat($scope.addFnMenuItem.parentIdAsString);
258 availableFnMenuItem.active=('true'==$scope.addFnMenuItem.activeAsString);
259 availableFnMenuItem.separator=('true'==$scope.addFnMenuItem.separatorAsString);
262 var postData={availableFnMenuItem: availableFnMenuItem};
267 //dataType: 'json', // data type expected from server
268 contentType: 'application/json',
269 data: JSON.stringify(postData), // data type sent to server
270 }).then(function(data){
271 //$scope.$apply(function(){
272 $scope.availableFnMenuItems=data.availableFnMenuItems;
275 $modalInstance.close({availableFnMenuItems:$scope.availableRoleFunctions}),function(data){
276 alert("Error while saving.");
279 console.log("Error",data);
281 $scope.getLeftMenuItems(); // get left menu items again from database
285 $scope.getLeftMenuItems = function() {
286 return $http.get('get_menu')
287 .then(function(response) {
288 if (typeof response.data === 'object') {
289 var leftChildData=[];
290 var leftParentData=[];
291 var leftMenuItems = [];
294 if(j && j !== "null" && j!== "undefined"){
295 leftParentData = JSON.parse(j.data);
296 leftChildData = JSON.parse(j.data2);
298 throw "Get Left Menu respsone is not an object/is empty";
301 var leftChildItemList = leftChildData;
302 var pageUrl = window.location.href.split('/')[window.location.href.split('/').length-1];
303 var leftParentList = leftParentData;
304 for (var i = 0; i < leftParentList.length; i++) {
306 parentLabel : leftParentList[i].label,
307 parentAction : leftParentList[i].action,
308 parentImageSrc : leftParentList[i].imageSrc,
309 open:pageUrl==leftParentList[i].action?true:false,
310 childItemList : leftChildItemList[i]==null?'x':leftChildItemList[i]
312 leftMenuItems.push($scope.item);
315 $scope.leftMenuItems = leftMenuItems;
318 console.log("error happened while trying to set left menu structure: "+err);
321 console.log("error happened while trying to get left menu items: "+e);
325 return response.data;
327 return $q.reject(response.data);
329 }, function(response) {
330 // something went wrong
331 return $q.reject(response.data);
335 $scope.close = function() {
336 $modalInstance.close();