package SGN::View::Mason::Commands;
use strict;
use vars qw($m $c);
HTML::Mason::Component::FileBased->new(
'code' => sub {
use utf8; local $SGN::View::Mason::Commands::m = $HTML::Mason::Commands::m;
HTML::Mason::Exception::Params->throw
    ( error =>
      "Odd number of parameters passed to component expecting name/value pairs"
    ) if @_ % 2;
my ( $user_role );
{
    my %pos;
    for ( my $x = 0; $x < @_; $x += 2 )
    {
        $pos{ $_[$x] } = $x + 1;
    }
#line 3 "/home/production/cxgn/sgn/mason/breeders_toolbox/delete_seedlots.mas"
     $user_role = exists $pos{'user_role'} ? $_[ $pos{'user_role'} ] :  undef;
}
$m->debug_hook( $m->current_comp->path ) if ( HTML::Mason::Compiler::IN_PERL_DB() );

#line 1 "/home/production/cxgn/sgn/mason/breeders_toolbox/delete_seedlots.mas"
$m->print( '
' );
#line 5 "/home/production/cxgn/sgn/mason/breeders_toolbox/delete_seedlots.mas"
$m->print( '
' );
#line 6 "/home/production/cxgn/sgn/mason/breeders_toolbox/delete_seedlots.mas"
$m->comp(   '/util/import_javascript.mas', classes => [ 'jquery', 'jqueryui', 'CXGN.BreedersToolbox.HTMLSelect', 'CXGN.List' ]   
); #line 6 "/home/production/cxgn/sgn/mason/breeders_toolbox/delete_seedlots.mas"
$m->print( '

<div class="modal fade" id="delete_seedlots_using_list_dialog" name="delete_seedlots_using_list_dialog" tabindex="-1" role="dialog" aria-labelledby="deleteSeedlotsDialog">
    <div class="modal-dialog modal-lg" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title" id="deleteSeedlotsDialog">Delete Seedlots </h4>
            </div>
            <div class="modal-body">
                <div class="container-fluid">
                    <div class="well well-sm">
                        <form class="form-horizontal" id="delete_seedlot_info" name="delete_seedlot_info">
                            <div class="form-group form-group-sm">
                                <ul>
                                    <strong>Note:</strong>
                                    <li>Only seedlots that are not associated with crosses or trials can be deleted.</li>
                                    <li>Deleting seedlots cannot be undone.</li>
                                </ul>
                            </div>
                        </form>
                    </div>
                    <form class="form-horizontal" role="form" method="post" id="delete_seedlots_form" name="delete_seedlots_form">
                        <div class="form-group" id="delete_seedlot_list_section" >
                            <label class="col-sm-4 control-label">Select a List of Seedlots:</label>
                            <div class="col-sm-8" id="seedlots_to_delete_html" name="seedlots_to_delete_html"></div>
                        </div>
                    </form>
                </div>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
                <button type="button" class="btn btn-primary" name="delete_seedlots_submit" id="delete_seedlots_submit">Delete Seedlots</button>
            </div>
        </div>
    </div>
</div>

<div class="modal fade" id="delete_seedlots_modal" name="delete_seedlots_modal" tabindex="-1" role="dialog">
    <div class="modal-dialog modal-lg" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title">Seedlot Deletion Verify</h4>
            </div>
            <div class="modal-body">
              <div class="container-fluid">
		<div id="seedlot_deletion_verify">
                </div>
	      </div>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
                <button type="button" class="btn btn-primary" name="delete_seedlots_confirm" id="delete_seedlots_confirm">Delete green elements</button>
            </div>
        </div>
    </div>
</div>


<script>

jQuery(window).ready( function() {

    jQuery("#delete_seedlots_link").click( function() {
        jQuery(\'#delete_seedlots_using_list_dialog\').modal(\'show\');
    });

    jQuery("#seedlots_to_delete_html").append(list.listSelect("seedlots_to_delete_html_select", [ \'seedlots\' ], \'None\', undefined, undefined));
    
});

jQuery(\'#delete_seedlots_submit\').click( function() {
   var list_id = jQuery(\'#seedlots_to_delete_html_select_list_select\').val();
   if (list_id === "") { alert("Please select a list "+list_id); return; }
   verify_seedlot_deletion(list_id).then(function(r) { display_seedlot_deletion_info(r) }, function(r) { alert("ERROR!")});
});

jQuery(\'#delete_seedlots_confirm\').click( function() {
    var list_id = jQuery(\'#seedlots_to_delete_html_select_list_select\').val();
    if (list_id) {
        delete_seedlots(list_id).then( function(r) { alert(r.delete_count+" elements have been deleted"); }, function(r) { alert(\'An error occurred\'); });
    }
});

function verify_seedlot_deletion(list_id) {

   return jQuery.ajax( {
        url: \'/ajax/seedlots/verify_delete_by_list?list_id=\'+list_id,
    });
}

function delete_seedlots(list_id) {
   return jQuery.ajax( {
       url: \'/ajax/seedlots/confirm_delete_by_list?list_id=\'+list_id,
   });
}

function display_seedlot_deletion_info(r) {
    jQuery(\'#delete_seedlots_modal\').modal(\'show\');

    var ok = r.ok;
    var errors = r.errors;

    var html = "";

    for (const n of ok) {
        html += "<li class=\'list-group-item list-group-item-success\'>"+n+"</li>";
    }

    for (const n of errors) {
       html += "<li class=\'list-group-item list-group-item-danger\' >"+n[0]+" ("+n[1]+")</li>";
    }

    html += "</ul>";

    if (ok.length === 0) {
        html += \'<br /><img src="/static/documents/img/info_icon.png"> No items can be deleted.\';
        jQuery(\'#delete_seedlots_confirm\').prop(\'disabled\', true);
    }
    else {
        jQuery(\'#delete_seedlots_confirm\').prop(\'disabled\', false);
    }

    jQuery(\'#seedlot_deletion_verify\').html(html);

}

</script>
' );
;return;
},
'declared_args' => {
  '$user_role' => { default => ' undef' }
},
'load_time' => 1763131595,

)
;