Initial OpenECOMP policy/engine commit
[policy/engine.git] / ecomp-sdk-app / src / main / webapp / WEB-INF / fusion / jsp / popup_modal_role.html
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
21 <script type="text/ng-template" id="role_functions_popup.html">
22           <div class="modal__informative font-showcase" style="width:700px;height:500px;overflow:scroll">
23             <div class="modal__header">
24                 <h2 class="font-showcase-font-name" style="width: 500px;">Select Role Functions</h2>
25             </div>
26             <button align="right" class="button button--primary button--small" herf="javascript:void(0)" ng-click="close()">Close</button>
27             <div class="divider-container"><hr> </div>      
28             <div class="modal__content">                        
29                                 <table table-data="availableRoleFunctions" att-table>
30                                         <thead att-table-row type="header">
31                                                 <tr>
32                                                         <th att-table-header sortable="false" width="10%"> </th>
33                                                         <th att-table-header sortable="false" width="90%">Role Function</th>
34                                                 </tr>
35                                         </thead>
36                                         <tbody att-table-row type="body" row-repeat="availableRoleFunction in availableRoleFunctions" style="max-height: 980px;" >
37                                           <tr>
38                                           
39                                                 <td width="10%">
40                                                         <div ng-click="toggleRoleFunction(availableRoleFunction.selected,availableRoleFunction);">
41                                                         <input type="checkbox" ng-model="availableRoleFunction.selected" att-toggle-main>
42                                                         </div>
43                                                 </td>
44                                                 <td width="90%">{{ availableRoleFunction.name }}</td>
45                                                 
46                                           </tr>
47                                         </tbody>
48                                 </table>        
49             </div>
50         </div>
51 </script>
52
53
54 <script type="text/ng-template" id="child_roles_popup.html">
55           <div class="modal__informative font-showcase" style="width:700px;height:500px;overflow:scroll">
56             <div class="modal__header">
57                 <h2 class="font-showcase-font-name" style="width: 500px;">Select Child Roles</h2>
58             </div>
59             <button align="right" class="button button--primary button--small" herf="javascript:void(0)" ng-click="close()">Close</button>
60             <div class="divider-container"><hr> </div>      
61             <div class="modal__content">                        
62                                         <table table-data="availableRoles" att-table>
63                                                 <thead att-table-row type="header">
64                                                         <tr>
65                                                                 <th att-table-header sortable="false" width="10%"> </th>
66                                                                 <th att-table-header sortable="false" width="90%">Role</th>
67                                                         </tr>
68                                                 </thead>
69                                                 <tbody att-table-row type="body" row-repeat="availableRole in availableRoles" style="max-height: 980px;" >
70                                                         <tr>
71                                                         <td att-table-body width="10%">
72                                                                 <div ng-click="toggleChildRole(availableRole.selected,availableRole);">
73                                                                 <input type="checkbox" ng-model="availableRole.selected" att-toggle-main>
74                                                                 </div>
75                                                         </td>
76                                                         <td att-table-body width="90%">{{ availableRole.name }}</td>
77                                                         </tr>
78                                                 </tbody>
79                                         </table>        
80             </div>
81         </div>
82 </script>
83
84 <script>
85
86 var rolepopupController =  function ($scope, $modalInstance, role,modalService){
87         $scope.role = role;
88         
89         if($scope.role.childRoles==null){
90                 $scope.role.childRoles=[];
91         }
92         
93         $scope.ociavailableRoles=${availableRoles};
94         console.log($scope.ociavailableRoles);
95         $scope.availableRoles=[];
96         if($scope.ociavailableRoles)
97                 $.each($scope.ociavailableRoles, function(i, a){ 
98                         var availableRole = a;
99                         availableRole.selected = false;
100                         if($scope.role.childRoles){
101                     $.each($scope.role.childRoles, function(j, b){ 
102                         if(a.id === b.id) {
103                                 availableRole.selected = true;
104                         }
105                     });
106                         };
107                     $scope.availableRoles.push(availableRole);      
108                 });     
109                 ;
110         
111         $scope.ociavailableRoleFunctions=${availableRoleFunctions};
112         
113         $scope.availableRoleFunctions = []; 
114         if($scope.ociavailableRoleFunctions)
115                 $.each($scope.ociavailableRoleFunctions, function(i, a){ 
116                         var availableRoleFunction = a;
117                         availableRoleFunction.selected = false;
118                     $.each($scope.role.roleFunctions, function(j, b){ 
119                         if(a.code === b.code) {
120                                 availableRoleFunction.selected = true;
121                         }
122                     });
123                     $scope.availableRoleFunctions.push(availableRoleFunction);      
124                 });     
125                 ;
126         
127                 $scope.toggleRoleFunction = function(selected,availableRoleFunction) {
128                         //alert('toggleRole: '+selected);
129                          
130                         if(!selected) {
131                                 //remove role function
132                                 if(role.id==null){
133                                         var index = $scope.role.roleFunctions.indexOf(availableRoleFunction);
134                                         if(index>=0)
135                                                 $scope.role.roleFunctions.splice(index, 1);
136                                         return;
137                                 }
138                                 var uuu = "role/removeRoleFunction.htm?role_id=${param.role_id}";
139                                 modalService.popupConfirmWinWithCancel("Confirm","You are about to remove the role function "+availableRoleFunction.name+" from the role for "+$scope.role.name+". Do you want to continue?",
140                                         function(){
141                                                                 var postData={roleFunction:availableRoleFunction};
142                                                                   $.ajax({
143                                                                          type : 'POST',
144                                                                          url : uuu,
145                                                                          dataType: 'json',
146                                                                          contentType: 'application/json',
147                                                                          data: JSON.stringify(postData),
148                                                                          success : function(data){
149                                                                                 $scope.$apply(function(){$scope.role=data.role;}); 
150                                                                          },
151                                                                          error : function(data){
152                                                                                  modalService.showFailure("Fail","Error while saving.");
153                                                                          }
154                                                                   });
155                                         
156                         },
157                         function(){
158                                 availableRoleFunction.selected=!availableRoleFunction.selected;
159                         })
160                                 
161                         } else {
162                                 //add role function
163                                 if(role.id==null){
164                                         $scope.role.roleFunctions.push(availableRoleFunction);
165                                         return;
166                                 }
167                                 var uuu = "role/addRoleFunction.htm?role_id=${param.role_id}";
168                                 modalService.popupConfirmWinWithCancel("Confirm","You are about to add the role function "+availableRoleFunction.name+" to the role for "+$scope.role.name+". Do you want to continue?",
169                                         function(){
170                                           var postData={roleFunction:availableRoleFunction};
171                                           $.ajax({
172                                                  type : 'POST',
173                                                  url : uuu,
174                                                  dataType: 'json',
175                                                  contentType: 'application/json',
176                                                  data: JSON.stringify(postData),
177                                                  success : function(data){
178                                                         $scope.$apply(function(){$scope.role=data.role;}); 
179                                                  },
180                                                  error : function(data){
181                                                          modalService.showFailure("Fail","Error while saving.");
182                                                  }
183                                           });
184                                         
185                         },
186                         function(){
187                                 availableRoleFunction.selected=!availableRoleFunction.selected;
188                         })
189                                 
190                         }
191                         
192                           
193         };
194         
195         $scope.toggleChildRole = function(selected,availableRole) {
196                 //alert('toggleRole: '+selected);
197
198                 if(!selected) {
199                         //remove role
200                         if(role.id==null){
201                                 var index = $scope.role.childRoles.indexOf(availableRole);
202                                 if(index>=0)
203                                         $scope.role.childRoles.splice(index, 1);
204                                 return;
205                         }
206                         var uuu = "role/removeChildRole.htm?role_id=${param.role_id}";
207                         modalService.popupConfirmWinWithCancel("Confirm","You are about to remove the child role "+availableRole.name+" from the role for "+$scope.role.name+". Do you want to continue?",
208                                 function(){
209                                                 var postData={childRole:availableRole};
210                                                   $.ajax({
211                                                          type : 'POST',
212                                                          url : uuu,
213                                                          dataType: 'json',
214                                                          contentType: 'application/json',
215                                                          data: JSON.stringify(postData),
216                                                          success : function(data){
217                                                                  console.log('role',data.role);
218                                                                  $scope.$apply(function(){$scope.role=data.role;}); 
219                                                          },
220                                                          error : function(data){
221                                                                  modalService.showFailure("Fail","Error while saving.");
222                                                          }
223                                                   });
224                                 
225                 },
226                 function(){
227                          availableRole.selected=true;                   
228                 })
229                         
230                 } else {
231                         //add role
232                         if(role.id==null){
233                                 $scope.role.childRoles.push(availableRole);
234                                 return;
235                         }
236                         var uuu = "role/addChildRole.htm?role_id=${param.role_id}";
237                         modalService.popupConfirmWinWithCancel("Confirm","You are about to add the child role "+availableRole.name+" to the role for "+$scope.role.name+". Do you want to continue?",
238                                 function(){
239                                   var postData={childRole:availableRole};
240                                   $.ajax({
241                                          type : 'POST',
242                                          url : uuu,
243                                          dataType: 'json',
244                                          contentType: 'application/json',
245                                          data: JSON.stringify(postData),
246                                          success : function(data){
247                                                 $scope.$apply(function(){$scope.role=data.role;}); 
248                                          },
249                                          error : function(data){
250                                                  modalService.showFailure("Fail","Error while saving.");
251                                          }
252                                 });
253                                 
254                 },
255                 function(){
256                         availableRole.selected=false;
257                 })
258                         
259                         
260                 }
261                 
262                   
263         };
264
265         
266         $scope.close = function() {
267                 console.log('role', $scope.role);
268                 $modalInstance.close({role:$scope.role});
269         };
270         
271 }
272
273
274 </script>