package SGN::View::Mason::Commands;
use strict;
use vars qw($m $c);
#line 34 "/home/production/cxgn/sgn/mason/chado/cvterm.mas"

use CXGN::Page::FormattingHelpers qw/
 info_section_html
 page_title_html
 columnar_table_html
/;
use CXGN::Phenome::Qtl::Tools;
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 ( $cvterm, $cvtermref );
{
    my %pos;
    for ( my $x = 0; $x < @_; $x += 2 )
    {
        $pos{ $_[$x] } = $x + 1;
    }

    foreach my $arg ( qw( cvterm cvtermref ) )
    {
        HTML::Mason::Exception::Params->throw
            ( error => "no value sent for required parameter '$arg'" )
                unless exists $pos{$arg};
    }
#line 30 "/home/production/cxgn/sgn/mason/chado/cvterm.mas"
    $cvterm = $_[ $pos{'cvterm'} ];
#line 31 "/home/production/cxgn/sgn/mason/chado/cvterm.mas"
    $cvtermref = $_[ $pos{'cvtermref'} ];
}
$m->debug_hook( $m->current_comp->path ) if ( HTML::Mason::Compiler::IN_PERL_DB() );

#line 28 "/home/production/cxgn/sgn/mason/chado/cvterm.mas"
$m->print( '
' );
#line 33 "/home/production/cxgn/sgn/mason/chado/cvterm.mas"
$m->print( '
' );
#line 42 "/home/production/cxgn/sgn/mason/chado/cvterm.mas"
$m->print( '
' );
#line 43 "/home/production/cxgn/sgn/mason/chado/cvterm.mas"


my $cvterm_id   = $cvterm->cvterm_id;
my $db_name     = $cvterm->db->name;
my $accession   = $cvterm->accession;
my $cvterm_name = $cvterm->name;
my $definition  = $cvterm->definition;
my $is_variable = $cvterm->is_variable;
my $comment     = '' ;#$cvterm->comment;
#$stockref->{props} (hash of arrayrefs of cvtermprops. Keys = prop name, value = prop value)
my $editable_cvterm_props_string = $cvtermref->{editable_cvterm_props};
my @editable_cvterm_props = split "," , $editable_cvterm_props_string;


my $is_obsolete = $cvterm->is_obsolete();
my @synonyms    = $cvterm->synonyms();
my @def_dbxrefs = $cvterm->def_dbxrefs();
my @secondary_dbxrefs = $cvterm->secondary_dbxrefs();
my @image_ids = $cvterm->get_image_ids;

my $curator   = $cvtermref->{curator};
my $submitter = $cvtermref->{submitter};
my $sequencer = $cvtermref->{sequencer};
my $cvtermprops = $cvtermref->{props};


my @def_accessions;
if ( scalar (@def_dbxrefs ) > 0 ) {
  # @def_accessions = map( $_->db->name . ":" . $_->accession , @def_dbxrefs);
}

my @secondary_accessions = ();
foreach ( @secondary_dbxrefs) {
  my $db_name =       $_->db->name;
  my $acc =           $_->accession;
  my $urlprefix=      $_->db->urlprefix;
  my $url =           $_->db->url;
  my $full_acc =      $db_name . ":" . $acc;
  my $link = $full_acc;
  if ( $url ) {
    my $xref_link = $urlprefix . $url . $acc;
    $link = qq | <a href="$xref_link">$full_acc</a> |
  }
  push @secondary_accessions , $link ;
}

my @qtl_pops = CXGN::Phenome::Qtl::Tools->new()->is_from_qtl( $cvterm_id );
my @qtl_data;

if ( @qtl_pops )
 {
    foreach my $pop (@qtl_pops)
    {
      my $pop_id   = $pop->get_population_id();
      my $name     = $pop->get_name();
      my $desc     = $pop->get_description();
      my $qtl_link = qq | <a href="/phenome/qtl_analysis.pl?population_id=$pop_id&amp;cvterm_id=$cvterm_id" onClick="Qtl.waitPage()">$name</a> |;
      push @qtl_data, [ $qtl_link, $desc ];
    }
 }

my $this_page = "/cvterm/$cvterm_id/view/";
my $image_subtitle =
   " <a href=\"/image/add?type_id=$cvterm_id&type=cvterm&refering_page=$this_page\">[Add image]</a>" ;


my $edit_privs = $curator ;

#line 112 "/home/production/cxgn/sgn/mason/chado/cvterm.mas"
$m->print( '

' );
#line 114 "/home/production/cxgn/sgn/mason/chado/cvterm.mas"
$m->comp(   '/util/import_javascript.mas', classes => [qw [CXGN.AJAX.Ontology  CXGN.Phenome.Qtl thickbox jquery  jquery.dataTables] ]   
); #line 114 "/home/production/cxgn/sgn/mason/chado/cvterm.mas"
$m->print( '


<script language="javascript">
  function recursiveAnnotations( a ) {
      jQuery.ajax( { url:      a.url+"?cvterm_id=' );
#line 119 "/home/production/cxgn/sgn/mason/chado/cvterm.mas"
$m->print(  $cvterm_id  );
#line 119 "/home/production/cxgn/sgn/mason/chado/cvterm.mas"
$m->print( '" ,
                     dataType: "json",
                     success: function(response) {
                              //jQuery("#"+a.content_id).html(response.html);
                              jQuery("#"+a.count_id).html( response.count + \' \' + a.inflect[ response.count == 1 ? 0 : 1 ]);
                       if( response.error )  {
                             alert(response.error);
                      }
                     }
                  });
  }
</script>


' );
#line 133 "/home/production/cxgn/sgn/mason/chado/cvterm.mas"
$m->comp(   '/page/page_title.mas', title=> "$accession '$cvterm_name' "   
); #line 133 "/home/production/cxgn/sgn/mason/chado/cvterm.mas"
$m->print( '


' );
#line 136 "/home/production/cxgn/sgn/mason/chado/cvterm.mas"
$m->comp( { content => sub {
#line 136 "/home/production/cxgn/sgn/mason/chado/cvterm.mas"
$m->print( '
<table>
<tr><td>Term id</td><td><b>' );
#line 138 "/home/production/cxgn/sgn/mason/chado/cvterm.mas"
$m->print(  $accession  );
#line 138 "/home/production/cxgn/sgn/mason/chado/cvterm.mas"
$m->print( '</b></td></tr>
<tr><td>Term name</td><td><b>' );
#line 139 "/home/production/cxgn/sgn/mason/chado/cvterm.mas"
$m->print(  $cvterm_name  );
#line 139 "/home/production/cxgn/sgn/mason/chado/cvterm.mas"
$m->print( '</b></td></tr>
<tr><td>Term definition</td><td><b>' );
#line 140 "/home/production/cxgn/sgn/mason/chado/cvterm.mas"
$m->print(  $definition  );
#line 140 "/home/production/cxgn/sgn/mason/chado/cvterm.mas"
$m->print( '</b></td></tr>
<tr><td>Comment</td><td><b>' );
#line 141 "/home/production/cxgn/sgn/mason/chado/cvterm.mas"
$m->print(  $comment  );
#line 141 "/home/production/cxgn/sgn/mason/chado/cvterm.mas"
$m->print( '</b></td></tr>
</table>

' );
#line 144 "/home/production/cxgn/sgn/mason/chado/cvterm.mas"
 if ($is_obsolete) {
$m->print( '<b>Obsolete:</b> TRUE <br />
' );
#line 146 "/home/production/cxgn/sgn/mason/chado/cvterm.mas"
 }
$m->print( '
<br /><b>Synonyms</b><br />
' );
#line 149 "/home/production/cxgn/sgn/mason/chado/cvterm.mas"
 foreach my $synonym (@synonyms) {
$m->print(  $synonym  );
#line 150 "/home/production/cxgn/sgn/mason/chado/cvterm.mas"
$m->print( ' <br />
' );
#line 151 "/home/production/cxgn/sgn/mason/chado/cvterm.mas"
 }
$m->print( '
<br /><b> Definition dbxrefs</b><br />
' );
#line 154 "/home/production/cxgn/sgn/mason/chado/cvterm.mas"
 foreach my $da (@def_accessions) {
$m->print(  $da  );
#line 155 "/home/production/cxgn/sgn/mason/chado/cvterm.mas"
$m->print( '<br />
' );
#line 156 "/home/production/cxgn/sgn/mason/chado/cvterm.mas"
 }
$m->print( '
<br /><b> Related dbxrefs</b><br />
' );
#line 159 "/home/production/cxgn/sgn/mason/chado/cvterm.mas"
 foreach my $sa (@secondary_accessions) {
$m->print(  $sa  );
#line 160 "/home/production/cxgn/sgn/mason/chado/cvterm.mas"
$m->print( '<br />
' );
#line 161 "/home/production/cxgn/sgn/mason/chado/cvterm.mas"
  }
$m->print( '
' );
#line 163 "/home/production/cxgn/sgn/mason/chado/cvterm.mas"
} }, '/page/info_section.mas', title=>"Cvterm details"
 );
#line 163 "/home/production/cxgn/sgn/mason/chado/cvterm.mas"
$m->print( '
<br />


' );
#line 167 "/home/production/cxgn/sgn/mason/chado/cvterm.mas"
 my $props_subtitle = $edit_privs ? "[<a id=\"cvterm_add_props\" href=\"javascript:cvtermprops_addPropDialog()\">Add...</a>]" : "[Add]";
$m->print( '
' );
#line 169 "/home/production/cxgn/sgn/mason/chado/cvterm.mas"
 if ($is_variable) { 
$m->comp( { content => sub {
#line 170 "/home/production/cxgn/sgn/mason/chado/cvterm.mas"
$m->print( '
      ' );
#line 171 "/home/production/cxgn/sgn/mason/chado/cvterm.mas"
$m->comp(   '/chado/cvtermprops.mas',
       cv_name    => 'trait_property',
       cvterm_id  =>$cvterm_id,
       props      => $cvtermprops,
        div_name   => 'cvtermprops',
	edit_privs => $edit_privs,
	subset     => \@editable_cvterm_props,
	editable   => \@editable_cvterm_props    
); #line 178 "/home/production/cxgn/sgn/mason/chado/cvterm.mas"
$m->print( '
' );
#line 179 "/home/production/cxgn/sgn/mason/chado/cvterm.mas"
} }, '/page/info_section.mas', title => "Variable Properties" , collapsible=> 1, is_subsection => 1, subtitle=>$props_subtitle
 );
#line 179 "/home/production/cxgn/sgn/mason/chado/cvterm.mas"
$m->print( '

' );
#line 181 "/home/production/cxgn/sgn/mason/chado/cvterm.mas"
 }
 else {
$m->print( '

' );
#line 185 "/home/production/cxgn/sgn/mason/chado/cvterm.mas"
}
$m->print( '
<div id="cvterm_id" style="display:none" >' );
#line 187 "/home/production/cxgn/sgn/mason/chado/cvterm.mas"
$m->print(  $cvterm_name  );
#line 187 "/home/production/cxgn/sgn/mason/chado/cvterm.mas"
$m->print( '|' );
#line 187 "/home/production/cxgn/sgn/mason/chado/cvterm.mas"
$m->print(  $accession  );
#line 187 "/home/production/cxgn/sgn/mason/chado/cvterm.mas"
$m->print( '</div>

' );
#line 189 "/home/production/cxgn/sgn/mason/chado/cvterm.mas"
$m->comp( { content => sub {
#line 189 "/home/production/cxgn/sgn/mason/chado/cvterm.mas"
$m->print( '
<div id="paste_to_list">
LOAD...
</div>

' );
#line 194 "/home/production/cxgn/sgn/mason/chado/cvterm.mas"
} }, '/page/info_section.mas', title=>"Add this term to a list", collapsible=>1, collapsed=>1
 );
#line 194 "/home/production/cxgn/sgn/mason/chado/cvterm.mas"
$m->print( '
<script>

  if (isLoggedIn()) { 
    addToListMenu(\'paste_to_list\', \'cvterm_id\', { listType: \'traits\' } );
  }
  else { 
    jQuery(\'#paste_to_list\').html("&nbsp;Please log in to use lists.");
  }
  
</script>

<br />


' );
#line 209 "/home/production/cxgn/sgn/mason/chado/cvterm.mas"
$m->comp(   '/ontology/embedded_browser.mas', cvterm => $cvterm   
); #line 209 "/home/production/cxgn/sgn/mason/chado/cvterm.mas"
$m->print( '



' );
#line 213 "/home/production/cxgn/sgn/mason/chado/cvterm.mas"
$m->comp( { content => sub {
#line 218 "/home/production/cxgn/sgn/mason/chado/cvterm.mas"
$m->print( '

<table id="loci_data" class="display">
<thead>
  <tr>
    <th>Organism</th>
    <th>Locus symbol</th>
    <th>Locus name</th>
  </tr>
</thead>

</table>

<script>

  jQuery(document).ready(function () {
  
    jQuery(\'#loci_data\').DataTable( { 
      \'ajax\': \'/cvterm/\'+ ' );
#line 236 "/home/production/cxgn/sgn/mason/chado/cvterm.mas"
$m->print(  $cvterm_id  );
#line 236 "/home/production/cxgn/sgn/mason/chado/cvterm.mas"
$m->print( ' + \'/datatables/annotated_loci\',
     });
  });

</script>


' );
#line 243 "/home/production/cxgn/sgn/mason/chado/cvterm.mas"
} }, '/page/info_section.mas',
    title=> "Annotated loci",
    subtitle => '',
    collapsible => 1,
    collapsed   => 1,
 );
#line 243 "/home/production/cxgn/sgn/mason/chado/cvterm.mas"
$m->print( '



' );
#line 247 "/home/production/cxgn/sgn/mason/chado/cvterm.mas"
$m->comp( { content => sub {
#line 253 "/home/production/cxgn/sgn/mason/chado/cvterm.mas"
$m->print( '

<table id="annotated_stocks_data" class="display">
<thead>
  <tr>
     <th>Type</th>
    <th>Stock name</th>
    <th>Description</th>
  </tr>
</thead>

</table>

<script>

  jQuery(document).ready(function () {
  
    jQuery(\'#annotated_stocks_data\').DataTable( { 
      \'ajax\': \'/cvterm/\'+ ' );
#line 271 "/home/production/cxgn/sgn/mason/chado/cvterm.mas"
$m->print(  $cvterm_id  );
#line 271 "/home/production/cxgn/sgn/mason/chado/cvterm.mas"
$m->print( ' + \'/datatables/annotated_stocks\',
     });
  });

</script>


' );
#line 278 "/home/production/cxgn/sgn/mason/chado/cvterm.mas"
} }, '/page/info_section.mas',
       title=> "Annotated stocks",
       collapsible => 1,
       collapsed=>1,
       subtitle => '',
       hide_if_empty => 1,
 );
#line 278 "/home/production/cxgn/sgn/mason/chado/cvterm.mas"
$m->print( '



' );
#line 282 "/home/production/cxgn/sgn/mason/chado/cvterm.mas"
 if ( @qtl_pops )
 {
$m->print( '    ' );
#line 284 "/home/production/cxgn/sgn/mason/chado/cvterm.mas"
$m->comp( { content => sub {
#line 287 "/home/production/cxgn/sgn/mason/chado/cvterm.mas"
$m->print( '
     ' );
#line 288 "/home/production/cxgn/sgn/mason/chado/cvterm.mas"
$m->comp(   '/page/columnar_table.mas',
        headings     => ["Analyze QTL in population", "Population description"], 
        data         => \@qtl_data,
        __alt_freq   => 2,
        __align      =>'l',
       
); #line 293 "/home/production/cxgn/sgn/mason/chado/cvterm.mas"
$m->print( '
  ' );
#line 294 "/home/production/cxgn/sgn/mason/chado/cvterm.mas"
} }, '/page/info_section.mas',
        title       => "QTL analysis",
        collapsible => 1,
 );
#line 294 "/home/production/cxgn/sgn/mason/chado/cvterm.mas"
$m->print( '
' );
#line 295 "/home/production/cxgn/sgn/mason/chado/cvterm.mas"
 }
$m->print( '


' );
#line 299 "/home/production/cxgn/sgn/mason/chado/cvterm.mas"
$m->comp( { content => sub {
#line 304 "/home/production/cxgn/sgn/mason/chado/cvterm.mas"
$m->print( '


<table id="phen_stocks_data" class="display">
<thead>
  <tr>
     <th>Type</th>
    <th>Stock name</th>
    <th>Description</th>
  </tr>
</thead>

</table>

<script>

  jQuery(document).ready(function () {
  
    jQuery(\'#phen_stocks_data\').DataTable( { 
      \'ajax\': \'/cvterm/\'+ ' );
#line 323 "/home/production/cxgn/sgn/mason/chado/cvterm.mas"
$m->print(  $cvterm_id  );
#line 323 "/home/production/cxgn/sgn/mason/chado/cvterm.mas"
$m->print( ' + \'/datatables/phenotyped_stocks\',
     });
  });

</script>


' );
#line 330 "/home/production/cxgn/sgn/mason/chado/cvterm.mas"
} }, '/page/info_section.mas',
      title       => "Phenotyped accessions",
      collapsible => 1,
      collapsed=>1,
      subtitle    => '' ,
 );
#line 330 "/home/production/cxgn/sgn/mason/chado/cvterm.mas"
$m->print( '



' );
#line 334 "/home/production/cxgn/sgn/mason/chado/cvterm.mas"
$m->comp( { content => sub {
#line 339 "/home/production/cxgn/sgn/mason/chado/cvterm.mas"
$m->print( '

<script language="javascript">
    recursiveAnnotations({
                         url:        "/cvterm/"+' );
#line 343 "/home/production/cxgn/sgn/mason/chado/cvterm.mas"
$m->print(  $cvterm_id  );
#line 343 "/home/production/cxgn/sgn/mason/chado/cvterm.mas"
$m->print( '+"/datatables/direct_trials",
                         content_id: "trial_div",
                         count_id:   "trial_count",
                         inflect:    [ \'trial\', \'trials\' ],
                       });
</script>



<table id="trial_data" class="display">
<thead>
  <tr>
     <th>Trial name</th>
     <th>Description</th>
  </tr>
</thead>

</table>

<script>

  jQuery(document).ready(function () {
  
    jQuery(\'#trial_data\').DataTable( { 
      \'ajax\': \'/cvterm/\'+ ' );
#line 367 "/home/production/cxgn/sgn/mason/chado/cvterm.mas"
$m->print(  $cvterm_id  );
#line 367 "/home/production/cxgn/sgn/mason/chado/cvterm.mas"
$m->print( ' + \'/datatables/direct_trials\',
       }
     );
  });

</script>

' );
#line 374 "/home/production/cxgn/sgn/mason/chado/cvterm.mas"
} }, '/page/info_section.mas',
      title       => "Phenotyping trials",
      collapsible => 1,
      collapsed=>1,
      subtitle    => '<span id="trial_count"></span>',
 );
#line 374 "/home/production/cxgn/sgn/mason/chado/cvterm.mas"
$m->print( '

' );
#line 376 "/home/production/cxgn/sgn/mason/chado/cvterm.mas"
$m->comp( { content => sub {
#line 382 "/home/production/cxgn/sgn/mason/chado/cvterm.mas"
$m->print( '

' );
#line 384 "/home/production/cxgn/sgn/mason/chado/cvterm.mas"
$m->comp(   '/image/print_images.mas', images => \@image_ids   
); #line 384 "/home/production/cxgn/sgn/mason/chado/cvterm.mas"
$m->print( '

' );
#line 386 "/home/production/cxgn/sgn/mason/chado/cvterm.mas"
} }, '/page/info_section.mas', 
    title => "Images and figures",
    subtitle      => $image_subtitle,
    collapsible   => 1,
    collapsed     => 0,
    hide_if_empty => 1,
 );
#line 386 "/home/production/cxgn/sgn/mason/chado/cvterm.mas"
$m->print( '

' );
#line 388 "/home/production/cxgn/sgn/mason/chado/cvterm.mas"
$m->comp(   '/qtl/waitmessage.mas'  
); #line 388 "/home/production/cxgn/sgn/mason/chado/cvterm.mas"
$m->print( '
' );
;return;
},
'declared_args' => {
  '$cvterm' => { default => undef },
  '$cvtermref' => { default => undef }
},
'load_time' => 1763079580,

)
;