graphical filtering of accession search
[sgn.git] / mason / people / add_person_role.mas
blob748a9e33d48d858dd9a9748e7723eade63779d3a
2 <%args>
3 </%args>
6 <div class="modal fade" id="add_person_role_dialog" name="add_person_role_dialog" tabindex="-1" role="dialog" aria-labelledby="addPersonRoleDialog">
7   <div class="modal-dialog" role="document">
8     <div class="modal-content">
9       <div class="modal-header">
10         <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
11         <h4 class="modal-title" id="addPersonRoleDialog">Give Role to User</h4>
12       </div>
13       <div class="modal-body">
14         <div class="container-fluid">
16                <form class="form-horizontal" >
17                 <div class="form-group">
18                 <label class="col-sm-3 control-label">Username: </label>
19                 <div class="col-sm-9" >
20                     <div id="add_person_role_person_select_div">
21                     [LOADING...]
22                     </div>
23                 </div>
24                 </div>
25             <div class="form-group">
26                 <label class="col-sm-3 control-label">Role: </label>
27                 <div class="col-sm-9" >
28                     <div id="add_person_role_role_select_div">
29                     [LOADING...]
30                     </div>
31                 </div>
32                 </div>
33                </form><br/>
34          
35         </div>
36       </div>
37       <div class="modal-footer">
38         <button type="button" class="btn btn-default" name="add_person_role_cancel_button" id="add_person_role_cancel_button" data-dismiss="modal">Close</button>
39         <button type="button" class="btn btn-primary" name="add_person_role_submit_button" id="add_person_role_submit_button" title="Submit">Submit</button>
40       </div>
41     </div>
42   </div>
43 </div>
45 <script>
47 jQuery(document).ready(function() {
49     jQuery('#add_person_role_button').click( function () {
51         jQuery.ajax ( {
52             url : '/ajax/people/people_and_roles',
53             beforeSend: function() {
54                 jQuery("#working_modal").modal("show");
55             },
56             success: function(response){
57                 //console.log(response);
58                 jQuery("#working_modal").modal("hide");
60                 var sp_person_html = '<select class="form-control" id="add_person_role_person_select">';
61                 for (var i=0; i<response.sp_persons.length; i++) {
62                     sp_person_html = sp_person_html + '<option value="'+response.sp_persons[i][1]+'">'+response.sp_persons[i][0]+'</option>';
63                 }
64                 jQuery('#add_person_role_person_select_div').empty().html(sp_person_html);
66                 var sp_role_html = '<select class="form-control" id="add_person_role_role_select">';
67                 for (var i=0; i<response.sp_roles.length; i++) {
68                     sp_role_html = sp_role_html + '<option value="'+response.sp_roles[i][1]+'">'+response.sp_roles[i][0]+'</option>';
69                 }
70                 jQuery('#add_person_role_role_select_div').empty().html(sp_role_html);
71             },
72             error: function(response) {
73                 jQuery("#working_modal").modal("hide");
74                 alert('An error occured: '+response);
75             }
76         });
78         jQuery('#add_person_role_dialog').modal("show");
80     });
81   
82     jQuery('#add_person_role_submit_button').click( function () {
83         jQuery.ajax ( {
84             url : '/ajax/people/add_person_role?sp_person_id='+jQuery("#add_person_role_person_select").val()+'&sp_role_id='+jQuery("#add_person_role_role_select").val(),
85             beforeSend: function() {
86                 jQuery("#working_modal").modal("show");
87             },
88             success: function(response){
89                 //console.log(response);
90                 jQuery("#working_modal").modal("hide");
91                 if (response.error) {
92                     alert('Error: '+response.error);
93                 } else {
94                     alert('Role Added for User!');
95                 }
96             },
97             error: function(response) {
98                 jQuery("#working_modal").modal("hide");
99                 alert('An error occured: '+response);
100             }
101         });
102     });
106 </script>