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 ( $seedlot_maintenance_enabled, $is_curator );
{
    my %pos;
    for ( my $x = 0; $x < @_; $x += 2 )
    {
        $pos{ $_[$x] } = $x + 1;
    }
#line 2 "/home/production/cxgn/sgn/mason/breeders_toolbox/download.mas"
     $seedlot_maintenance_enabled = exists $pos{'seedlot_maintenance_enabled'} ? $_[ $pos{'seedlot_maintenance_enabled'} ] :  0;
#line 3 "/home/production/cxgn/sgn/mason/breeders_toolbox/download.mas"
     $is_curator = exists $pos{'is_curator'} ? $_[ $pos{'is_curator'} ] :  0;
}
$m->debug_hook( $m->current_comp->path ) if ( HTML::Mason::Compiler::IN_PERL_DB() );

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

' );
#line 8 "/home/production/cxgn/sgn/mason/breeders_toolbox/download.mas"
$m->comp(   '/page/page_title.mas', title=>"Download Using Lists"   
); #line 8 "/home/production/cxgn/sgn/mason/breeders_toolbox/download.mas"
$m->print( '

<div class="container-fluid">

<div class="well">
Choose a list for each parameter and click "Download".
</div>

<div class="well well-sm">
<h4>Download Phenotypes Using Lists</h4><p>Select Parameters:</p>
<form id="download_form" action="/breeders/download_action" method="POST" >
<table class="table table-bordered" >
  <thead>
  <tr>
    <th>
      Accessions
    </th>
    <th>
      Trials
    </th>
    <th>
      Traits
    </th>
    <th>
        Options
    </th>
    <th>
      Action
    </th>
  </tr>
  </thead>
  <tbody>
  <tr>
    <td>
      <div id="accession_list">
      </div>
    </td>
    <td>
      <div id="trial_list">
      </div>
    </td>
    <td>
      <div id="trait_list">
      </div>
   </td>
    <td>
    <b>Format:</b><br/>
    <select class="form-control" id="format" name="format">
        <option value=".csv">CSV</option>
        <option value=".xlsx">XLSX</option>
        <option value="html">HTML</option>
    </select>
    <br/>
    <b>Data Level:</b><br/>
    <select class="form-control" id="phenotype_datalevel" name="phenotype_datalevel">
        <option value="all">All</option>
        <option value="plot">Plot</option>
        <option value="plant">Plant</option>
    </select>
    <br/>
    <b>Timestamp:</b><br/>
    <select class="form-control" id="timestamp" name="timestamp">
        <option value="0">No</option>
        <option value="1">Yes</option>
    </select>
    <br/>
    <b>Exclude Phenotype Outliers:</b><br/>
    <select class="form-control" id="exclude_phenotype_outlier" name="exclude_phenotype_outlier">
        <option value="0">No</option>
        <option value="1">Yes</option>
    </select>
    </td>
    <td>
      <button class="btn btn-primary" type="button" id="phenotype">Download</button>
      <input type="hidden" id="phenotype_download_token" name="phenotype_download_token"/>
    </td>
  </tr>
  </tbody>
  </table>
</form>
</div>

<div class="well well-sm">
<h4>Inspect Datasets</h4>
<table class="table table-bordered" >
  <thead>
  <tr>
    <th>
      Datasets
    </th>
  </tr>
  </thead>
  <tbody>
  <tr>
    <td>
      <div id="phenotype_download_dataset_list">
      </div>
    </td>
  </tr>
  </tbody>
  </table>
</div>

<div class="well well-sm">
<h4>Download Metadata</h4><p>Select Parameters:</p>
<form id="download_metadata_form" action="/breeders/download_action" method="POST" >
<table class="table table-bordered" >
  <thead>
  <tr>
    <th>
      Trials
    </th>
    <th>
        Options
    </th>
    <th>
      Action
    </th>
  </tr>
  </thead>
  <tbody>
  <tr>
    <td>
      <div id="trial_metadata_list">
      </div>
    </td>
    <td>
    <b>Format:</b><br/>
    <select class="form-control" id="metadata_format" name="metadata_format">
        <option value=".xlsx">XLSX</option>
        <option value=".csv">CSV</option>
        <option value="html">HTML</option>
    </select>
    <br/>
    <div id="datalevel" style="display:none">
      <select class="form-control" id="metadata_datalevel" name="metadata_datalevel">
          <option value="metadata">Metadata</option>
      </select>
    </div>
    </td>
    <td>
      <button class="btn btn-primary" type="button" id="metadata">Download</button>
      <input type="hidden" id="metadata_download_token" name="metadata_download_token"/>
    </td>
  </tr>
  </tbody>
  </table>
</form>
</div>

<script>
$(document).ready(function() {

    var lo = new CXGN.List();

    $(\'#accession_list\').html(lo.listSelect(\'accession_list\', [ \'accessions\' ], \'select\', undefined, undefined));
    $(\'#trial_list\').html(lo.listSelect(\'trial_list\', [ \'trials\' ], \'select\', undefined, undefined ));
    $(\'#trait_list\').html(lo.listSelect(\'trait_list\', [ \'traits\' ], \'select\', undefined, undefined  ));
    $(\'#trial_metadata_list\').html(lo.listSelect(\'trial_metadata_list\', [\'trials\'], \'select\', undefined, undefined));

    get_select_box(\'datasets\', \'phenotype_download_dataset_list\');

    $(\'#metadata\').click(function() {
      var trial_list_id = $(\'#trial_metadata_list_list_select\').val();
      var trial_validation = 1;
      if (trial_list_id) { trial_validation = lo.validate(trial_list_id, \'trials\', true).then(
         function(r) {
            if (r.missing.length != 0) {
               alert("The following lists did not pass validation: "+r.missing.join(", ")+". Please correct the list(s) and try again");
            }
            else {


//      var ladda = Ladda.create(this);
//      ladda.start();
//      var token = new Date().getTime(); //use the current timestamp as the token name and value
//      manage_dl_with_cookie(token, ladda);
//      jQuery(\'#metadata_download_token\').val(token);
               jQuery(\'#download_metadata_form\').submit();
            }
        });
      } });

    $(\'#phenotype\').click(function() {

      var accession_list_id = $(\'#accession_list_list_select\').val();
      var trial_list_id = $(\'#trial_list_list_select\').val();
      var trait_list_id = $(\'#trait_list_list_select\').val();

      var lists = new Array();
      var types = new Array();

      if (accession_list_id) {
         lists.push(accession_list_id);
         types.push(\'accessions\');
         //alert("ACC LIST ID = "+accession_list_id);
      }
      if (trial_list_id) {
          lists.push(trial_list_id);
          types.push(\'trials\');
      }

      if (trait_list_id) {
          lists.push(trait_list_id);
          types.push(\'traits\');
      }

      jQuery(\'#working_modal\').modal(\'show\');

      validateLists(lists, types).then(function(r) {
         console.log(\'validation results: \'+JSON.stringify(r));
         var names_str = \'\';
         for (var n=0; n < r.invalid_lists.length; n++) {
            names_str += r.invalid_lists[n][1];
	 }
         if(names_str.length > 0) {
            alert(\'Some lists (\'+names_str+\') are not valid, please check.\');
            jQuery(\'#working_modal\').modal(\'hide\');
         }
         else {
            download_phenotypes(this);
            jQuery(\'#working_modal\').modal(\'hide\');

         }},

         function(e) { alert(e);     jQuery(\'#working_modal\').modal(\'hide\');
}
         );

      });




//alert("The following lists did not pass validation: "+problem_lists.join(", ")+". Please correct the list(s) and try again");
//	 return;
//


});


function download_phenotypes() {
    //alert("NOW DOWNLOADING!");
    //var ladda = Ladda.create(data);
     // ladda.start();
      var token = new Date().getTime(); //use the current timestamp as the token name and value
     // manage_dl_with_cookie(token, ladda);
      jQuery(\'#phenotype_download_token\').val(token);
      jQuery(\'#download_form\').submit();


}

</script>



<!-- DOWNLOAD ACCESSION PROPERTIES -->

<div class="well well-sm">
  <form id="download_accession_properties" action="/breeders/download_accession_properties_action" method="POST">
    <table class="table"  cellpadding="10">
      <thead>
        <tr><td colspan="2"><h4>Download Accession Properties</h4><p>Select parameters:</p></tr>
        <tr>
          <th>Accessions</th>
          <th>Format</th>
          <th>Action</th>
        </tr>
      </thead>
      <tbody>
      <tr>
        <td>
          <div id="accession_list5"></div>
        </td>
        <td>
          <select class="form-control" id="accession_properties_format" name="file_format">
              <option value=".xlsx">XLSX</option>
              <option value=".csv">CSV</option>
          </select>
        </td>
        <td>
          <button class="btn btn-primary" type="button" id="accession_properties_download">Download</button>
          <input type="hidden" id="accession_properties_download_token" name="accession_properties_download_token"/>
        </td>
      </tr>
      </tbody>
  </table>
</form>
</div>


<script>
$(document).ready(function() {

    var lo = new CXGN.List();

    $(\'#accession_list5\').html(lo.listSelect(\'accession_properties_accession_list\', [ \'accessions\' ], \'select\', undefined, undefined));

    $(\'#accession_properties_download\').click(function() {

        var accession_list_id = $(\'#accession_properties_accession_list_list_select\').val();
        if (!accession_list_id) {
            alert("You need to select an accession list!");
            return;
        }


        if (accession_list_id) {
              jQuery(\'#working_modal\').modal(\'show\');
              lo.validate(accession_list_id, \'accessions\', true).then(
              function(r) {
                 if (r.valid != 1) {
                    alert("The accession list did not pass validation. Please correct the list and try again");
                    jQuery(\'#working_modal\').modal(\'hide\');
                 }
                 else {
                    //var ladda = Ladda.create(this);
                    //ladda.start();
                    //var token = new Date().getTime(); //use the current timestamp as the token name and value
                    //manage_dl_with_cookie(token, ladda);
                    //jQuery(\'#accession_properties_download_token\').val(token);
                    jQuery(\'#download_accession_properties\').submit();
                    jQuery(\'#working_modal\').modal(\'hide\');
                }
            });
        }
    });

});
</script>

<!-- END OF DOWNLOAD ACCESSION PROPERTIES -->





<!-- start of code for pedigree download -->

<div class="well well-sm">
<form id="download_pedigree" action="/breeders/download_pedigree_action" method="POST">
<table class="table"  cellpadding="10">
  <thead>
  <tr><td colspan="2"><h4>Download Pedigrees </h4><p>Select parameter:</p></tr>
  <tr>
    <th>
      Accessions
    </th>
    <th>
      Query
    </th>
    <th>
      Format
    </th>
    <th>
      Action
    </th>
  </tr>
  </thead>
  <tbody>
  <tr>
    <td>
      <div id="accession_list4">
      </div>
    </td>
    <td>
      <div style="width: 175px">
        <p><strong>Depth:</strong></p>
        <div class="radio">
          <label><input type="radio" id="ped_format_parents" name="ped_format" value="parents_only" checked>Only One Generation</label>
        </div>
        <div class="radio">
          <label><input type="radio" id="ped_format_full" name="ped_format" value="full">All Generations</label>
        </div>
        <p><strong>Include:</strong></p>
        <div class="radio">
          <label><input type="radio" id="include_ancestors" name="ped_include" value="ancestors" checked>Only Ancestors</label>
        </div>
        <div class="radio">
          <label><input type="radio" id="include_ancestors_descendants" name="ped_include" value="ancestors_descendants">Ancestors and Descendants</label>
        </div>
      </div>
    </td>
    <td>
      <select class="form-control" id="pedigree_file_format" name="file_format">
        <option value=".txt">Plain Text</option>
        <option value=".helium">Helium Format</option>
      </select>
    </td>
    <td>
      <button class="btn btn-primary" type="button" id="pedigree">Download</button>
      <input type="hidden" id="pedigree_download_token" name="pedigree_download_token"/>
    </td>
  </tr>
  </tbody>
  </table>
</form>
</div>


<script>
$(document).ready(function() {

    var lo = new CXGN.List();

    $(\'#accession_list4\').html(lo.listSelect(\'pedigree_accession_list\', [ \'accessions\' ], \'select\', undefined, undefined));

    $(\'#pedigree\').click(function() {

        var accession_list_id = $(\'#pedigree_accession_list_list_select\').val();
        if (!accession_list_id) {
            alert("You need to select an accession list!");
            return;
        }

        if (accession_list_id) {
           accession_validation = lo.validate(accession_list_id, \'accessions\', true).then(
             function(r) {
                 if(r.valid != 1) {
                   alert("The accession list did not pass validation. Please correct the list and try again");
                 }
                 else {
                    //var ladda = Ladda.create(this);
                    //ladda.start();
                    //var token = new Date().getTime(); //use the current timestamp as the token name and value
                    //manage_dl_with_cookie(token, ladda);
                    //jQuery(\'#pedigree_download_token\').val(token);
                    jQuery(\'#working_modal\').modal(\'show\');
                    var http = new XMLHttpRequest();
                    http.open(\'POST\', \'/breeders/download_pedigree_action\', true);
                    http.setRequestHeader(\'Content-type\', \'application/x-www-form-urlencoded\');
                    http.onreadystatechange = () => {
                      if( http.readyState == 4 ) {
                        jQuery(\'#working_modal\').modal(\'hide\');
                        if ( http.status == 200) {
                          var blob = new Blob([http.response], { type : \'plain/text\' });
                          var fileName = http.getResponseHeader("FileName");
                          var link = document.createElement(\'a\');
                          link.href = window.URL.createObjectURL(blob);
                          link.download = fileName;
                          link.click();
                        }
                      }
                    }
                    http.send(jQuery("#download_pedigree").serialize());
                 }
             });
        } });
});

</script>

<!-- end of code for pedigree download -->

<!-- start of code for cross and family download -->

<div class="well well-sm">
    <form id="download_cross_family" action="/breeders/download_cross_family_of_progenies" method="POST">
        <table class="table"  cellpadding="10">
            <thead>
                <tr><td colspan="2"><h4>Download Crosses and Families of Progenies </h4><p>Select parameters:</p></tr>
                <tr>
                    <th>Accessions</th>
                    <th>Format</th>
                    <th>Action</th>
                </tr>
            </thead>
            <tbody>
                <tr>
                    <td>
                        <div id="progeny_list"></div>
                    </td>
                    <td>
                        <select class="form-control" id="cross_family_file_format" name="file_format">
                            <option value=".xlsx">XLSX</option>
                        </select>
                    </td>
                    <td>
                        <button class="btn btn-primary" type="button" id="cross_family">Download</button>
                        <input type="hidden" id="progeny_list_id" name="list_id" />
                        <input type="hidden" id="cross_family_download_token" name="list_download_token" />
                    </td>
                </tr>
            </tbody>
        </table>
    </form>
</div>


<script>
$(document).ready(function() {
    const lo = new CXGN.List();
    jQuery(\'#progeny_list\').html(lo.listSelect(\'progeny_list\', [ \'accessions\' ], \'select\', undefined, undefined));
    jQuery(\'#cross_family\').click(function() {
        const progeny_list_id = $(\'#progeny_list_list_select\').val();
        if (!progeny_list_id) {
            alert("You need to select an accession list!");
            return;
        }
        else {
            lo.validate(progeny_list_id, \'accessions\', true).then((r) => {
                if (r.missing.length > 0) {
                   alert("The accession list did not pass validation. Please correct the list and try again");
                }
                else {
                    jQuery("#progeny_list_id").val(seedlot_list_id);
                    jQuery(\'#download_cross_family\').submit();
                }
            });
        }
    });
});

</script>

<!-- end of code for cross and family download -->


<!-- start of code for seedlot details download -->

<div class="well well-sm">
    <form id="download_seedlot_details" action="/list/download_details" method="POST">
        <table class="table"  cellpadding="10">
            <thead>
                <tr><td colspan="2"><h4>Download Seedlot Details </h4><p>Select parameters:</p></tr>
                <tr>
                    <th>Seedlots</th>
                    <th>Format</th>
                    <th>Action</th>
                </tr>
            </thead>
            <tbody>
                <tr>
                    <td>
                        <div id="seedlot_list"></div>
                    </td>
                    <td>
                        <select class="form-control" id="seedlot_file_format" name="file_format">
                            <option value=".txt">Plain Text</option>
                        </select>
                    </td>
                    <td>
                        <button class="btn btn-primary" type="button" id="seedlot">Download</button>
                        <input type="hidden" id="seedlot_list_id" name="list_id" />
                        <input type="hidden" id="seedlot_download_token" name="list_download_token" />
                    </td>
                </tr>
            </tbody>
        </table>
    </form>
</div>


<script>
$(document).ready(function() {
    var lo = new CXGN.List();
    $(\'#seedlot_list\').html(lo.listSelect(\'seedlot_list\', [ \'seedlots\' ], \'select\', undefined, undefined));
    $(\'#seedlot\').click(function() {
        var seedlot_list_id = $(\'#seedlot_list_list_select\').val();
        if (!seedlot_list_id) {
            alert("You need to select a seedlot list!");
            return;
        }
        else {
            lo.validate(seedlot_list_id, \'seedlots\', true).then((r) => {
                if (r.missing.length > 0) {
                   alert("The seedlot list did not pass validation. Please correct the list and try again");
                }
                else {
                    jQuery("#seedlot_list_id").val(seedlot_list_id);
                    jQuery(\'#download_seedlot_details\').submit();
                }
            });
        }
    });
});

</script>

<!-- end of code for seedlot download -->



<!-- start of code for download seedlot matinenance events -->

' );
#line 595 "/home/production/cxgn/sgn/mason/breeders_toolbox/download.mas"
 if ( $seedlot_maintenance_enabled ) {
$m->print( '
<div class="well well-sm">
  <form id="download_seedlot_maintenance_events" action="/breeders/download_seedlot_maintenance_events_action" method="POST">
      <table class="table"  cellpadding="10">
        <thead>
          <tr><td colspan="2"><h4>Download Seedlot Maintenance Events</h4><p>Select parameters:</p></tr>
          <tr>
            <th>Seedlots</th>
            <th>Format</th>
            <th>Action</th>
          </tr>
        </thead>
        <tbody>
        <tr>
          <td>
            <div id="seedlot_list1"></div>
          </td>
          <td>
            <select class="form-control" id="seedlot_maintenance_events_format" name="file_format">
                <option value=".xlsx">XLSX</option>
            </select>
          </td>
          <td>
            <button class="btn btn-primary" type="button" id="seedlot_maintenance_events_download">Download</button>
            <input type="hidden" id="seedlot_maintenance_events_download_token" name="seedlot_maintenance_events_download_token"/>
          </td>
        </tr>
        </tbody>
    </table>
  </form>
</div>

<script>
$(document).ready(function() {

    var lo = new CXGN.List();

    $(\'#seedlot_list1\').html(lo.listSelect(\'seedlot_maintenance_events_list\', [ \'seedlots\' ], \'select\', undefined, undefined));

    $(\'#seedlot_maintenance_events_download\').click(function() {

        var seedlot_list_id = $(\'#seedlot_maintenance_events_list_list_select\').val();
        if (!seedlot_list_id) {
            alert("You need to select a seedlot list!");
            return;
        }

        var seedlot_validation = 1;
        if (seedlot_list_id) {
            seedlot_validation = lo.validate(seedlot_list_id, \'seedlots\', true);
        }

        if (seedlot_validation != 1) {
            alert("The seedlot list did not pass validation. Please correct the list and try again");
            return;
        }

        var ladda = Ladda.create(this);
        ladda.start();
        var token = new Date().getTime(); //use the current timestamp as the token name and value
        manage_dl_with_cookie(token, ladda);
        jQuery(\'#seedlot_maintenance_events_download_token\').val(token);
        jQuery(\'#download_seedlot_maintenance_events\').submit();

    });
});

</script>

' );
#line 665 "/home/production/cxgn/sgn/mason/breeders_toolbox/download.mas"
 }
$m->print( '
<!-- end of code for seedlot maintenance event download -->


<!-- start of code for obsolete metadata download -->

' );
#line 672 "/home/production/cxgn/sgn/mason/breeders_toolbox/download.mas"
 if ($is_curator) {
$m->print( '
<div class="well well-sm">
    <form id="download_obsolete_metadata_action" action="/breeders/download_obsolete_metadata_action" method="POST">
        <table class="table" cellpadding="10">
            <thead>
                <tr><td colspan="2"><h4>Download Obsolete Metadata</h4><p>Select parameters:</p></tr>
                <tr>
                    <th>Obsoleted Stocks</th>
                    <th>Format</th>
                    <th>Action</th>
                </tr>
            </thead>
            <tbody>
                <tr>
                    <td>
                        <div id="obsoleted_stock_list"></div>
                    </td>
                    <td>
                        <select class="form-control" id="obsoleted_metadata_format" name="file_format">
                            <option value=".xlsx">XLSX</option>
                        </select>
                    </td>
                    <td>
                        <button class="btn btn-primary" type="button" id="obsolete_metadata_download">Download</button>
                        <input type="hidden" id="obsolete_metadata_download_token" name="obsolete_metadata_download_token"/>
                    </td>
                </tr>
            </tbody>
        </table>
    </form>
</div>

<script>
jQuery(document).ready(function() {

    var lo = new CXGN.List();
    jQuery(\'#obsoleted_stock_list\').html(lo.listSelect(\'obsoleted_stock_list\', [ \'obsoleted_stocks\' ], \'Please select\', undefined, undefined));

    jQuery(\'#obsolete_metadata_download\').click(function() {
        var obsoleted_stock_list_id = jQuery(\'#obsoleted_stock_list_list_select\').val();
        if (!obsoleted_stock_list_id) {
            alert("Please select an obsoleted stock list!");
            return;
        } else {
            lo.validate(obsoleted_stock_list_id, \'obsoleted_stocks\', true).then((r) => {
                if (r.missing.length > 0) {
                   alert("The obsoleted stock list did not pass validation. Please correct the list and try again");
                } else {
                    var token = new Date().getTime(); //use the current timestamp as the token name and value
                    jQuery(\'#obsolete_metadata_download_token\').val(token);
                    jQuery(\'#download_obsolete_metadata_action\').submit();
                }
            });
        }
    });

});

</script>

' );
#line 733 "/home/production/cxgn/sgn/mason/breeders_toolbox/download.mas"
 }
$m->print( '
<!-- end of code for obsolete metadata download -->


<div class="well well-sm">
<form id="download_gbs" action="/breeders/download_gbs_action" method="POST">
<table class="table"  cellpadding="10">
  <thead>
  <tr><td colspan="2"><h4>Download Genotypes </h4><p>Select parameter:</p></tr>
  <tr>
    <th>
      Accessions
    </th>
    <th>
      Genotyping Protocol
    </th>
    <th>
      Action
    </th>
  </tr>
  </thead>
  <tbody>
  <tr>
    <td>
      <div id="accession_list2">
      </div>
    </td>
    <td>
      <div id="protocol_list">
      </div>
    </td>
    <td>
      <button class="btn btn-primary" type="button" id="genotype">Download</button>
      <input type="hidden" id="gbs_download_token" name="gbs_download_token"/>
    </td>
  </tr>
  </tbody>
  </table>
</form>
</div>

<script>
  $(document).ready(function() {

      var lo = new CXGN.List();

      $(\'#accession_list2\').html(lo.listSelect(\'genotype_accession_list\', [ \'accessions\' ], \'select\', undefined, undefined));
      get_select_box("genotyping_protocol", "protocol_list");

      $(\'#genotype\').click(function() {

      var accession_list_id = $(\'#genotype_accession_list_list_select\').val();
      var protocol_list_id = $(\'#gtp_select\').val();

      var accession_validation = 1;
      if (accession_list_id) {
  accession_validation = lo.validate(accession_list_id, \'accessions\', true).then(
     function(r) {
         if (!( accession_list_id || protocol_list_id) ) {
             alert("You need to select a list of accessions and a protocol !");
         }
         else if(r.valid != 1)  {
             alert("The accession list could not be validated. Please correct the list(s) and try again");
         }
  else  {


      //var ladda = Ladda.create(this);
      //ladda.start();
      //var token = new Date().getTime(); //use the current timestamp as the token name and value
      //manage_dl_with_cookie(token, ladda);
      //jQuery(\'#gbs_download_token\').val(token);
      jQuery(\'#download_gbs\').submit();
   }
  }, function(e) { alert(\'An error occurred.\'); });
  }

  });
  });
</script>

<div class="well well-sm">
<form id="gbs_qc" action="/breeders/gbs_qc_action" method="POST">
<table class="table" cellpadding="10">
  <thead>
  <tr><td colspan="3"><h4>Genotyping QC</h4><p>Select parameter:</p></tr>
  <tr>
    <th>
      Trials
    </th>
    <th>
      Accessions
    </th>
    <th>
      Genotyping Protocol
    </th>
    <th>
      Action
    </th>
  </tr>
  </thead>
  <tbody>
  <tr>
    <td>
      <div id="trial_list3">
      </div>
    </td>
    <td>
      <div id="accession_list3">
      </div>
    </td>
    <td>
      <div id="protocol_list2">
      </div>
    </td>
    <td>
      <button class="btn btn-primary" type="button" id="genotype_qc">Download</button>
      <input type="hidden" id="qc_download_token" name="qc_download_token"/>
    </td>
  </tr>
  </tbody>
  </table>
</form>
</div>

</div>

<script>
  $(document).ready(function() {

      var lo = new CXGN.List();

      $(\'#accession_list3\').html(lo.listSelect(\'genotype_qc_accession_list\', [ \'accessions\' ], \'select\', undefined, undefined));
      $(\'#trial_list3\').html(lo.listSelect(\'genotype_trial_list\', [ \'trials\' ], \'select\', undefined, undefined ));
      get_select_box("genotyping_protocol", "protocol_list2", {\'id\':\'protocol_list2_select\', \'name\':\'protocol_list2_select\'});

      $(\'#genotype_qc\').click(function() {

	$(\'#working\').dialog( {
		height: 100,
		width:  300,
		modal: true,
		autoOpen: false,
		closeOnEscape: true,
		draggable: true,
		resizable: true,
		open: function() { $(this).closest(\'.ui-dialog\').find(\'.ui-dialog-titlebar-close\').hide(); },
		title: \'Downloading genotype...\'
		});

      var lists = new Array();

      var accession_list_id = $(\'#genotype_qc_accession_list_list_select\').val();
      var trial_list_id = $(\'#genotype_trial_list_list_select\').val();


      if (! (accession_list_id || trial_list_id) ) {
        alert("You need to select an accession or a trial, or both!");
        return;
      }

      var lists = new Array();
      var types = new Array();

  if (accession_list_id) {
  lists.push(accession_list_id);
  types.push(\'accessions\');
  }

  if(trial_list_id) {
  lists.push(trial_list_id);
  types.push(\'trials\');
  }


      validateLists(lists, types).then(function(r) {
         console.log(\'validation results: \'+JSON.stringify(r));
         var names_str = \'\';
         for (var n=0; n < r.invalid_lists.length; n++) {
            names_str += r.invalid_lists[n][1];
	 }
         if(names_str.length > 0) {
            alert(\'Some lists (\'+names_str+\') are not valid, please check.\');
            jQuery(\'#working_modal\').modal(\'hide\');
         }
         else {
           //      var ladda = Ladda.create(this);
//         ladda.start();
//         var token = new Date().getTime(); //use the current timestamp as the token name and value
//          manage_dl_with_cookie(token, ladda);
//          jQuery(\'#qc_download_token\').val(token);
            jQuery(\'#gbs_qc\').submit();

            jQuery(\'#working_modal\').modal(\'hide\');

        }

      });


    });

  });
</script>
' );
;return;
},
'declared_args' => {
  '$is_curator' => { default => ' 0' },
  '$seedlot_maintenance_enabled' => { default => ' 0' }
},
'load_time' => 1763105272,

)
;