Initial OpenECOMP policy/engine commit
[policy/engine.git] / ecomp-sdk-app / src / main / webapp / app / fusion / scripts / controllers / admin_menu_edit.js
1 /*-
2  * ================================================================================
3  * eCOMP Portal SDK
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
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
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  * ================================================================================
19  */
20 app.controller('AdminMenuEditController', function ($scope, AdminService, modalService, $modal, $route){
21         $( "#dialog" ).hide();
22         
23 /*    AdminService.getRoleFunctionList().then(function(data){
24                 
25                 var j = data;
26                 $scope.data = JSON.parse(j.data);
27                 $scope.availableRoleFunctions =JSON.parse($scope.data.availableRoleFunctions);
28                 
29                 //$scope.resetMenu();
30         
31         },function(error){
32                 console.log("failed");
33                 reloadPageOnce();
34         });*/
35         $scope.init = function () {
36                 $scope.numberOfRecordstoShow=20;
37                  AdminService.getFnMenuItems().then(function(data){ 
38                                 var j = data;
39                                 $scope.data =JSON.parse(j.data);
40                                 $scope.fnMenuItems =($scope.data.fnMenuItems);          
41                         
42                         },function(error){
43                                 console.log("failed");
44                                 //reloadPageOnce();
45                         }); 
46         }
47         $scope.init();
48     $scope.mapActiveStatus = function(status){
49         if(status)
50                 status = "Y";
51                 else
52                         status = "N";
53         return status;
54         
55     };
56     
57
58     $scope.addNewFnMenuItemModalPopup = function(availableFnMenuItem) {
59                 $scope.editFnMenuItem = null;
60                 var modalInstance = $modal.open({
61                     templateUrl: 'fn_menu_add_popup.html',
62                     controller: 'fn_menu_popupController',
63                     resolve: {
64                         message: function () {
65                                 var message = {
66                                                 availableFnMenuItem: $scope.editFnMenuItem
67                                 };
68                           return message;
69                         }                                       
70                       }
71                   }); 
72                 modalInstance.result.then(function(response){
73             console.log('response', response);
74             $scope.availableFnMenuItems=response.availableFnMenuItems; 
75             $route.reload();
76         });
77         };
78         
79         $scope.removeMenuItem = function(fnMenuItem) { 
80                 modalService.popupConfirmWin("Confirm","You are about to delete the menu item "+fnMenuItem.label+". Do you want to continue?",
81                         function(){
82                                           var uuu = "admin_fn_menu/removeMenuItem.htm";
83                                           var postData={fnMenuItem: fnMenuItem};
84                                           $.ajax({
85                                                  type : 'POST',
86                                                  url : uuu,
87                                                  dataType: 'json',
88                                                  contentType: 'application/json',
89                                                  data: JSON.stringify(postData),
90                                                  success : function(data){
91                                                         $scope.$apply(function(){$scope.fnMenuItem=data.fnMenuItem;}); 
92                                                         $route.reload();
93                                                  },
94                                                  error : function(data){
95                                                          console.log(data);
96                                                          modalService.showFailure("Fail","Error while deleting: "+ data.responseText);
97                                                  }
98                                           });
99                                         
100         })
101                 
102         };      
103         
104         $scope.editRoleFunction = null;
105         var dialog = null;
106         $scope.editRoleFunctionPopup = function(availableRoleFunction) {
107                 $scope.editRoleFunction = availableRoleFunction;
108                 $( "#dialog" ).dialog({
109                       modal: true
110             });
111         };
112         
113     $scope.editMenuItemModalPopup = function(availableFnMenuItem) {
114                 $scope.editFnMenuItem = availableFnMenuItem;
115                 var modalInstance = $modal.open({
116                     templateUrl: 'fn_menu_add_popup.html',
117                     controller: 'fn_menu_popupController',
118                     resolve: {
119                         message: function () {
120                                 var message = {
121                                                 availableFnMenuItem: $scope.editFnMenuItem
122                                 };
123                           return message;
124                         }                                       
125                       }
126                   }); 
127                 modalInstance.result.then(function(response){
128             $scope.availableFnMenuItems=response.availableFnMenuItems;
129             $route.reload();
130         });
131         };      
132         
133         $scope.editRoleFunctionModalPopup = function(availableRoleFunction) {
134                 $scope.editRoleFunction = availableRoleFunction;
135                 var modalInstance = $modal.open({
136                     templateUrl: 'edit_role_function_popup.html',
137                     controller: 'rolefunctionpopupController',
138                     resolve: {
139                         message: function () {
140                                 var message = {
141                                                 availableRoleFunction: $scope.editRoleFunction
142                                 };
143                           return message;
144                         }                                       
145                       }
146                   }); 
147                 modalInstance.result.then(function(response){
148             console.log('response', response);
149             $scope.availableRoleFunctions=response.availableRoleFunctions;
150         });
151         };
152         
153         $scope.addNewRoleFunctionModalPopup = function(availableRoleFunction) {
154                 $scope.editRoleFunction = null;
155                 var modalInstance = $modal.open({
156                     templateUrl: 'edit_role_function_popup.html',
157                     controller: 'rolefunctionpopupController',
158                     resolve: {
159                         message: function () {
160                                 var message = {
161                                                 availableRoleFunction: $scope.editRoleFunction
162                                 };
163                           return message;
164                         }                                       
165                       }
166                   }); 
167                 modalInstance.result.then(function(response){
168             console.log('response', response);
169             $scope.availableRoleFunctions=response.availableRoleFunctions;
170         });
171         };
172         
173         $scope.addNewRoleFunctionPopup = function() {
174                 $scope.editRoleFunction = null;
175                 $( "#dialog" ).dialog({
176                       modal: true
177             });
178         };
179         
180         $scope.saveRoleFunction = function(availableRoleFunction) {
181                   var uuu = "role_function_list/saveRoleFunction.htm";
182                   var postData={availableRoleFunction: availableRoleFunction};
183                   $.ajax({
184                          type : 'POST',
185                          url : uuu,
186                          dataType: 'json',
187                          contentType: 'application/json',
188                          data: JSON.stringify(postData),
189                          success : function(data){
190                                 $scope.$apply(function(){
191                                         $scope.availableRoleFunctions=[];$scope.$apply();
192                                         $scope.availableRoleFunctions=data.availableRoleFunctions;});  
193                                 //alert("Update Successful.") ;
194                                 console.log($scope.availableRoleFunctions);
195                                 
196                                 $scope.editRoleFunction = null;
197                                 $( "#dialog" ).dialog("close");
198                          },
199                          error : function(data){
200                                  modalService.showFailure("Fail","Error while saving.");
201                          }
202                   });
203                 };
204         
205                 
206                 $scope.removeRole = function(availableRoleFunction) {
207                         modalService.popupConfirmWin("Confirm","You are about to delete the role function "+availableRoleFunction.name+". Do you want to continue?",
208                                 function(){
209                                                   var uuu = "role_function_list/removeRoleFunction.htm";
210                                                   var postData={availableRoleFunction: availableRoleFunction};
211                                                   $.ajax({
212                                                          type : 'POST',
213                                                          url : uuu,
214                                                          dataType: 'json',
215                                                          contentType: 'application/json',
216                                                          data: JSON.stringify(postData),
217                                                          success : function(data){
218                                                                 $scope.$apply(function(){$scope.availableRoleFunctions=data.availableRoleFunctions;});  
219                                                          },
220                                                          error : function(data){
221                                                                  console.log(data);
222                                                                  modalService.showFailure("Fail","Error while deleting: "+ data.responseText);
223                                                          }
224                                                   });
225                                                 
226                 })
227                         
228                 };
229
230 });