Initial OpenECOMP policy/engine commit
[policy/engine.git] / ecomp-sdk-app / src / main / webapp / WEB-INF / fusion / jsp / role_list.jsp
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 <%-- <%@ include file="/WEB-INF/fusion/jsp/include.jsp" %> --%>
22
23 <%@ taglib prefix="c"      uri="http://java.sun.com/jsp/jstl/core" %>
24 <%@ taglib prefix="fmt"    uri="http://java.sun.com/jsp/jstl/fmt" %>
25 <%@ taglib prefix="fn"     uri="http://java.sun.com/jsp/jstl/functions" %>
26 <%@ include file="/WEB-INF/fusion/jsp/popup_modal.html" %>
27
28 <div class="pageTitle">
29         <h1 class="heading1" style="margin-top:20px;">Roles</h1>
30 </div>
31 <br>
32 Click on a Role to view its details.
33      
34 <div ng-controller="roleListController" >       
35         <div id="dialog" title="Roles">
36           <table att-table table-data="availableRoles" current-page="1">
37                 <thead att-table-row type="header">
38                         <tr>
39                                 <th att-table-header width="70%">Name</th>
40                                 <th att-table-header width="10%">Priority</th>
41                                 <th att-table-header width="10%">Active?</th>
42                                 <th att-table-header width="10%">Delete?</th>
43                         </tr>
44                 </thead>
45                 <tbody att-table-row type="body" row-repeat="availableRole in availableRoles" style="max-height: 980px;" ><!-- background colors will alternate not properly with multiple tbody-->
46 <!--              <tr ng-repeat="availableRole in availableRoles track by availableRole.id">                     -->
47                   <tr>
48                     <td width="70%"><a href="role.htm?role_id={{availableRole.id}}">{{ availableRole.name }}</a></td>
49                     <td width="10%">{{ availableRole.priority }}</td>
50                     <td width="10%">
51                         <div ng-click="toggleRole(availableRole.active,availableRole);">
52                         <input type="checkbox" ng-model="availableRole.active" att-toggle-main>
53                         </div>
54                     </td>
55                      <td att-table-body width="10%">
56                         <div ng-click="removeRole(availableRole);" style="font-size:20px;"><a href="javascript:void(0)" class="ion-trash-b"></a></div>
57                      </td>
58                   </tr>
59                 </tbody>
60                 </table>
61         </div>
62         
63         <div align="left" style="marin-bottom: 50px;">
64                 <button type="submit" onClick="window.location='role.htm';" att-button
65                         btn-type="primary" size="small">Create</button>
66         </div>
67         
68 </div>
69
70
71
72
73 <script>
74 app.controller('roleListController', function ($scope,modalService){
75         
76         $scope.availableRoles=${availableRoles};
77         //console.log($scope.availableRoles);
78                 $scope.toggleRole = function(selected,availableRole) {
79                                 //alert('toggleRole: '+selected);
80                                 var toggleType = null;
81                                 if(selected) {
82                                         toggleType = "activate";
83                                 } else {
84                                         toggleType = "inactivate";
85                                 }
86                                 
87                                 modalService.popupConfirmWinWithCancel("Confirm","You are about to "+toggleType+" the test role "+availableRole.name+". Do you want to continue?",
88                                         function(){
89                                             var uuu = "role_list/toggleRole";
90                                                                 
91                                                                 var postData={role:availableRole};
92                                                                   $.ajax({
93                                                                          type : 'POST',
94                                                                          url : uuu,
95                                                                          dataType: 'json',
96                                                                          contentType: 'application/json',
97                                                                          data: JSON.stringify(postData),
98                                                                          success : function(data){
99                                                                                 console.log(data);
100                                                                                 $scope.$apply(function(){$scope.availableRoles=data.availableRoles;}); 
101                                                                                 console.log($scope.availableRoles);
102                                                                          },
103                                                                          error : function(data){
104                                                                                  console.log(data);
105                                                                                  modalService.showFailure("Fail","Error while saving.");
106                                                                          }
107                                                                   });
108                                         
109                         },
110                         function(){
111                                 availableRole.active=!availableRole.active;
112                         })
113                                   
114                 };
115
116                 $scope.removeRole = function(role) {
117                         modalService.popupConfirmWin("Confirm","You are about to delete the role "+role.name+". Do you want to continue?",
118                                 function(){
119                                                         var uuu = "role_list/removeRole";
120                                                           var postData={role:role};
121                                                           $.ajax({
122                                                                  type : 'POST',
123                                                                  url : uuu,
124                                                                  dataType: 'json',
125                                                                  contentType: 'application/json',
126                                                                  data: JSON.stringify(postData),
127                                                                  success : function(data){
128                                                                         $scope.$apply(function(){$scope.availableRoles=data.availableRoles;});  
129                                                                  },
130                                                                  error : function(data){
131                                                                          console.log(data);
132                                                                          modalService.showFailure("Fail","Error while deleting: "+ data.responseText);
133                                                                  }
134                                                           });
135                                 
136                 })
137                 };
138 });
139 </script>