add addiitional refresh option for all views except genoview
[sgn.git] / mason / breeders_toolbox / delete_seedlots.mas
blob8953193ffa7225be08fedf1aad7548edb6e2aee3
2 <%args>
3 $user_role => undef
4 </%args>
6 <& /util/import_javascript.mas, classes => [ 'jquery', 'jqueryui', 'CXGN.BreedersToolbox.HTMLSelect', 'CXGN.List' ] &>
7   
9   <&| /page/info_section.mas, title=>"Delete seedlots using a list",  collapsible => 1, collapsed=>1 &>
10     
12 % if ($user_role eq "curator" ) { 
13     <div style="margin-left:20px">
14       
15       
16       <p><strong>Select a list of type "seedlot" to delete from the database</strong></p>
17       Note:
18       <ul><li>Only seedlots that are not associated with crosses or trials can be deleted.</li>
19         <li>Deleting seedlots cannot be undone.</li>
20       </ul>
21       <form class="form-horizontal" role="form" method="post" id="delete_seedlots_form" name="delete_seedlots_form">
22         <div class="form-group">
23           <div style="width:300px;margin-left:40px;margin-top:30px;" id="seedlots_to_delete_html">
24           </div>
25         </div>
26       </form>
27       <br /><br />
28       <button type="button" class="btn btn-primary" name="delete_seedlots_submit" id="delete_seedlots_submit">Delete Seedlots</button>
29     </div>
30 </div>
33 % else {
35 You need to be logged in or you do not have sufficient privileges to delete seedlots using lists.
38 </&>
40 <div class="modal fade" id="delete_seedlots_modal" name="delete_seedlots_modal" tabindex="-1" role="dialog">
41     <div class="modal-dialog modal-lg" role="document">
42         <div class="modal-content">
43             <div class="modal-header">
44                 <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
45                 <h4 class="modal-title">Seedlot Deletion Verify</h4>
46             </div>
47             <div class="modal-body">
48               <div class="container-fluid">
49                 <div id="seedlot_deletion_verify">
50                 </div>
51               </div>
52             </div>
53             <div class="modal-footer">
54                 <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
55                 <button type="button" class="btn btn-primary" name="delete_seedlots_confirm" id="delete_seedlots_confirm">Delete green elements</button>
56             </div>
57         </div>
58     </div>
59 </div>
62 <script>
64 jQuery(window).ready( function() { 
65     jQuery("#seedlots_to_delete_html").append(list.listSelect("seedlots_to_delete_html_select", [ 'seedlots' ], 'None', undefined, undefined));
66 });
68 jQuery('#delete_seedlots_submit').click( function() {
69    var list_id = jQuery('#seedlots_to_delete_html_select_list_select').val();
70    if (list_id === "") { alert("Please select a list "+list_id); return; }
71    verify_seedlot_deletion(list_id).then(function(r) { display_seedlot_deletion_info(r) }, function(r) { alert("ERROR!")});
72 });
74 jQuery('#delete_seedlots_confirm').click( function() {
75     var list_id = jQuery('#seedlots_to_delete_html_select_list_select').val();
76     if (list_id) {
77         delete_seedlots(list_id).then( function(r) { alert(r.delete_count+" elements have been deleted"); }, function(r) { alert('An error occurred'); });
78     }
79 });
81 function verify_seedlot_deletion(list_id) {
83    return jQuery.ajax( {
84         url: '/ajax/seedlots/verify_delete_by_list?list_id='+list_id,
85     });
88 function delete_seedlots(list_id) {
89    return jQuery.ajax( {
90        url: '/ajax/seedlots/confirm_delete_by_list?list_id='+list_id,
91    });
94 function display_seedlot_deletion_info(r) {
95     jQuery('#delete_seedlots_modal').modal('show');
97     var ok = r.ok;
98     var errors = r.errors;
100     var html = "";
102     for (const n of ok) {
103         html += "<li class='list-group-item list-group-item-success'>"+n+"</li>";
104     }
106     for (const n of errors) {
107        html += "<li class='list-group-item list-group-item-danger' >"+n[0]+" ("+n[1]+")</li>";
108     }
110     html += "</ul>";
112     if (ok.length === 0) {
113         html += '<br /><img src="/static/documents/img/info_icon.png"> No items can be deleted.';
114         jQuery('#delete_seedlots_confirm').prop('disabled', true);
115     }
116     else {
117         jQuery('#delete_seedlots_confirm').prop('disabled', false);
118     }
120     jQuery('#seedlot_deletion_verify').html(html);
124 </script>