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