« blib/lib/Bio/Graphics/Browser2/Render/HTML/TrackListing/Categories.pm
↑ Summary
blib/lib/Bio/Graphics/Browser2/DataLoader/bed.pm »
| 1 | package Bio::Graphics::Browser2::Render::HTML::TrackListing; | ||
| 2 | |||
| 3 | # This module produces components of the track listing. | ||
| 4 | |||
| 5 | use strict; | ||
| 6 | use warnings; | ||
| 7 | use Bio::Graphics::Browser2::Util 'citation'; | ||
| 8 | use CGI qw(:standard); | ||
| 9 | use Carp 'croak'; | ||
| 10 | |||
| 11 | sub new { | ||
| 12 | my $class = shift; | ||
| 13 | my $render = shift; | ||
| 14 | return bless {render=>$render},ref $class||$class; | ||
| 15 | } | ||
| 16 | |||
| 17 | sub render {shift->{render} } | ||
| 18 | sub source {shift->render->data_source} | ||
| 19 | sub settings {shift->render->state } | ||
| 20 | |||
| 21 | sub render_track_listing { | ||
| 22 | croak 'render_track_listing() must be implemented in a subclass of TrackListing.pm'; | ||
| 23 | } | ||
| 24 | |||
| 25 | sub categorize_track { | ||
| 26 | my $self = shift; | ||
| 27 | my $label = shift; | ||
| 28 | return; # no categories in parent class | ||
| 29 | } | ||
| 30 | |||
| 31 | # render the label and controls for an individual track, | ||
| 32 | # used in subclasses. Returns the HTML to be pasted onto | ||
| 33 | # the page. | ||
| 34 | sub render_one_track { | ||
| 35 | my $self = shift; | ||
| 36 | my $label = shift; | ||
| 37 | my $hilite = shift || []; | ||
| 38 | |||
| 39 | my $settings = $self->settings; | ||
| 40 | my $render = $self->render; | ||
| 41 | my $source = $self->source; | ||
| 42 | my $button_url = $source->button_url; | ||
| 43 | |||
| 44 | my $key = $render->label2key($label); | ||
| 45 | my ($link,$mouseover); | ||
| 46 | |||
| 47 | if ($label =~ /^plugin:/) { | ||
| 48 | $key = $render->plugin_name($label); | ||
| 49 | } | ||
| 50 | |||
| 51 | elsif ($label =~ /^file:/){ | ||
| 52 | $link = "?Download%20File=$key"; | ||
| 53 | } | ||
| 54 | |||
| 55 | elsif ($source->setting($label=>'citation')){ | ||
| 56 | $link = "?display_citation=$label"; | ||
| 57 | my $cit_txt = citation( $source, $label, $render->language ) || ''; | ||
| 58 | if ( length $cit_txt > 100) { | ||
| 59 | $cit_txt =~ s/\<[^\>]+\>//g; # truncate and strip tags for preview | ||
| 60 | $cit_txt =~ s/(.{100}).+/$1/; | ||
| 61 | $cit_txt =~ s/\s+\S+$//; | ||
| 62 | $cit_txt =~ s/\'/\&\#39;/g; | ||
| 63 | $cit_txt =~ s/\"/\&\#34;/g; | ||
| 64 | $cit_txt .= '... <i>' . ($render->translate('CLICK_FOR_MORE')||'') . '</i>'; | ||
| 65 | } | ||
| 66 | $mouseover = "<b>$key</b>"; | ||
| 67 | $mouseover .= ": $cit_txt" if $cit_txt; | ||
| 68 | } | ||
| 69 | |||
| 70 | my $track_on = $settings->{features}{$label}{visible}; | ||
| 71 | my $favorite = $settings->{favorites}{$label}; | ||
| 72 | my $balloon = $source->setting('balloon style') || 'GBubble'; | ||
| 73 | my $cellid = 'datacell'; | ||
| 74 | |||
| 75 | my @classes = 'track_title'; | ||
| 76 | push @classes,'activeTrack' if $track_on; | ||
| 77 | push @classes,'favorite' if $favorite; | ||
| 78 | push @classes,'remote' if $label =~ /^(http|ftp|file):/; | ||
| 79 | |||
| 80 | # add hilighting if requested | ||
| 81 | for my $h (@$hilite) { | ||
| 82 | $key =~ s!($h)!<span class='text_match'>$1</span>!gi; | ||
| 83 | } | ||
| 84 | |||
| 85 | #if the track has already been favorited, the image source is made into the yellow star | ||
| 86 | my $star = $favorite ? 'ficon_2.png' : 'ficon.png'; | ||
| 87 | my $class = $favorite ? 'star favorite' : 'star'; | ||
| 88 | my $show_fav = $render->translate('ADDED_TO'); | ||
| 89 | my $favoriteicon = img({-class => $class, | ||
| 90 | -id => "star_$label", | ||
| 91 | -onClick => "togglestars('$label')", | ||
| 92 | -onMouseOver => "GBubble.showTooltip(event,'$show_fav')", | ||
| 93 | -style => 'cursor:pointer;', | ||
| 94 | -src => "$button_url/$star"} | ||
| 95 | ); | ||
| 96 | |||
| 97 | my $category = $self->categorize_track($label); | ||
| 98 | my $clickaction = "gbToggleTrack('$label')"; | ||
| 99 | $clickaction .= ";gbTurnOff('${category}_section')" if $category; | ||
| 100 | |||
| 101 | my @args; | ||
| 102 | push @args, (-class => "@classes"); | ||
| 103 | push @args, (-onClick => $clickaction); | ||
| 104 | push @args, (-onmouseover => "$balloon.showTooltip(event,'$mouseover')") if $mouseover; | ||
| 105 | |||
| 106 | my $title = span({-id=>"${label}_check",@args},$key); | ||
| 107 | |||
| 108 | my $checkicon = img({-id => "${label}_img", | ||
| 109 | -onClick => "gbToggleTrack('$label')", | ||
| 110 | -src =>$track_on ? "$button_url/check.png" | ||
| 111 | : "$button_url/square.png"}); | ||
| 112 | my $help = $link ? a({-href => $link, | ||
| 113 | -target => '_new', | ||
| 114 | -onmouseover => "$balloon.showTooltip(event,'$mouseover')", | ||
| 115 | }, '[?]') | ||
| 116 | : ''; | ||
| 117 | |||
| 118 | my $html = join(' ',$favoriteicon,span({-class=>'track_label'},$checkicon,$title),$help); | ||
| 119 | |||
| 120 | |||
| 121 | if (my ($selected,$total) = $render->subtrack_counts($label)) { | ||
| 122 | my $escaped_label = CGI::escape($label); | ||
| 123 | $html .= ' ['. span({-class =>'clickable', | ||
| 124 | -onMouseOver => "GBubble.showTooltip(event,'".$render->translate('CLICK_MODIFY_SUBTRACK_SEL')."')", | ||
| 125 | -onClick => "GBox.showTooltip(event,'url:?action=select_subtracks;track=$escaped_label',true)" | ||
| 126 | },i($render->translate('SELECT_SUBTRACKS',$selected,$total))).']'; | ||
| 127 | } | ||
| 128 | |||
| 129 | return $html; | ||
| 130 | } | ||
| 131 | |||
| 132 | |||
| 133 | 1; | ||
| 134 |