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">
14 <tr><th>User</th><th>Roles</th></tr>
16 <tr><th>User</th><th>Breeding Programs</th></tr>
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">×</span></button>
30 <h4 class="modal-title" id="addPersonRoleDialog">Add Role for <span id="person_name_for_role"></span></h4>
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">
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">
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>
64 </div> <!-- manage_user_roles -->
66 % if (! $is_curator) {
67 Note: Only curators can change user role assignments.
72 jQuery(document).ready(function() {
74 jQuery('#manage_user_roles_table').DataTable( {
75 ajax : '/ajax/roles/list'
82 function delete_user_role(sp_person_role_id) {
84 var yes = confirm("Really delete this role association?");
87 url: '/ajax/roles/delete/association/'+sp_person_role_id
89 jQuery('#manage_user_roles_table').DataTable().ajax.reload();
90 alert('Association deleted.');
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);
100 url : '/ajax/people/people_and_roles',
101 beforeSend: function() {
102 jQuery("#working_modal").modal("show");
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>';
111 jQuery('#add_person_role_role_select_div').empty().html(sp_role_html);
113 error: function(response) {
114 jQuery("#working_modal").modal("hide");
115 alert('An error occured: '+response);
122 jQuery('#add_person_role_submit_button').click( function(e) {
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");
130 success: function(response){
131 //console.log(response);
132 jQuery("#working_modal").modal("hide");
133 if (response.error) {
134 alert('Error: '+response.error);
136 jQuery('#manage_user_roles_table').DataTable().ajax.reload();
137 alert('Role Added for User!');
140 error: function(response) {
141 jQuery("#working_modal").modal("hide");
142 alert('An error occured: '+response);