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

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

#line 6 "/home/production/cxgn/sgn/mason/breeders_toolbox/manage_trial_phenotyping.mas"
$m->print( '
' );
#line 7 "/home/production/cxgn/sgn/mason/breeders_toolbox/manage_trial_phenotyping.mas"
$m->comp(   '/page/page_title.mas', title=>"Manage Phenotyping for $trial_name"   
); #line 7 "/home/production/cxgn/sgn/mason/breeders_toolbox/manage_trial_phenotyping.mas"
$m->print( '
' );
#line 8 "/home/production/cxgn/sgn/mason/breeders_toolbox/manage_trial_phenotyping.mas"
$m->comp(   '/breeders_toolbox/trial/download_phenotypes_dialog.mas', trial_ids => $trial_id   
); #line 8 "/home/production/cxgn/sgn/mason/breeders_toolbox/manage_trial_phenotyping.mas"
$m->print( '

<div class="well well-sm">
  <div class="row">
    <div class="col-md-1 col-lg-1">
    </div>
    <div class="col-md-10 col-lg-10">

        <form class="form-horizontal" role="form" action="/barcode/direct_trial_phenotyping">
            <div class="form-group form-group-sm">
                <label class="col-sm-4 control-label">Plot Name: </label>
                <div class="col-sm-8" id="plot_name_1">

                </div>
            </div>
            <div class="form-group form-group-sm">
                <label id = "manage_phenotyping_stock_type" class="col-sm-4 control-label"></label>
                <div class="col-sm-8" id="accession_name">

                </div>
            </div>
            <div class="form-group form-group-sm">
                <label class="col-sm-4 control-label">Plot No: </label>
                <div class="col-sm-8" id="plot_no">

                </div>
            </div>
            <div class="form-group form-group-sm">
                <label class="col-sm-4 control-label">Block No: </label>
                <div class="col-sm-8" id="block_no">

                </div>
            </div>
            <div class="form-group form-group-sm">
                <label class="col-sm-4 control-label">Rep No: </label>
                <div class="col-sm-8" id="rep_no">

                </div>
            </div>

    </div>
  <div class="col-md-1 col-lg-1">
  </div>
  </div>
</div>


<div class="well well-sm">
  <div class="row">
    <div class="col-md-1 col-lg-1">
    </div>
    <div class="col-md-10 col-lg-10">

        <div class="form-group form-group-sm" id="all_traits">
          <label class="col-sm-4 control-label" for="select_traits_for_trait_file">Select trait: </label>
          <div class="col-sm-8">
            <select class="form-control" id="select_traits_for_trait_file"></select>
          </div>
        </div>

        <div class="form-group form-group-sm">
          <label class="col-sm-4 control-label">Or Use Trait List: </label>
            <div class="col-sm-8">
              <input type="checkbox"  id="use_trait_list" value="use_trait_list"/>
          </div>
        </div>

        <br />

        <div id="show_trait_textbox" style="display: none">
          <div class="form-group form-group-sm" >
              <label class="col-sm-4 control-label">Enter a List of Trait Names: </label>
              <div class="col-sm-8" id="show_trait_selectbox">

              </div>
          </div>
          <br /><br />
        </div>

        <div id="show_trait_list_box" style="display: none">
            <div class="form-group form-group-sm">
              <label class="col-sm-4 control-label">Or Paste From a List: </label>
              <div class="col-sm-8">
                  <div id="list_menu_traits"></div>
                  <script defer="defer">
                    jQuery(document).ready(function() {
                        pasteTraitListMenu(\'show_trait_selectbox\', \'list_menu_traits\', \'Paste Trait List\');

                        function pasteTraitListMenu (div_name, menu_div, button_name) {
                            var list = new CXGN.List();
                            var html=\'\';
                            html = list.listSelect(div_name, [\'traits\'], undefined, undefined, undefined);
                            html = html + \'<button class="btn btn-info btn-sm" type="button" id="paste_button_id" value="\'+button_name+\'" onclick="javascript:pasteTraitList(\\\'\'+div_name+\'\\\')" >\'+button_name+\'</button>\';
                            jQuery(\'#\'+menu_div).html(html);
                        }

                    });
                  </script>
              </div>
            </div>
        </div>
        <br /><br />
        <div class="form-group form-group-sm" id = "new_pheno_input" style="display: none">
            <label class="col-sm-4 control-label">Enter trait value: </label>
            <div class="col-sm-3">
                <input type="number" class="form-control" id="select_pheno_value" name="select_pheno_value"></input>
            </div>
            <div class="col-sm-5">
              <div id="loading-trial-phenotype" style="display: none"></div>
              <div id="success-trial-phenotype" style="display: none">
                <span class="glyphicon glyphicon-ok" style="color: #A9AE00; font-size: 150%"></span>
              </div>
              <div id="error-trial-phenotype" style="display: none">
                <span class="glyphicon glyphicon-remove-sign" style="color: #AE1000; font-size: 150%"></span>
              </div>
            </div>
        </div>
        <div class="form-group form-group-sm" id = "stored_pheno_input" style="display: none">
            <label class="col-sm-4 control-label">Stored trait value: </label>
            <div class="col-sm-3">
                <input class="form-control" name="stored_pheno_value" id="stored_pheno_value" disabled ></input>
            </div>
        </div>
    </div>
    <div class="col-md-1 col-lg-1">
    </div>
  </div>
</div>

</form>
<!--<div id="main" class="container">
    <div id="virtualKeyboard"></div>
    <hr>
</div>-->
' );
#line 142 "/home/production/cxgn/sgn/mason/breeders_toolbox/manage_trial_phenotyping.mas"
$m->comp( { content => sub {
#line 142 "/home/production/cxgn/sgn/mason/breeders_toolbox/manage_trial_phenotyping.mas"
$m->print( '

    ' );
#line 144 "/home/production/cxgn/sgn/mason/breeders_toolbox/manage_trial_phenotyping.mas"
$m->comp(   '/breeders_toolbox/trial/phenotype_summary.mas', trial_id => $trial_id, trial_stock_type => $trial_stock_type   
); #line 144 "/home/production/cxgn/sgn/mason/breeders_toolbox/manage_trial_phenotyping.mas"
$m->print( '


' );
#line 147 "/home/production/cxgn/sgn/mason/breeders_toolbox/manage_trial_phenotyping.mas"
} }, '/page/info_section.mas', id=> "trial_detail_traits_assayed", title => "Traits assayed", collapsible=>1, collapsed=>1, hide_if_empty=>1, subtitle=>"[<a id='trial_download_phenotypes_button'>Download Trial Data</a>]"
 );
#line 147 "/home/production/cxgn/sgn/mason/breeders_toolbox/manage_trial_phenotyping.mas"
$m->print( '

<script>

var trial_info_object = [];

  jQuery(document).ready(function($) {

      var  trial_id = ' );
#line 155 "/home/production/cxgn/sgn/mason/breeders_toolbox/manage_trial_phenotyping.mas"
$m->print(  $trial_id  );
#line 155 "/home/production/cxgn/sgn/mason/breeders_toolbox/manage_trial_phenotyping.mas"
$m->print( ';

      new jQuery.ajax( {
           type: \'POST\',
           url: \'/ajax/breeders/trial_phenotyping_info\',
           dataType: "json",
           data: {
            \'trial_id\' : trial_id,
           },

           success: function(response) {
                trial_info_object = response.trial_info;
               if (response.error){
                 alert("Error Retrieving Trial Information: "+response.error);
               }

               var trial_plot_name_html = "<select class=\'form-control\' id=\'plot_name\' >";
               var trial_accession_html = "<select class=\'form-control\' id=\'trial_accession_table\' disabled>";
               var trial_plot_number_html = "<select class=\'form-control\' id=\'trial_plot_number_table\'>";
               var trial_block_number_html = "<select class=\'form-control\' id=\'trial_block_number_table\' disabled>";
               var trial_rep_number_html = "<select class=\'form-control\' id=\'trial_rep_number_table\' disabled>";

                for (n=0; n<response.trial_info.length; n++){
                //console.log(response.trial_info[n]);

                      trial_plot_name_html = trial_plot_name_html + "<option value=" + response.trial_info[n].plot_name + ">" + response.trial_info[n].plot_name + "</option>";
                      trial_accession_html = trial_accession_html + "<option value=" + response.trial_info[n].accession_name + ">" + response.trial_info[n].accession_name + "</option>";
                      trial_plot_number_html = trial_plot_number_html + "<option value=" + response.trial_info[n].plot_number + ">" + response.trial_info[n].plot_number + "</option>";
                      trial_block_number_html = trial_block_number_html + "<option value=" + response.trial_info[n].block_number + ">" + response.trial_info[n].block_number + "</option>";
                      trial_rep_number_html = trial_rep_number_html + "<option value=" + response.trial_info[n].rep_number + ">" + response.trial_info[n].rep_number + "</option>";

                  }
                  trial_plot_name_html = trial_plot_name_html + "</select>";
                  jQuery(\'#plot_name_1\').empty();
                  jQuery(\'#plot_name_1\').html(trial_plot_name_html);

                  trial_accession_html = trial_accession_html + "</select>";
                  jQuery(\'#accession_name\').empty();
                  jQuery(\'#accession_name\').html(trial_accession_html);

                  trial_plot_number_html = trial_plot_number_html + "</select>";
                  jQuery(\'#plot_no\').empty();
                  jQuery(\'#plot_no\').html(trial_plot_number_html);

                  trial_block_number_html = trial_block_number_html + "</select>";
                  jQuery(\'#block_no\').empty();
                  jQuery(\'#block_no\').html(trial_block_number_html);

                  trial_rep_number_html = trial_rep_number_html + "</select>";
                  jQuery(\'#rep_no\').empty();
                  jQuery(\'#rep_no\').html(trial_rep_number_html);

              },
              error: function() {
                alert(\'An error occurred retrieving trial information\');
              }

      });

  var null_trait_value = \'\';

  $("#use_trait_list").click(function () {
    if ($(\'#use_trait_list\').is(\':checked\')) {
      $(\'#all_traits\').hide();
      jQuery(\'#select_traits_for_trait_file\').empty();
      $(\'#show_trait_textbox\').show();
      $(\'#show_trait_list_box\').show();
      jQuery("#select_pheno_value").val(null_trait_value);
    }
    else {
        $(\'#all_traits\').show();
        $(\'#show_trait_textbox\').hide();
        $(\'#show_trait_list_box\').hide();
        jQuery(\'#select_traits_for_trait_file_2\').empty();
        jQuery("#select_pheno_value").val(null_trait_value);
        jQuery(\'#select_pheno_value\').empty();
        get_select_box(\'traits\', \'select_traits_for_trait_file\', {
            \'name\': \'html_select_traits_for_trait_file\',
            \'id\': \'html_select_traits_for_trait_file\',
            \'empty\': 1
        });
    }
  });

    get_select_box(\'traits\', \'select_traits_for_trait_file\', {
        \'name\': \'html_select_traits_for_trait_file\',
        \'id\': \'html_select_traits_for_trait_file\',
        \'empty\': 1
    });

    var plot_focusin;
    var trait_focusin;
    var trait_list_option_focusin;
    jQuery( "#select_pheno_value" ).focusin(function() {
        jQuery("#success-trial-phenotype").hide();
        jQuery("#error-trial-phenotype").hide();
        jQuery("#loading-trial-phenotype").hide();
        plot_focusin = jQuery("#plot_name").val();
        trait_focusin = jQuery("#select_traits_for_trait_file").val();
        //var trait_list_option = \'\';
        if (jQuery(\'#use_trait_list\').is(\':checked\')) {
           //trait_list_option = jQuery(\'#use_trait_list\').val();
           trait_list_option_focusin = jQuery(\'#use_trait_list\').val();
        }
        if (trait_focusin === null){
          trait_focusin = jQuery("#select_traits_for_trait_file_2").val();
        }
        console.log(plot_focusin +" and "+trait_focusin);
    });

    jQuery( "#select_pheno_value" ).focusout(function() {
    //jQuery(\'input[name=select_pheno_value]\').change(function() {
      var trait_value = jQuery("#select_pheno_value").val();
      var plot_name = plot_focusin;
      var trait = trait_focusin;
      var trait_list_option = trait_list_option_focusin;

      jQuery("#success-trial-phenotype").hide();
      jQuery("#error-trial-phenotype").hide();
      jQuery("#loading-trial-phenotype").show();
      new jQuery.ajax ( {
        type: \'POST\',
        url : \'/ajax/phenotype/plot_phenotype_upload\',
        dataType: "json",
        data: {
                \'plot_name\' : plot_name,
                \'trait\' : trait,
                \'trait_value\' : trait_value,
                \'trait_list_option\' : trait_list_option,
                \'trial_id\' : trial_id
        },

        success: function (response) {
          jQuery("#loading-trial-phenotype").hide();
          if (response.error){
            alert("Error Saving Trait Value: "+response.error);
            jQuery("#error-trial-phenotype").show();
          }
          else {
            jQuery("#success-trial-phenotype").show();
          }
        },
          error: function() {
            alert(\'An error occurred saving trait value\');
            jQuery("#loading-trial-phenotype").hide();
            jQuery("#error-trial-phenotype").show();
          },

      });

    });

    function Retrieve_pheno(){
        var plot_name = jQuery("#plot_name").val();
        var trait = \'\';
        trait = jQuery("#select_traits_for_trait_file").val();
        if (trait === null){
            trait = jQuery("#select_traits_for_trait_file_2").val();
        }

        var trait_list_option = \'\';
        if ($(\'#use_trait_list\').is(\':checked\')) {
           trait_list_option = jQuery(\'#use_trait_list\').val();
        }

        new jQuery.ajax ( {
            type: \'POST\',
            url : \'/ajax/phenotype/plot_phenotype_retrieve\',
            dataType: "json",
            data: {
                \'plot_name\' : plot_name,
                \'trait\' : trait,
                \'trait_list_option\' : trait_list_option,
            },
            success: function (response) {
                var value = response.trait_value;
                var red = {\'color\': \'red\'};
                if (response.error){
                    alert("Error Retrieving Trait Value: "+response.error);
                } else if (value) {
                    jQuery(\'#new_pheno_input\').hide();
                    jQuery("#stored_pheno_value").css(red);
                    jQuery(\'#stored_pheno_input\').show();
                    jQuery("#stored_pheno_value").val(value);
                } else if ((trait || trait_list_option) && !value) {
                    jQuery(\'#stored_pheno_input\').hide();
                    jQuery("#select_pheno_value").val(null_trait_value);
                    jQuery(\'#select_pheno_value\').empty();
                    jQuery(\'#new_pheno_input\').show();
                }
            },
            error: function() {
                alert(\'An error occurred retrieving trait value\');
            }
        });
    }

    jQuery(document).on(\'change\', \'#select_traits_for_trait_file_2\', function(){
        jQuery("#select_traits_for_trait_file").empty();
        Retrieve_pheno();
    });

    jQuery("#select_traits_for_trait_file").on(\'change\', function() {
        jQuery("#select_traits_for_trait_file_2").empty();
        Retrieve_pheno();
    });

  jQuery(document).on(\'change\', \'#plot_name\', function(){
      var plot_infor = jQuery(\'#plot_name\').val();
      for (i=0; i<trial_info_object.length; i++){
          if (trial_info_object[i].plot_name == plot_infor){
              var plotNo = trial_info_object[i].plot_number;
              var accessionName = trial_info_object[i].accession_name;
              var blockNo = trial_info_object[i].block_number;
              var repNo = trial_info_object[i].rep_number;

              jQuery(\'#trial_accession_table\').val(accessionName);
              jQuery(\'#trial_plot_number_table\').val(plotNo);
              jQuery(\'#trial_block_number_table\').val(blockNo);
              jQuery(\'#trial_rep_number_table\').val(repNo);
              Retrieve_pheno();
          }
      }

  });

  jQuery(document).on(\'change\', \'#trial_plot_number_table\', function(){
      var plot_infor = jQuery(\'#trial_plot_number_table\').val();
      for (i=0; i<trial_info_object.length; i++){
          if (trial_info_object[i].plot_number == plot_infor){
              var accessionName = trial_info_object[i].accession_name;
              var plotName = trial_info_object[i].plot_name;
              var blockNo = trial_info_object[i].block_number;
              var repNo = trial_info_object[i].rep_number;

              jQuery(\'#plot_name\').val(plotName);
              jQuery(\'#trial_accession_table\').val(accessionName);
              jQuery(\'#trial_block_number_table\').val(blockNo);
              jQuery(\'#trial_rep_number_table\').val(repNo);
              Retrieve_pheno();
          }
      }

  });

    var trial_stock_type = "' );
#line 400 "/home/production/cxgn/sgn/mason/breeders_toolbox/manage_trial_phenotyping.mas"
$m->print(  $trial_stock_type  );
#line 400 "/home/production/cxgn/sgn/mason/breeders_toolbox/manage_trial_phenotyping.mas"
$m->print( '";
    var manage_phenotyping_label = \'\';

    if (trial_stock_type == \'family_name\') {
        manage_phenotyping_label = \'Family Name :\';
    } else if (trial_stock_type == \'cross\') {
        manage_phenotyping_label = \'Cross Unique ID :\';
    } else {
        manage_phenotyping_label = \'Accession Name :\';
    }

    jQuery(\'#manage_phenotyping_stock_type\').text(manage_phenotyping_label);

});
</script>

<style>
  #loading-trial-phenotype {
    color: #A9AE00
  }
  #loading-trial-phenotype,
  #loading-trial-phenotype:after {
    box-sizing: border-box;
  }
  #loading-trial-phenotype {
    display: inline-block;
    width: 40px;
    height: 40px;
  }
  #loading-trial-phenotype:after {
    content: " ";
    display: block;
    width: 28px;
    height: 28px;
    margin: 0px;
    border-radius: 50%;
    border: 3.2px solid currentColor;
    border-color: currentColor transparent currentColor transparent;
    animation: loading-trial-phenotype 1.2s linear infinite;
  }
  @keyframes loading-trial-phenotype {
    0% {
      transform: rotate(0deg);
    }
    100% {
      transform: rotate(360deg);
    }
  }
</style>
' );
;return;
},
'declared_args' => {
  '$trial_id' => { default => undef },
  '$trial_name' => { default => undef },
  '$trial_stock_type' => { default => ' undef' }
},
'load_time' => 1763641490,

)
;