Changed trials-in-common page to use a single database query to get analyses. Changed...
[sgn.git] / mason / breeders_toolbox / manage_roles.mas
blobb5ba1b1e850376d9bbab665cc24e126cc826db64
2 <%args>
3 $roles => undef
4 $is_curator => undef
5 </%args>
7 <& /util/import_javascript.mas, entries => [ "manage_user_roles" ] &>
9 <& /page/page_title.mas, title=>"Manage User Roles" &>
11 <table id="manage_user_roles_table" class="table table-bordered">
12 <thead>
13 % if ($is_curator){
14 <tr><th>User</th><th>Roles</th></tr>
15 % } else {
16 <tr><th>User</th><th>Breeding Programs</th></tr>
17 % }
18 </thead>
19 <tbody>
20 </tbody>
21 </table>
23 <div id="manage_user_roles" >
25 <div class="modal fade" id="add_person_role_dialog" name="add_person_role_dialog" tabindex="-1" role="dialog" aria-labelledby="addPersonRoleDialog">
26   <div class="modal-dialog" role="document">
27     <div class="modal-content">
28       <div class="modal-header">
29         <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
30         <h4 class="modal-title" id="addPersonRoleDialog">Add Role for <span id="person_name_for_role"></span></h4>
31       </div>
32       <div class="modal-body">
33         <div class="container-fluid">
35                <!-- form class="form-horizontal" >
36                 <div class="form-group">
37                 <label class="col-sm-3 control-label">Username: </label>
38                 <div class="col-sm-9" >
39                     <div id="add_person_role_person_select_div">
40                     [LOADING...]
41                     </div>
42                 </div>
43                 </div -->
44             <input type="hidden" id="sp_person_id" name="sp_person_id" value="" />
45             <div class="form-group">
46                 <label class="col-sm-3 control-label">Role: </label>
47                 <div class="col-sm-9" >
48                     <div id="add_person_role_role_select_div">
49                     [LOADING...]
50                     </div>
51                 </div>
52                 </div>
53                </form><br/>
54          
55         </div>
56       </div>
57       <div class="modal-footer">
58         <button type="button" class="btn btn-default" name="add_person_role_cancel_button" id="add_person_role_cancel_button" data-dismiss="modal">Close</button>
59         <button type="button" class="btn btn-primary" name="add_person_role_submit_button" id="add_person_role_submit_button" title="Submit">Submit</button>
60       </div>
61     </div>
62   </div>
63 </div>
64 </div>  <!-- manage_user_roles -->
66 % if (! $is_curator) {
67 Note: Only curators can change user role assignments.
68 % }
70 <script>
72 jQuery(document).ready(function() {
74    jQuery('#manage_user_roles_table').DataTable( {
75        ajax : '/ajax/roles/list'
76    });
79 });
82 function delete_user_role(sp_person_role_id) {
83     
84     var yes = confirm("Really delete this role association?");
85     if (yes) { 
86       $.ajax( {
87         url: '/ajax/roles/delete/association/'+sp_person_role_id
88       });
89       jQuery('#manage_user_roles_table').DataTable().ajax.reload();                                       
90       alert('Association deleted.');
91     }
92   }
94 function add_user_role(sp_person_id, person_name) {
95         $('#add_person_role_dialog').modal("show");
96         $('#sp_person_id').val(sp_person_id);
97         $('#person_name_for_role').html(person_name);
99         jQuery.ajax ( {
100             url : '/ajax/people/people_and_roles',
101             beforeSend: function() {
102                 jQuery("#working_modal").modal("show");
103             },
104             success: function(response){
105                 jQuery("#working_modal").modal("hide");
107                 var sp_role_html = '<select class="form-control" id="add_person_role_role_select">';
108                 for (var i=0; i<response.sp_roles.length; i++) {
109                     sp_role_html = sp_role_html + '<option value="'+response.sp_roles[i][1]+'">'+response.sp_roles[i][0]+'</option>';
110                 }
111                 jQuery('#add_person_role_role_select_div').empty().html(sp_role_html);
112             },
113             error: function(response) {
114                 jQuery("#working_modal").modal("hide");
115                 alert('An error occured: '+response);
116             }
117         });
122     jQuery('#add_person_role_submit_button').click( function(e) {
124                                                           
125     jQuery.ajax ( {
126         url : '/ajax/people/add_person_role?sp_person_id='+jQuery("#sp_person_id").val()+'&sp_role_id='+jQuery("#add_person_role_role_select").val(),
127         beforeSend: function() {
128             jQuery("#working_modal").modal("show");
129         },
130         success: function(response){
131             //console.log(response);
132             jQuery("#working_modal").modal("hide");
133             if (response.error) {
134                 alert('Error: '+response.error);
135             } else {
136             jQuery('#manage_user_roles_table').DataTable().ajax.reload();
137                 alert('Role Added for User!');
138             }
139         },
140         error: function(response) {
141             jQuery("#working_modal").modal("hide");
142             alert('An error occured: '+response);
143         }
144     });
146         
148 </script>