2b3663c057b7cac301df3a7bb9c0f0bf93147883
[portal/sdk.git] /
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);
8             };
9
10             $scope.cancel = function () {
11                 $modalInstance.dismiss('cancel');
12             };
13             
14             $scope.deleteFun = function(data){
15                  $modalInstance.close(data);
16             }
17         };
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',
23                         resolve: {
24                 items: function () {
25                     return '';
26                 }
27                 }
28                 });
29     };
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',
35                         resolve: {
36                 items: function () {
37                     return '';
38                 }
39                 }
40                 });
41     };
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',
47                         resolve: {
48                 items: function () {
49                     return '';
50                 }
51                 }
52                 });
53     };
54         $scope.deleteMenuItem= function(fnMenuItem){
55                   var uuu = "admin_fn_menu/removeMenuItem.htm";
56                   var postData={fnMenuItem: fnMenuItem};
57                   $http({
58                         method :'POST',
59                          url : uuu,
60                          dataType: 'json',
61                          contentType: 'application/json',
62                          data: JSON.stringify(postData)
63                          
64                   }).then(function(data){
65                         $scope.successPopUp();
66                         //      $scope.$apply(function(){$scope.fnMenuItem=data.data.fnMenuItem;}); 
67                                 location.reload();
68                          },function(data){
69                                  $scope.errorPopUp();
70                                 // console.log(data);
71                                 // modalService.showFailure("Fail","Error while deleting: "+ data.responseText);
72                          });
73         }/// examine the LeftMenuService
74 }
75         var fn_menu_popupController =  function ($scope, $modalInstance, message, $http){ /// examine the LeftMenuService
76
77                                 if(message.availableFnMenuItem==null)
78                                         $scope.label='Add New Menu Item'
79                                                 
80                                 else{
81                                         $scope.label='Edit Menu Item'
82                                         //$scope.disableParentId=true;
83                                 }
84                                 
85                                 $scope.getParentData = function(){
86                                         var uuu = "admin_fn_menu/get_parent_list"
87                                                  $http({
88                                                         method : 'GET',
89                                                                  url : uuu,
90                                                                  dataType: 'json',                                                      // data type expected from server
91                                                                  contentType: 'application/json',  
92                                                                  //data: JSON.stringify(postData),                      // data type sent to server     
93                                                                 
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 = [];
100                                                                                 var children = [];
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]) 
104                                                                                                         children.push(
105                                                                                                                         {
106                                                                                                                         menuId: menuItems[j][0],
107                                                                                                                         label:  menuItems[j][1]
108                                                                                                                         }
109                                                                                                         );
110                                                                                         }
111                                                                                         if(children.length!=0){
112                                                                                         heirarchicalMenuItems.push(
113                                                                                                         {
114                                                                                                                 
115                                                                                                                         menuId: menuItems[i][0],
116                                                                                                                         label:  menuItems[i][1],
117                                                                                                                         children: children.sort($scope.sortItems("label"))
118                                                                                                         }
119                                                                                         
120                                                                                         );
121                                                                                         }
122                                                                                         children = [];
123                                                                                         
124                                                                                 }
125                                                                                 heirarchicalMenuItems.sort($scope.sortItems("label"));
126                                                                                 $scope.childListSelectData = heirarchicalMenuItems;
127                                                                                 //console.log(data);
128                                                                         //});  
129                                                                         //$scope.editRoleFunction = null;
130                                                                         ///$modalInstance.close({functionCDselectData:$scope.functionCDselectData});
131                                                                  },function(data){
132                                                                          alert("Parent Data not available !"); 
133                                                                  });
134                                         
135                                 };
136                                 
137                                 $scope.sortItems = function(prop){
138                                         return function(a, b) {  
139                                         if (a[prop] > b[prop]) {  
140                                             return 1;  
141                                         } else if (a[prop] < b[prop]) {  
142                                             return -1;  
143                                         }  
144                                         return 0;  
145                                     }  
146                                                                         
147                                 };
148                                 
149                                 $scope.getParentLabel = function(parentId, parentListSelectData){
150                                         var element;
151                                         element = parentListSelectData[0];
152                                     for (var i=0; i<parentListSelectData.length; i++){
153                                         
154                                         element = parentListSelectData[i];
155                                         if (element[0] == parentId)                    
156                                             return element[1];
157                                         else "---";
158                                     }
159                                 };
160
161
162                                 $scope.getFunctionCDselectData = function(){
163                                         var uuu = "admin_fn_menu/get_function_cd_list"
164                                                   $http({
165                                                         method : 'GET',
166                                                                  url : uuu,
167                                                                  dataType: 'json',                              // data type expected from server
168                                                                  contentType: 'application/json',  
169                                                                  //data: JSON.stringify(postData),   // data type sent to server        
170                                                                 
171                                                           }).then(function(data){
172                                                                         //$scope.$apply(function(){
173                                                                                 //$scope.availableRoleFunctions=[];$scope.$apply();
174                                                                                 $scope.functionCDselectData=data.data;
175                                                                         //});  
176                                                                         //alert("Update Successful.") ;
177                                                                         //$scope.editRoleFunction = null;
178                                                                         ///$modalInstance.close({functionCDselectData:$scope.functionCDselectData});
179                                                                  },function(data){
180                                                                          alert("Function Code Data not available !"); 
181                                                                  });
182                                         
183                                 };
184                                 
185                                 if(message.availableFnMenuItem){
186                                         $scope.addFnMenuItem = message.availableFnMenuItem;
187                                 } else {
188                                         $scope.addFnMenuItem = {};
189                                 }
190                                 $scope.addFnMenuItem.menuSetCode = "APP";
191                                 
192                             $scope.statusOptions = [        
193                                                         {index: 0, value: 'true', title: 'Y'},
194                                                         {index: 1, value: 'false', title: 'N'}
195                                                     ];
196                                 $scope.selectedValue = $scope.statusOptions[0];
197                                 
198                                 $scope.separator = {
199                                                         availableOptions:[
200                                                                                             {value: 'true',  name: 'Y'},
201                                                                                             {value: 'false', name: 'N'}
202                                                                                          ],
203                                                                                          
204                                                                                          selectedOption: {value: 'true', name: 'Y'}
205                                                               
206                                                                         };
207                                         
208                                         
209                             $scope.activeStatusOptions = [        
210                                                         {index: 0, value: 'true', title: 'Y'},
211                                                         {index: 1, value: 'false', title: 'N'}
212                                                     ];
213                             $scope.activeSelectedValue = $scope.activeStatusOptions[0];
214                                     
215                             $scope.separatorStatusOptions = [        
216                                                                                 {index: 0, value: 'true', title: 'Y'},
217                                                                                 {index: 1, value: 'false', title: 'N'}
218                                                                             ];
219                             $scope.separatorSelectedValue = $scope.separatorStatusOptions[1];                               
220                                 
221                                 $scope.active = {
222                                                         availableOptions:[
223                                                                                             {value: 'true',  name: 'Y'},
224                                                                                             {value: 'false', name: 'N'}
225                                                                                          ],
226                                                                                          
227                                                                                          selectedOption: {value: 'true', name: 'Y'}
228                                                               
229                                                                         };
230                                 
231                                 
232                                 $scope.updateFnMenu = function(availableFnMenuItem) { 
233                                                 // form validation
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";
239                                                 
240                                                 validationRule = /^\S{3,}$/;
241                                                 var selectedFunction = document.getElementById("repeatSelect");
242                                                 var selectedFunctionText = selectedFunction.options[selectedFunction.selectedIndex].text;
243                                                 if(
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 == ""
250                                                   )     
251                                                         {
252                                                                 alert("please provide valid entries !");  
253                                                         }
254                                                 
255                                                 else{ 
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);
260
261
262                                                                   var postData={availableFnMenuItem: availableFnMenuItem};
263                                                                   
264                                                                   $http({
265                                                                         method :'POST', 
266                                                                         url : uuu,
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;
273                                                                                 //});
274                                                                                 
275                                                                                 $modalInstance.close({availableFnMenuItems:$scope.availableRoleFunctions}),function(data){
276                                                                                  alert("Error while saving."); 
277                                                                          }
278                                                                          },function(data){
279                                                                                  console.log("Error",data);
280                                                                          });
281                                                 $scope.getLeftMenuItems();                                              // get left menu items again from database
282
283                                         };
284
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 = [];
292                                                                                                                                                         var j = response; 
293                                                                                                                                                 try{
294                                                                                                                                                         if(j && j !== "null" && j!== "undefined"){
295                                                                                                                                                                 leftParentData = JSON.parse(j.data);
296                                                                                                                                                     leftChildData = JSON.parse(j.data2);
297                                                                                                                                                         }else{
298                                                                                                                                                                 throw "Get Left Menu respsone is not an object/is empty"; 
299                                                                                                                                                         }  
300                                                                                                                                                 try{
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++) {
305                                                                                                                                                                 $scope.item = {
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]
311                                                                                                                                                                 }
312                                                                                                                                                                 leftMenuItems.push($scope.item);                                                                                        
313                                                                                                                                                         };
314                                                                                                                                                         
315                                                                                                                                                         $scope.leftMenuItems = leftMenuItems;
316                                                                                 
317                                                                                                                                                         }catch(err){
318                                                                                                                                                                 console.log("error happened while trying to set left menu structure: "+err);                                       
319                                                                                                                                                         }
320                                                                                                                                                 }catch (e) {
321                                                                                                                                                         console.log("error happened while trying to get left menu items: "+e);
322                                                                                                                                                         reloadPageOnce();
323                                                                                                                                                         return;
324                                                                                                                                         }       
325                                                                                                                                                         return response.data;
326                                                                                                                                                 } else {
327                                                                                                                                                         return $q.reject(response.data);
328                                                                                                                                                 }
329                                                                                                                                 }, function(response) {
330                                                                                                                                         // something went wrong
331                                                                                                                                         return $q.reject(response.data);
332                                                                                                                                 });
333                                         };
334
335                                 $scope.close = function() {
336                                         $modalInstance.close();
337                                 };
338 }
339         }