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 ( $trial_id, $trial_name );
{
    my %pos;
    for ( my $x = 0; $x < @_; $x += 2 )
    {
        $pos{ $_[$x] } = $x + 1;
    }

    foreach my $arg ( qw( trial_id ) )
    {
        HTML::Mason::Exception::Params->throw
            ( error => "no value sent for required parameter '$arg'" )
                unless exists $pos{$arg};
    }
#line 3 "/home/production/cxgn/sgn/mason/breeders_toolbox/trial/add_plants_per_plot.mas"
    $trial_id = $_[ $pos{'trial_id'} ];
#line 4 "/home/production/cxgn/sgn/mason/breeders_toolbox/trial/add_plants_per_plot.mas"
     $trial_name = exists $pos{'trial_name'} ? $_[ $pos{'trial_name'} ] :  undef;
}
$m->debug_hook( $m->current_comp->path ) if ( HTML::Mason::Compiler::IN_PERL_DB() );

#line 1 "/home/production/cxgn/sgn/mason/breeders_toolbox/trial/add_plants_per_plot.mas"
$m->print( '
' );
#line 6 "/home/production/cxgn/sgn/mason/breeders_toolbox/trial/add_plants_per_plot.mas"
$m->print( '
<div class="modal fade" id="add_plants_dialog" name="add_plants_dialog" tabindex="-1" role="dialog" aria-labelledby="addPlantsDialog">
  <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="addPlantsDialog">Add plants to ' );
#line 12 "/home/production/cxgn/sgn/mason/breeders_toolbox/trial/add_plants_per_plot.mas"
$m->print(  $trial_name  );
#line 12 "/home/production/cxgn/sgn/mason/breeders_toolbox/trial/add_plants_per_plot.mas"
$m->print( '</h4>
      </div>
      <div class="modal-body">
        <div class="container-fluid">

	       <form class="form-horizontal" role="form" method="post" id="add_plants_dialog_form" name="add_plants_dialog_form">
	        <div class="form-group">
      	      <label class="col-sm-3 control-label">Maximum number of plants per plot: </label>
      	      <div class="col-sm-9" >
                <input name="add_plants_per_plot_num" id="add_plants_per_plot_num" class="form-control" type="number" autofocus/>
              </div>
	        </div>
            <div class="form-group">
      	      <label class="col-sm-3 control-label">Inherits Treatment(s) From Plots: </label>
      	      <div class="col-sm-9" >
                <input name="add_plants_per_plot_inherit_treatments" id="add_plants_per_plot_inherit_treatments" type="checkbox" checked disabled/>
              </div>
	        </div>
            <div class="form-group">
      	      <label class="col-sm-3 control-label">Assign row and column data to plants within plots?</label>
      	      <div class="col-sm-9" >
                <input name="add_rows_and_columns_to_plants" id="add_rows_and_columns_to_plants" type="checkbox"/>
                <div id="plant_row_column_format_dialog" style="display:none">
                    <p><i>One plant per (row,column) coordinate. Rows and columns will be populated in a zigzag pattern. Row and column numbers start at 1 within each plot.</i></p>
                    <table style="width:60%">
                        <tr>
                            <td>
                                <label>Number of rows per plot</label>
                            </td>
                            <td>
                                <input name="rows_per_plot" id="rows_per_plot" type="number"/>
                            </td>
                        </tr><tr>
                            <td>
                                <label>Number of columns per plot</label>
                            </td>
                            <td>
                                <input name="cols_per_plot" id="cols_per_plot" type="number"/>
                            </td>
                        </tr>
                    </table>
                </div>
              </div>
	        </div>
	       </form><br/>

        </div>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" name="add_plants_cancel_button" id="add_plants_cancel_button" data-dismiss="modal">Close</button>
	      <button type="button" class="btn btn-primary" name="add_plants_save_button" id="add_plants_save_button" title="Save">Save</button>
      </div>
    </div>
  </div>
</div>

<div class="modal fade" id="upload_plants_dialog" name="upload_plants_dialog" tabindex="-1" role="dialog" aria-labelledby="uploadPlantsDialog">
    <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="uploadPlantsDialog">Upload plants to ' );
#line 73 "/home/production/cxgn/sgn/mason/breeders_toolbox/trial/add_plants_per_plot.mas"
$m->print(  $trial_name  );
#line 73 "/home/production/cxgn/sgn/mason/breeders_toolbox/trial/add_plants_per_plot.mas"
$m->print( '</h4>
            </div>
            <div class="modal-body">
                <div class="container-fluid">

                    ' );
#line 78 "/home/production/cxgn/sgn/mason/breeders_toolbox/trial/add_plants_per_plot.mas"
$m->comp( { content => sub {
#line 78 "/home/production/cxgn/sgn/mason/breeders_toolbox/trial/add_plants_per_plot.mas"
$m->print( '
                        <p>
                            <b>File format information</b>
                            <br>
                            <a id="trial_upload_plants_spreadsheet_info_format">Spreadsheet format</a>
                        </p>
                    ' );
#line 84 "/home/production/cxgn/sgn/mason/breeders_toolbox/trial/add_plants_per_plot.mas"
} }, '/page/explanation.mas', title=>'Template information'
 );
#line 84 "/home/production/cxgn/sgn/mason/breeders_toolbox/trial/add_plants_per_plot.mas"
$m->print( '

                    <form class="form-horizontal" role="form" method="post" enctype="multipart/form-data" encoding="multipart/form-data" id="upload_plants_dialog_form" name="upload_plants_dialog_form">
                        <div class="form-group">
                            <label class="col-sm-4 control-label">Upload File (.xls or .xlsx): </label>
                            <div class="col-sm-8" >
                                <input type="file" name="trial_upload_plants_file" id="trial_upload_plants_file" encoding="multipart/form-data" />
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-4 control-label">Maximum number of plants per plot: </label>
                            <div class="col-sm-8" >
                                <input name="upload_plants_per_plot_number" id="upload_plants_per_plot_number" class="form-control" type="number" />
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-4 control-label">Inherits Treatment(s) From Plots: </label>
                            <div class="col-sm-8" >
                                <input name="upload_plants_per_plot_inherit_treatments" id="upload_plants_per_plot_inherit_treatments" type="checkbox" checked disabled/>
                            </div>
                        </div>
                    </form><br/>
                </div>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" name="upload_plants_cancel_button" id="upload_plants_cancel_button" data-dismiss="modal">Close</button>
                <button type="button" class="btn btn-primary" name="upload_plants_save_button" id="upload_plants_save_button" title="Upload">Upload</button>
            </div>
        </div>
    </div>
</div>

<div class="modal fade" id="upload_plants_spreadsheet_info_dialog" name="upload_plants_spreadsheet_info_dialog" tabindex="-1" role="dialog" aria-labelledby="uploadPlantsInfoDialog">
    <div class="modal-dialog modal-lg" role="document">
        <div class="modal-content">
            <div class="modal-header" style="text-align: center">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title" id="uploadPlantsInfoDialog">Upload Template Information</h4>
            </div>
            <div class="modal-body">
                <div class="container-fluid">
                    <b>This is for recording individual plants in a plot.</b>
                    <br/>
                    <b>Plant names may be uploaded in an Excel (.xls or .xlsx)</b>
                    <br />
                    <b>Header:</b>
                    <br>
                    The first row (header) should contain the following:
                    <br />

                    <table class="table table-hover table-bordered table-condensed" >
                        <thead></thead>
                        <tbody>
                            <tr>
                                <td>plot_name</td>
                                <td>plant_name</td>
                            </tr>
                        </tbody>
                    </table>

                    <b>Required fields:</b>
                    <br/>
                    - plot_name (must exist in the database already)
                    <br />
                    - plant_name (must be globally unique. usually this is a concatenation of plot_name + plant_number, such as MyTrial_plot101_plant1)

                    <br>
                    <b>Optional fields:</b>
                    <br>
                    - row_num
                    <br>
                    - col_num
                    <br>
                    Rows and columns are at the plot level if each plot contains multiple plants. If including this data, both fields must be present.
                </div>
            </div>
            <div class="modal-footer">
                <button id="close_upload_plants_info_dialog" type="button" class="btn btn-default" data-dismiss="modal">Close</button>
            </div>
        </div>
    </div>
</div>


<div class="modal fade" id="upload_plants_with_index_number_dialog" name="upload_plants_with_index_number_dialog" tabindex="-1" role="dialog" aria-labelledby="uploadPlantsWithIndexNumberDialog">
    <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="uploadPlantsWithIndexNumberDialog">Upload plants to ' );
#line 173 "/home/production/cxgn/sgn/mason/breeders_toolbox/trial/add_plants_per_plot.mas"
$m->print(  $trial_name  );
#line 173 "/home/production/cxgn/sgn/mason/breeders_toolbox/trial/add_plants_per_plot.mas"
$m->print( ' with plant index number</h4>
            </div>
            <div class="modal-body">
                <div class="container-fluid">

                    ' );
#line 178 "/home/production/cxgn/sgn/mason/breeders_toolbox/trial/add_plants_per_plot.mas"
$m->comp( { content => sub {
#line 178 "/home/production/cxgn/sgn/mason/breeders_toolbox/trial/add_plants_per_plot.mas"
$m->print( '
                        <p>
                            <b>File format information</b>
                            <br>
                            <a id="trial_upload_plants_with_index_number_spreadsheet_info_format">Spreadsheet format</a>
                        </p>
                    ' );
#line 184 "/home/production/cxgn/sgn/mason/breeders_toolbox/trial/add_plants_per_plot.mas"
} }, '/page/explanation.mas', title=>'Template information'
 );
#line 184 "/home/production/cxgn/sgn/mason/breeders_toolbox/trial/add_plants_per_plot.mas"
$m->print( '

                    <form class="form-horizontal" role="form" method="post" enctype="multipart/form-data" encoding="multipart/form-data" id="upload_plants_with_index_number_dialog_form" name="upload_plants_with_index_number_dialog_form">
                        <div class="form-group">
                            <label class="col-sm-4 control-label">Upload File (.xls or .xlsx): </label>
                            <div class="col-sm-8" >
                                <input type="file" name="trial_upload_plants_with_index_number_file" id="trial_upload_plants_with_index_number_file" encoding="multipart/form-data" />
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-4 control-label">Maximum number of plants per plot: </label>
                            <div class="col-sm-8" >
                                <input name="upload_plants_with_index_number_per_plot_number" id="upload_plants_with_index_number_per_plot_number" class="form-control" type="number" />
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-4 control-label">Inherits Treatment(s) From Plots: </label>
                            <div class="col-sm-8" >
                                <input name="upload_plants_with_index_number_inherit_treatments" id="upload_plants_with_index_number_inherit_treatments" type="checkbox" checked disabled/>
                            </div>
                        </div>
                    </form><br/>
                </div>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" name="upload_plants_with_index_number_cancel_button" id="upload_plants_with_index_number_cancel_button" data-dismiss="modal">Close</button>
                <button type="button" class="btn btn-primary" name="upload_plants_with_index_number_save_button" id="upload_plants_with_index_number_save_button" title="Upload">Upload</button>
            </div>
        </div>
    </div>
</div>

<div class="modal fade" id="upload_plants_with_index_number_spreadsheet_info_dialog" name="upload_plants_with_index_number_spreadsheet_info_dialog" tabindex="-1" role="dialog" aria-labelledby="uploadPlantsWithIndexNumberInfoDialog">
    <div class="modal-dialog modal-lg" role="document">
        <div class="modal-content">
            <div class="modal-header" style="text-align: center">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title" id="uploadPlantsWithIndexNumberInfoDialog">Upload Template Information</h4>
            </div>
            <div class="modal-body">
                <div class="container-fluid">
                    <b>This is for recording individual plants in a plot. The plant name will be saved as a concatenation of plot_name + _ + plant_index_number</b>
                    <br/>
                    <b>May be uploaded in an Excel file (.xls or .xlsx)</b>
                    <br />
                    <b>Header:</b>
                    <br>
                    The first row (header) should contain the following:
                    <br />

                    <table class="table table-hover table-bordered table-condensed" >
                        <thead></thead>
                        <tbody>
                            <tr>
                                <td>plot_name</td>
                                <td>plant_index_number</td>
                            </tr>
                        </tbody>
                    </table>

                    <b>Required fields:</b>
                    <br/>
                    - plot_name (must exist in the database already)
                    <br />
                    - plant_index_number (must be a number. the saved plant name will be a concatenation of plot_name + plant_index_number, such as MyTrial_plot101_plant1.)
                    <br>
                    <b>Optional fields:</b>
                    <br>
                    - row_num
                    <br>
                    - col_num
                    <br>
                    Rows and columns are at the plot level if each plot contains multiple plants. If including this data, both fields must be present.
                </div>
            </div>
            <div class="modal-footer">
                <button id="close_upload_plants_with_index_number_info_dialog" type="button" class="btn btn-default" data-dismiss="modal">Close</button>
            </div>
        </div>
    </div>
</div>

<div class="modal fade" id="upload_plants_with_number_of_plants_number_dialog" name="upload_plants_with_number_of_plants_number_dialog" tabindex="-1" role="dialog" aria-labelledby="uploadPlantsWithNumPlantsPerPlotDialog">
    <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="uploadPlantsWithNumPlantsPerPlotDialog">Upload plants to ' );
#line 271 "/home/production/cxgn/sgn/mason/breeders_toolbox/trial/add_plants_per_plot.mas"
$m->print(  $trial_name  );
#line 271 "/home/production/cxgn/sgn/mason/breeders_toolbox/trial/add_plants_per_plot.mas"
$m->print( ' with number of plants per plot</h4>
            </div>
            <div class="modal-body">
                <div class="container-fluid">

                    ' );
#line 276 "/home/production/cxgn/sgn/mason/breeders_toolbox/trial/add_plants_per_plot.mas"
$m->comp( { content => sub {
#line 276 "/home/production/cxgn/sgn/mason/breeders_toolbox/trial/add_plants_per_plot.mas"
$m->print( '
                        <p>
                            <b>File format information</b>
                            <br>
                            <a id="trial_upload_plants_with_num_plants_spreadsheet_info_format">Spreadsheet format</a>
                        </p>
                    ' );
#line 282 "/home/production/cxgn/sgn/mason/breeders_toolbox/trial/add_plants_per_plot.mas"
} }, '/page/explanation.mas', title=>'Template information'
 );
#line 282 "/home/production/cxgn/sgn/mason/breeders_toolbox/trial/add_plants_per_plot.mas"
$m->print( '

                    <form class="form-horizontal" role="form" method="post" enctype="multipart/form-data" encoding="multipart/form-data" id="upload_plants_with_num_plants_dialog_form" name="upload_plants_with_num_plants_dialog_form">
                        <div class="form-group">
                            <label class="col-sm-4 control-label">Upload File (.xls or .xlsx): </label>
                            <div class="col-sm-8" >
                                <input type="file" name="trial_upload_plants_with_number_of_plants_file" id="trial_upload_plants_with_number_of_plants_file" encoding="multipart/form-data" />
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-4 control-label">Maximum number of plants per plot: </label>
                            <div class="col-sm-8" >
                                <input name="upload_plants_with_num_plants_per_plot_number" id="upload_plants_with_num_plants_per_plot_number" class="form-control" type="number" />
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-4 control-label">Inherits Treatment(s) From Plots: </label>
                            <div class="col-sm-8" >
                                <input name="upload_plants_with_num_plants_inherit_treatments" id="upload_plants_with_num_plants_inherit_treatments" type="checkbox" checked disabled/>
                            </div>
                        </div>
                    </form><br/>
                </div>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" name="upload_plants_with_num_plants_cancel_button" id="upload_plants_with_num_plants_cancel_button" data-dismiss="modal">Close</button>
                <button type="button" class="btn btn-primary" name="upload_plants_with_num_plants_save_button" id="upload_plants_with_num_plants_save_button" title="Upload">Upload</button>
            </div>
        </div>
    </div>
</div>

<div class="modal fade" id="upload_plants_with_num_plants_spreadsheet_info_dialog" name="upload_plants_with_num_plants_spreadsheet_info_dialog" tabindex="-1" role="dialog" aria-labelledby="uploadPlantsWithNumPlantsInfoDialog">
    <div class="modal-dialog modal-lg" role="document">
        <div class="modal-content">
            <div class="modal-header" style="text-align: center">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title" id="uploadPlantsWithNumPlantsInfoDialog">Upload Template Information</h4>
            </div>
            <div class="modal-body">
                <div class="container-fluid">
                    <b>This is for recording individual plants in a plot. The plant name will be saved as a concatenation of plot_name + _ + plant_index_number for as many plants as specfied by num_plants_per_plot</b>
                    <br/>
                    <b>May be uploaded in an Excel file (.xls or .xlsx)</b>
                    <br />
                    <b>Header:</b>
                    <br>
                    The first row (header) should contain the following:
                    <br />

                    <table class="table table-hover table-bordered table-condensed" >
                        <thead></thead>
                        <tbody>
                            <tr>
                                <td>plot_name</td>
                                <td>num_plants_per_plot</td>
                            </tr>
                        </tbody>
                    </table>

                    <b>Required fields:</b>
                    <br/>
                    - plot_name (must exist in the database already)
                    <br />
                    - num_plants_per_plot (must be a number. the number of plants in the plot. the saved plant name will be a concatenation of plot_name + plant_number, such as MyTrial_plot101_plant1)
                    <br>
                    <b>Optional fields:</b>
                    <br>
                    - num_rows
                    <br>
                    - num_cols
                    <br>
                    The number of spaces given by the rows and columns should be greater than or equal to the num_plants_per_plot. Plants will be assigned rows and columns in zigzag pattern, starting from (1,1).
                </div>
            </div>
            <div class="modal-footer">
                <button id="close_upload_plants_with_number_plants_info_dialog" type="button" class="btn btn-default" data-dismiss="modal">Close</button>
            </div>
        </div>
    </div>
</div>


<script>

jQuery(document).ready(function() {

    jQuery(\'#create_plant_entries_button\').click( function () {
        jQuery(\'#add_plants_dialog\').modal("show");
    });

    jQuery(\'#upload_plant_entries_button\').click( function () {
        jQuery(\'#upload_plants_dialog\').modal("show");
    });

    jQuery(\'#upload_plant_entries_with_index_number_button\').click( function () {
        jQuery(\'#upload_plants_with_index_number_dialog\').modal("show");
    });

    jQuery(\'#trial_upload_plants_spreadsheet_info_format\').click( function () {
        jQuery(\'#upload_plants_spreadsheet_info_dialog\').modal("show");
    });

    jQuery(\'#trial_upload_plants_with_index_number_spreadsheet_info_format\').click( function () {
        jQuery(\'#upload_plants_with_index_number_spreadsheet_info_dialog\').modal("show");
    });

    jQuery(\'#trial_upload_plants_with_num_plants_button\').click( function () {
        jQuery(\'#upload_plants_with_number_of_plants_number_dialog\').modal("show");
    });

    jQuery(\'#trial_upload_plants_with_num_plants_spreadsheet_info_format\').click( function () {
        jQuery(\'#upload_plants_with_num_plants_spreadsheet_info_dialog\').modal("show");
    });

    jQuery(\'#add_plants_save_button\').click( function () {
        add_plants_to_trial();
    });

    jQuery(\'#upload_plants_save_button\').click( function () {
        upload_plants_to_trial();
    });

    jQuery(\'#upload_plants_with_index_number_save_button\').click( function () {
        upload_plants_with_index_number_to_trial();
    });

    jQuery(\'#upload_plants_with_num_plants_save_button\').click( function () {
        upload_plants_with_num_plants_to_trial();
    });

    jQuery(\'#add_rows_and_columns_to_plants\').click( function () {
        if (jQuery(\'#add_rows_and_columns_to_plants\').is(\':checked\')){
            jQuery(\'#plant_row_column_format_dialog\').show();
        } else {
            jQuery(\'#plant_row_column_format_dialog\').hide();
        }

    });

    function upload_plants_to_trial() {
        var uploadFile = jQuery("#trial_upload_plants_file").val();
        jQuery(\'#upload_plants_dialog_form\').attr("action", "/ajax/breeders/trial/' );
#line 424 "/home/production/cxgn/sgn/mason/breeders_toolbox/trial/add_plants_per_plot.mas"
$m->print(  $trial_id  );
#line 424 "/home/production/cxgn/sgn/mason/breeders_toolbox/trial/add_plants_per_plot.mas"
$m->print( '/upload_plants");
        if (uploadFile === \'\') {
            alert("Please select a file");
            return;
        }
        jQuery("#upload_plants_dialog_form").submit();
    }

    jQuery(\'#upload_plants_dialog_form\').iframePostForm({
        json: true,
        post: function () {
            var uploadedPlantsFile = jQuery("#trial_upload_plants_file").val();
            jQuery(\'#working_modal\').modal("show");
            if (uploadedPlantsFile === \'\') {
                jQuery(\'#working_modal\').modal("hide");
                alert("No file selected");
            }
        },
        complete: function (response) {
            console.log(response);
            jQuery(\'#working_modal\').modal("hide");

            if (response.error_string) {
                alert(response.error_string);
                return;
            }
            if (response.success) {
                alert("File uploaded successfully");
                window.location.replace(\'/breeders/trial/\'+' );
#line 452 "/home/production/cxgn/sgn/mason/breeders_toolbox/trial/add_plants_per_plot.mas"
$m->print(  $trial_id  );
#line 452 "/home/production/cxgn/sgn/mason/breeders_toolbox/trial/add_plants_per_plot.mas"
$m->print( ');
            }
        }
    });

    function upload_plants_with_index_number_to_trial() {
        var uploadFile = jQuery("#trial_upload_plants_with_index_number_file").val();
        jQuery(\'#upload_plants_with_index_number_dialog_form\').attr("action", "/ajax/breeders/trial/' );
#line 459 "/home/production/cxgn/sgn/mason/breeders_toolbox/trial/add_plants_per_plot.mas"
$m->print(  $trial_id  );
#line 459 "/home/production/cxgn/sgn/mason/breeders_toolbox/trial/add_plants_per_plot.mas"
$m->print( '/upload_plants_with_plant_index_number");
        if (uploadFile === \'\') {
            alert("Please select a file");
            return;
        }
        jQuery("#upload_plants_with_index_number_dialog_form").submit();
    }

    jQuery(\'#upload_plants_with_index_number_dialog_form\').iframePostForm({
        json: true,
        post: function () {
            var uploadedPlantsFile = jQuery("#trial_upload_plants_with_index_number_file").val();
            jQuery(\'#working_modal\').modal("show");
            if (uploadedPlantsFile === \'\') {
                jQuery(\'#working_modal\').modal("hide");
                alert("No file selected");
            }
        },
        complete: function (response) {
            console.log(response);
            jQuery(\'#working_modal\').modal("hide");

            if (response.error_string) {
                alert(response.error_string);
                return;
            }
            if (response.success) {
                alert("File uploaded successfully");
                window.location.replace(\'/breeders/trial/\'+' );
#line 487 "/home/production/cxgn/sgn/mason/breeders_toolbox/trial/add_plants_per_plot.mas"
$m->print(  $trial_id  );
#line 487 "/home/production/cxgn/sgn/mason/breeders_toolbox/trial/add_plants_per_plot.mas"
$m->print( ');
            }
        }
    });

    function upload_plants_with_num_plants_to_trial() {
        var uploadFile = jQuery("#trial_upload_plants_with_number_of_plants_file").val();
        jQuery(\'#upload_plants_with_num_plants_dialog_form\').attr("action", "/ajax/breeders/trial/' );
#line 494 "/home/production/cxgn/sgn/mason/breeders_toolbox/trial/add_plants_per_plot.mas"
$m->print(  $trial_id  );
#line 494 "/home/production/cxgn/sgn/mason/breeders_toolbox/trial/add_plants_per_plot.mas"
$m->print( '/upload_plants_with_number_of_plants");
        if (uploadFile === \'\') {
            alert("Please select a file");
            return;
        }
        jQuery("#upload_plants_with_num_plants_dialog_form").submit();
    }

    jQuery(\'#upload_plants_with_num_plants_dialog_form\').iframePostForm({
        json: true,
        post: function () {
            var uploadedPlantsFile = jQuery("#trial_upload_plants_with_number_of_plants_file").val();
            jQuery(\'#working_modal\').modal("show");
            if (uploadedPlantsFile === \'\') {
                jQuery(\'#working_modal\').modal("hide");
                alert("No file selected");
            }
        },
        complete: function (response) {
            console.log(response);
            jQuery(\'#working_modal\').modal("hide");

            if (response.error_string) {
                alert(response.error_string);
                return;
            }
            if (response.success) {
                alert("File uploaded successfully");
                window.location.replace(\'/breeders/trial/\'+' );
#line 522 "/home/production/cxgn/sgn/mason/breeders_toolbox/trial/add_plants_per_plot.mas"
$m->print(  $trial_id  );
#line 522 "/home/production/cxgn/sgn/mason/breeders_toolbox/trial/add_plants_per_plot.mas"
$m->print( ');
            }
        }
    });

});

function add_plants_to_trial() {

    var is_checked;
    if(jQuery(\'#add_plants_per_plot_inherit_treatments\').is(":checked")){
        is_checked = 1;
    }

    var num_rows = jQuery(\'#rows_per_plot\').val();
    var num_cols = jQuery(\'#cols_per_plot\').val();
    var plants_per_plot = jQuery(\'#add_plants_per_plot_num\').val();
    var include_plant_coordinates = 0;

    if (jQuery(\'#add_rows_and_columns_to_plants\').is(\':checked\')) {

        include_plant_coordinates = 1;

        if (num_rows == "" || num_cols == "" || num_rows * num_cols == 0) {
            alert("You need to specify the number of rows and columns to give plant coordinates within plots.");
            return;
        }
        if (num_rows * num_cols < plants_per_plot) {
            alert("Only one plant per (row, column) coordinate is allowed. You must specify fewer plants per plot, or add rows and columns.");
            return;
        }
    }

    jQuery.ajax( {
      url: \'/ajax/breeders/trial/\'+' );
#line 556 "/home/production/cxgn/sgn/mason/breeders_toolbox/trial/add_plants_per_plot.mas"
$m->print(  $trial_id  );
#line 556 "/home/production/cxgn/sgn/mason/breeders_toolbox/trial/add_plants_per_plot.mas"
$m->print( '+\'/create_plant_entries/\',
      type: \'POST\',
      beforeSend: function() {
          enable_working_modal();
      },
      data: {
        \'plants_per_plot\' : plants_per_plot,
        \'inherits_plot_treatments\' : is_checked,
        \'include_plant_coordinates\' : include_plant_coordinates,
        \'rows_per_plot\' : num_rows,
        \'cols_per_plot\' : num_cols
      },
      success: function(response) {
        disable_working_modal();
        if (response.error) {
          alert(response.error);
        }
        else {
          alert("Successfully created plant entries.");
          jQuery(\'#add_plants_dialog\').modal("hide");
          window.location.replace(\'/breeders/trial/\'+' );
#line 576 "/home/production/cxgn/sgn/mason/breeders_toolbox/trial/add_plants_per_plot.mas"
$m->print(  $trial_id  );
#line 576 "/home/production/cxgn/sgn/mason/breeders_toolbox/trial/add_plants_per_plot.mas"
$m->print( ');
        }
      },
      error: function(response) {
        disable_working_modal();
        alert("An error occurred saving plant entries");
      },
    });

}

function enable_working_modal() {
    jQuery("#working_modal").modal("show");
}

function disable_working_modal() {
    jQuery("#working_modal").modal("hide");
}

function enable_plants_datatable() {
    jQuery(\'#trial_plants_table_html\').DataTable();
}

</script>
' );
;return;
},
'declared_args' => {
  '$trial_id' => { default => undef },
  '$trial_name' => { default => ' undef' }
},
'load_time' => 1763102299,

)
;