6 <& /util/import_javascript.mas, classes => [ 'jquery', 'jqueryui', 'CXGN.BreedersToolbox.HTMLSelect', 'CXGN.List' ] &>
9 <&| /page/info_section.mas, title=>"Delete seedlots using a list", collapsible => 1, collapsed=>1 &>
12 % if ($user_role eq "curator" ) {
13 <div style="margin-left:20px">
16 <p><strong>Select a list of type "seedlot" to delete from the database</strong></p>
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>
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">
28 <button type="button" class="btn btn-primary" name="delete_seedlots_submit" id="delete_seedlots_submit">Delete Seedlots</button>
35 You need to be logged in or you do not have sufficient privileges to delete seedlots using lists.
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">×</span></button>
45 <h4 class="modal-title">Seedlot Deletion Verify</h4>
47 <div class="modal-body">
48 <div class="container-fluid">
49 <div id="seedlot_deletion_verify">
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>
64 jQuery(window).ready( function() {
65 jQuery("#seedlots_to_delete_html").append(list.listSelect("seedlots_to_delete_html_select", [ 'seedlots' ], 'None', undefined, undefined));
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!")});
74 jQuery('#delete_seedlots_confirm').click( function() {
75 var list_id = jQuery('#seedlots_to_delete_html_select_list_select').val();
77 delete_seedlots(list_id).then( function(r) { alert(r.delete_count+" elements have been deleted"); }, function(r) { alert('An error occurred'); });
81 function verify_seedlot_deletion(list_id) {
84 url: '/ajax/seedlots/verify_delete_by_list?list_id='+list_id,
88 function delete_seedlots(list_id) {
90 url: '/ajax/seedlots/confirm_delete_by_list?list_id='+list_id,
94 function display_seedlot_deletion_info(r) {
95 jQuery('#delete_seedlots_modal').modal('show');
98 var errors = r.errors;
102 for (const n of ok) {
103 html += "<li class='list-group-item list-group-item-success'>"+n+"</li>";
106 for (const n of errors) {
107 html += "<li class='list-group-item list-group-item-danger' >"+n[0]+" ("+n[1]+")</li>";
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);
117 jQuery('#delete_seedlots_confirm').prop('disabled', false);
120 jQuery('#seedlot_deletion_verify').html(html);