« blib/lib/Bio/Graphics/Browser2/TrackDumper/RichSeqMaker.pm
↑ Summary
blib/lib/Bio/Graphics/Browser2/Render/Login.pm »
| 1 | package Bio::Graphics::Browser2::Render::HTML; | ||
| 2 | |||
| 3 | use strict; | ||
| 4 | use warnings; | ||
| 5 | use base 'Bio::Graphics::Browser2::Render'; | ||
| 6 | use Bio::Graphics::Browser2::Shellwords; | ||
| 7 | use Bio::Graphics::Browser2::SubtrackTable; | ||
| 8 | use Bio::Graphics::Karyotype; | ||
| 9 | use Bio::Graphics::Browser2::Render::TrackConfig; | ||
| 10 | use Bio::Graphics::Browser2::Util qw[citation url_label segment_str]; | ||
| 11 | use JSON; | ||
| 12 | use Digest::MD5 'md5_hex'; | ||
| 13 | use Carp qw(croak cluck); | ||
| 14 | use CGI qw(:standard escape start_table end_table); | ||
| 15 | use Text::Tabs; | ||
| 16 | use POSIX qw(floor); | ||
| 17 | |||
| 18 | use constant JS => '/gbrowse2/js'; | ||
| 19 | use constant ANNOTATION_EDIT_ROWS => 25; | ||
| 20 | use constant ANNOTATION_EDIT_COLS => 100; | ||
| 21 | use constant MAXIMUM_EDITABLE_UPLOAD => 1_000_000; # bytes | ||
| 22 | use constant DEBUG => 0; | ||
| 23 | |||
| 24 | use constant HAVE_SVG => eval "require GD::SVG; 1"; | ||
| 25 | our $CAN_PDF; | ||
| 26 | |||
| 27 | # Render HTML Start - Returns the HTML for the browser's <head> section. | ||
| 28 | sub render_html_start { | ||
| 29 | my $self = shift; | ||
| 30 | my ($title,@actions) = @_; | ||
| 31 | my $dsn = $self->data_source; | ||
| 32 | my $html = $self->render_html_head($dsn,$title,@actions); | ||
| 33 | $html .= $self->render_js_controller_settings(); | ||
| 34 | $html .= $self->render_balloon_settings(); | ||
| 35 | $html .= "<div id='main'>"; | ||
| 36 | $html .= $self->render_select_menus(); | ||
| 37 | return $html; | ||
| 38 | } | ||
| 39 | |||
| 40 | # Render Top - Returns the HTML for the top banner of the page. | ||
| 41 | sub render_top { | ||
| 42 | my $self = shift; | ||
| 43 | my ($title,$features) = @_; | ||
| 44 | my $err = $self->render_error_div; | ||
| 45 | my $html = ''; | ||
| 46 | |||
| 47 | $features ||= []; | ||
| 48 | $html .= $self->render_title($title,$self->state->{name} | ||
| 49 | && @$features == 0); | ||
| 50 | # ***Render the snapshot title*** | ||
| 51 | $html .= $self->snapshot_manager->render_title; | ||
| 52 | $html .= $self->html_frag('html1',$self->state); | ||
| 53 | |||
| 54 | return $err | ||
| 55 | . $self->toggle({nodiv=>1},'banner','',$html); | ||
| 56 | } | ||
| 57 | |||
| 58 | # Render Error DIV - Returns the HTML for the error display at the top of the page. | ||
| 59 | sub render_error_div { | ||
| 60 | my $self = shift; | ||
| 61 | |||
| 62 | my $error = $self->error_message; | ||
| 63 | my $display = $error ? 'block' : 'none'; | ||
| 64 | |||
| 65 | my $button = button({-onClick=>'Controller.hide_error()', | ||
| 66 | -name=>'Ok'}); | ||
| 67 | return div({-class=>'errorpanel', | ||
| 68 | -style=>"display:${display}", | ||
| 69 | -id=>'errordiv'}, | ||
| 70 | table( | ||
| 71 | TR( | ||
| 72 | td(span({-class=>'error',-id=>'errormsg'},$error || 'no error')), | ||
| 73 | td({-align=>'right'},$button) | ||
| 74 | ), | ||
| 75 | ), | ||
| 76 | div({-class=>'errorpanel', | ||
| 77 | -style=>"display:none;margin: 6px 6px 6px 6px", | ||
| 78 | -id =>'errordetails'}, | ||
| 79 | 'no details' | ||
| 80 | ) | ||
| 81 | ).br(); | ||
| 82 | } | ||
| 83 | |||
| 84 | sub render_login_required { | ||
| 85 | my $self = shift; | ||
| 86 | my $action = shift; | ||
| 87 | return div( | ||
| 88 | h1($self->translate('LOGIN_REQUIRED'), | ||
| 89 | button(-name => $self->translate('LOGIN'), | ||
| 90 | -onClick => $action) | ||
| 91 | )); | ||
| 92 | } | ||
| 93 | |||
| 94 | # Render Tabbed Pages - Returns the HTML containing the tabs & the page DIVs to hold the content. | ||
| 95 | sub render_tabbed_pages { | ||
| 96 | my $self = shift; | ||
| 97 | my ($main_html,$tracks_html,$snapshot_html,$community_tracks_html,$custom_tracks_html,$settings_html) = @_; | ||
| 98 | my $uses_database = $self->user_tracks->database; | ||
| 99 | |||
| 100 | my $main_title = $self->translate('MAIN_PAGE'); | ||
| 101 | my $tracks_title = $self->translate('SELECT_TRACKS'); | ||
| 102 | my $snapshot_title = $self->translate('SNAPSHOT_SELECT'); | ||
| 103 | my $community_tracks_title = $self->translate('COMMUNITY_TRACKS_PAGE') if $uses_database; | ||
| 104 | my $custom_tracks_title = $self->translate('CUSTOM_TRACKS_PAGE'); | ||
| 105 | my $settings_title = $self->translate('SETTINGS_PAGE'); | ||
| 106 | |||
| 107 | my $html = ''; | ||
| 108 | |||
| 109 | $html .= div({-id=>'tabbed_section', -class=>'tabbed'}, | ||
| 110 | div({-id=>'tabbed_menu',-class=>'tabmenu'}, | ||
| 111 | span({id=>'main_page_select'}, $main_title), | ||
| 112 | span({id=>'track_page_select'}, $tracks_title), | ||
| 113 | span({id=>'snapshots_page_select'}, $snapshot_title), | ||
| 114 | $uses_database? span({id=>'community_tracks_page_select'}, $community_tracks_title) : "", | ||
| 115 | span({id=>'custom_tracks_page_select'}, $custom_tracks_title),, | ||
| 116 | span({id=>'settings_page_select'}, $settings_title) | ||
| 117 | ), | ||
| 118 | div({-id=>'main_page', -class=>'tabbody'}, $main_html), | ||
| 119 | div({-id=>'track_page', -class=>'tabbody' ,-style=>'display:none'}, $tracks_html), | ||
| 120 | div({-id=>'snapshots_page', -class=>'tabbody' ,-style=>'display:none'}, $snapshot_html), | ||
| 121 | $uses_database?div({-id=>'community_tracks_page',-class=>'tabbody',-style=>'display:none'}, $community_tracks_html) : "", | ||
| 122 | div({-id=>'custom_tracks_page', -class=>'tabbody',-style=>'display:none'}, $custom_tracks_html), | ||
| 123 | div({-id=>'settings_page', -class=>'tabbody',-style=>'display:none'}, $settings_html), | ||
| 124 | ); | ||
| 125 | |||
| 126 | return $html; | ||
| 127 | } | ||
| 128 | |||
| 129 | # Render User Head - Returns any HTML for the <head> section specified by the user in GBrowse.conf. | ||
| 130 | sub render_user_head { | ||
| 131 | my $self = shift; | ||
| 132 | my $settings = $self->state; | ||
| 133 | return '' unless $settings->{head}; | ||
| 134 | my $a = $self->data_source->global_setting('head'); | ||
| 135 | return $a->(@_) if ref $a eq 'CODE'; | ||
| 136 | return $a || ''; | ||
| 137 | } | ||
| 138 | |||
| 139 | # Render User Header - Returns any HTML for the top of the browser (the header) as specified by the user in GBrowse.conf. | ||
| 140 | sub render_user_header { | ||
| 141 | my $self = shift; | ||
| 142 | my $settings = $self->state; | ||
| 143 | return '' unless $settings->{head}; | ||
| 144 | my $a = $self->data_source->global_setting('header'); | ||
| 145 | return $a->(@_) if ref $a eq 'CODE'; | ||
| 146 | return $a || ''; | ||
| 147 | } | ||
| 148 | |||
| 149 | # Render Bottom - Returns any HTML included in the footer specified by the user in GBrowse.conf. | ||
| 150 | sub render_bottom { | ||
| 151 | my $self = shift; | ||
| 152 | my $features = shift; # not used | ||
| 153 | my $a = $self->data_source->global_setting('footer'); | ||
| 154 | my $value = ref $a eq 'CODE' ? $a->(@_) : $a; | ||
| 155 | $value ||= ''; | ||
| 156 | return $value."</div>".end_html(); | ||
| 157 | } | ||
| 158 | |||
| 159 | # Render Navbar - Returns the HTML for the navigation bar along the top of the main browser page (in the "Search" node). | ||
| 160 | sub render_navbar { | ||
| 161 | my $self = shift; | ||
| 162 | my $segment = shift; | ||
| 163 | |||
| 164 | warn "render_navbar()" if DEBUG; | ||
| 165 | |||
| 166 | my $settings = $self->state; | ||
| 167 | my $source = '/'.$self->session->source.'/'; | ||
| 168 | |||
| 169 | my $searchform = join '',( | ||
| 170 | start_form( | ||
| 171 | -name => 'searchform', | ||
| 172 | -id => 'searchform', | ||
| 173 | |||
| 174 | ), | ||
| 175 | hidden(-name=>'force_submit',-value=>0), | ||
| 176 | hidden(-name=>'plugin_find', -value=>0), | ||
| 177 | div({ -id => 'search_form_objects' }, | ||
| 178 | $self->render_search_form_objects(), | ||
| 179 | ), | ||
| 180 | end_form | ||
| 181 | ); | ||
| 182 | |||
| 183 | my $search = $self->setting('no search') | ||
| 184 | ? '' : b($self->translate('Landmark')).':'.br().$searchform.$self->examples(); | ||
| 185 | |||
| 186 | my $plugin_form = div({-id=>'plugin_form'},$self->plugin_form()); | ||
| 187 | |||
| 188 | # *** Checks the state to see if a snapshot is active and assigns it *** | ||
| 189 | my $source_form = div({-id=>'source_form'},$self->source_form()); | ||
| 190 | |||
| 191 | my $sliderform = div({-id=>'slider_form'},$self->sliderform($segment)); | ||
| 192 | |||
| 193 | # *** Creates the save session button and assigns it to save_prompt *** | ||
| 194 | my $snapshot_options = $self->snapshot_manager->snapshot_options; | ||
| 195 | return $self->toggle('Search', | ||
| 196 | div({-class=>'searchbody'}, | ||
| 197 | table({-border=>0,-width=>'95%'}, | ||
| 198 | TR(td({-width=>'50%'},$search),td({-width=>'45%'},$plugin_form,$snapshot_options)), | ||
| 199 | TR(td({-align=>'left'}, | ||
| 200 | $source_form, | ||
| 201 | ), | ||
| 202 | td({-align=>'left'}, | ||
| 203 | $sliderform || ' ' | ||
| 204 | ), | ||
| 205 | ) | ||
| 206 | ), | ||
| 207 | $self->html_frag('html3',$self->state) | ||
| 208 | ) | ||
| 209 | ) | ||
| 210 | . div( { -id => "plugin_configure_div"},''); | ||
| 211 | } | ||
| 212 | |||
| 213 | # Plugin Form - Returns the HTML for the plugin form in the main navigation bar. | ||
| 214 | sub plugin_form { | ||
| 215 | my $self = shift; | ||
| 216 | my $settings = $self->state; | ||
| 217 | |||
| 218 | return $settings->{GALAXY_URL} | ||
| 219 | ? button(-name => $self->translate('SEND_TO_GALAXY'), | ||
| 220 | -onClick => $self->galaxy_link). | ||
| 221 | button(-name => $self->translate('CANCEL'), | ||
| 222 | -onClick => $self->galaxy_clear.";Controller.update_sections(['plugin_form'])", | ||
| 223 | ) | ||
| 224 | : join '',( | ||
| 225 | start_form(-name=>'pluginform', | ||
| 226 | -id=>'pluginform', | ||
| 227 | -onSubmit=>'return false'), | ||
| 228 | $self->plugin_menu(), | ||
| 229 | end_form); | ||
| 230 | } | ||
| 231 | |||
| 232 | # Source Form - Returns the HTML for the source chooser in the main navigation bar. | ||
| 233 | sub source_form { | ||
| 234 | my $self = shift; | ||
| 235 | join '',( | ||
| 236 | start_form(-name=>'sourceform', | ||
| 237 | -id=>'sourceform', | ||
| 238 | -onSubmit=>''), | ||
| 239 | $self->source_menu(), | ||
| 240 | end_form | ||
| 241 | ); | ||
| 242 | } | ||
| 243 | |||
| 244 | # *** Create the snapshot_form *** | ||
| 245 | sub snapshot_form { | ||
| 246 | return shift->snapshot_manager->snapshot_form; | ||
| 247 | } | ||
| 248 | |||
| 249 | # Slider Form - Returns the HTML for the zooming controls with the "Flip" checkbox. | ||
| 250 | sub sliderform { | ||
| 251 | my $self = shift; | ||
| 252 | my $segment = shift; | ||
| 253 | my $settings = $self->state; | ||
| 254 | if ($segment) { | ||
| 255 | return | ||
| 256 | join '',( | ||
| 257 | start_form(-name=>'sliderform',-id=>'sliderform',-onSubmit=>'return false'), | ||
| 258 | b($self->translate('Scroll'). ': '), | ||
| 259 | $self->slidertable($segment), | ||
| 260 | b( | ||
| 261 | checkbox(-name=>'flip', | ||
| 262 | -checked=>$settings->{flip},-value=>1, | ||
| 263 | -label=>$self->translate('Flip'),-override=>1, | ||
| 264 | -onClick => 'Controller.update_coordinates(this.name + " " + this.checked)', | ||
| 265 | ) | ||
| 266 | ), | ||
| 267 | hidden(-name=>'navigate',-value=>1,-override=>1), | ||
| 268 | end_form | ||
| 269 | ); | ||
| 270 | } | ||
| 271 | else { | ||
| 272 | return ''; | ||
| 273 | } | ||
| 274 | } | ||
| 275 | |||
| 276 | # Render Search For Objects - Returns the "Landmark or Region" search box on the browser tab. | ||
| 277 | sub render_search_form_objects { | ||
| 278 | my $self = shift; | ||
| 279 | my $settings = $self->state; | ||
| 280 | |||
| 281 | # avoid exposing the internal database ids to the public | ||
| 282 | my $search_value = $settings->{name} =~ /^id:/ && $self->region->features | ||
| 283 | ? eval{$self->region->features->[0]->display_name} | ||
| 284 | : $settings->{name}; | ||
| 285 | my $html = textfield( | ||
| 286 | -name => 'name', | ||
| 287 | -id => 'landmark_search_field', | ||
| 288 | -size => 25, | ||
| 289 | -default => $search_value, | ||
| 290 | -override=>1, | ||
| 291 | ); | ||
| 292 | if ($self->setting('autocomplete')) { | ||
| 293 | my $spinner_url = $self->data_source->button_url.'/spinner.gif'; | ||
| 294 | $html .= <<END | ||
| 295 | <span id="indicator1" style="display: none"> | ||
| 296 | <img src="$spinner_url" alt="$self->translate('WORKING')" /> | ||
| 297 | </span> | ||
| 298 | <div id="autocomplete_choices" class="autocomplete"></div> | ||
| 299 | END | ||
| 300 | } | ||
| 301 | $html .= submit( -name => $self->translate('Search') ); | ||
| 302 | return $html; | ||
| 303 | } | ||
| 304 | |||
| 305 | # Render HTML Head - Returns the HTML for the beginning of the page (for CGI's start HTML function). | ||
| 306 | sub render_html_head { | ||
| 307 | my $self = shift; | ||
| 308 | my ($dsn,$title,@other_initialization) = @_; | ||
| 309 | my @plugin_list = $self->plugins->plugins; | ||
| 310 | my $uses_database = $self->user_tracks->database; | ||
| 311 | |||
| 312 | return if $self->{started_html}++; | ||
| 313 | |||
| 314 | $title =~ s/<[^>]+>//g; # no markup in the head | ||
| 315 | |||
| 316 | # pick scripts | ||
| 317 | my $js = $dsn->globals->js_url; | ||
| 318 | my @scripts; | ||
| 319 | |||
| 320 | # Set any onTabLoad functions | ||
| 321 | my $main_page_onLoads = ""; | ||
| 322 | my $track_page_onLoads = ''; | ||
| 323 | my $community_track_page_onLoads = ''; | ||
| 324 | my $custom_track_page_onLoads = ""; | ||
| 325 | my $settings_page_onLoads = ""; | ||
| 326 | |||
| 327 | # Get plugin onTabLoad functions for each tab, if any | ||
| 328 | my %plugin_onLoads = map ($_->onLoads, @plugin_list); | ||
| 329 | $main_page_onLoads .= $plugin_onLoads{'main_page'} if $plugin_onLoads{'main_page'}; | ||
| 330 | $track_page_onLoads .= $plugin_onLoads{'track_page'} if $plugin_onLoads{'track_page'}; | ||
| 331 | $custom_track_page_onLoads .= $plugin_onLoads{'custom_track_page'} if $plugin_onLoads{'custom_track_page'} && $uses_database; | ||
| 332 | $community_track_page_onLoads .= $plugin_onLoads{'community_track_page'} if $plugin_onLoads{'community_track_page'}; | ||
| 333 | $settings_page_onLoads .= $plugin_onLoads{'settings_page'} if $plugin_onLoads{'settings_page'}; | ||
| 334 | |||
| 335 | my $onTabScript .= "function onTabLoad(tab_id) {\n"; | ||
| 336 | $onTabScript .= "if (tab_id == 'main_page_select') {$main_page_onLoads}\n"; | ||
| 337 | $onTabScript .= "if (tab_id == 'track_page_select') {$track_page_onLoads}\n"; | ||
| 338 | $onTabScript .= "if (tab_id == 'community_track_page_select') {$community_track_page_onLoads}\n" if $uses_database; | ||
| 339 | $onTabScript .= "if (tab_id == 'custom_track_page_select') {$custom_track_page_onLoads}\n"; | ||
| 340 | $onTabScript .= "if (tab_id == 'settings_page_select') {$settings_page_onLoads}\n"; | ||
| 341 | $onTabScript .= "};"; | ||
| 342 | push (@scripts,({type=>"text/javascript"}, $onTabScript)); | ||
| 343 | |||
| 344 | my $url = "?action=get_translation_tables" . ( $self->language_code ? ';language='.($self->language_code)[0] : '' ); #Include language as a parameter to prevent browser from using wrong cache if user changes languages | ||
| 345 | push (@scripts,({src=>$url})); | ||
| 346 | |||
| 347 | # drag-and-drop functions from scriptaculous | ||
| 348 | push @scripts,{src=>"$js/$_"} | ||
| 349 | foreach qw( | ||
| 350 | prototype.js | ||
| 351 | scriptaculous.js | ||
| 352 | subtracktable.js | ||
| 353 | ); | ||
| 354 | |||
| 355 | if ($self->setting('autocomplete')) { | ||
| 356 | push @scripts,{src=>"$js/$_"} | ||
| 357 | foreach qw(controls.js autocomplete.js); | ||
| 358 | } | ||
| 359 | |||
| 360 | if ($self->globals->user_accounts) { | ||
| 361 | push @scripts,{src=>"$js/$_"} | ||
| 362 | foreach qw(login.js); | ||
| 363 | } | ||
| 364 | |||
| 365 | # our own javascript files | ||
| 366 | push @scripts,map { {src=>"$js/$_"} } qw( | ||
| 367 | buttons.js | ||
| 368 | trackFavorites.js | ||
| 369 | karyotype.js | ||
| 370 | rubber.js | ||
| 371 | overviewSelect.js | ||
| 372 | detailSelect.js | ||
| 373 | regionSelect.js | ||
| 374 | track.js | ||
| 375 | balloon.js | ||
| 376 | balloon.config.js | ||
| 377 | GBox.js | ||
| 378 | ajax_upload.js | ||
| 379 | tabs.js | ||
| 380 | track_configure.js | ||
| 381 | track_pan.js | ||
| 382 | ruler.js | ||
| 383 | controller.js | ||
| 384 | snapshotManager.js | ||
| 385 | ); | ||
| 386 | |||
| 387 | # add scripts needed by plugins. Looks in /js folder unless specified. | ||
| 388 | my @plugin_scripts = map ($_->scripts, @plugin_list); | ||
| 389 | # add a path if one isn't specified. | ||
| 390 | foreach (@plugin_scripts) { | ||
| 391 | if ($_ !~ /^\.{0,2}[\/\\]/) { | ||
| 392 | $_ = "$js/$_"; | ||
| 393 | } | ||
| 394 | }; | ||
| 395 | push @scripts,{src=>"$_"} foreach @plugin_scripts; | ||
| 396 | |||
| 397 | # pick stylesheets. Looks in /css folder unless specified. | ||
| 398 | my @stylesheets; | ||
| 399 | my $titlebar = 'css/titlebar-default.css'; | ||
| 400 | my $stylesheet = $self->setting('stylesheet')||'/gbrowse2/css/gbrowse.css'; | ||
| 401 | push @stylesheets,{src => $self->globals->resolve_path('css/tracks.css','url')}; | ||
| 402 | push @stylesheets,{src => $self->globals->resolve_path('css/subtracktable.css','url')}; | ||
| 403 | push @stylesheets,{src => $self->globals->resolve_path('css/snapshots.css','url')}; | ||
| 404 | push @stylesheets,{src => $self->globals->resolve_path('css/karyotype.css','url')}; | ||
| 405 | push @stylesheets,{src => $self->globals->resolve_path('css/dropdown/dropdown.css','url')}; | ||
| 406 | push @stylesheets,{src => $self->globals->resolve_path('css/dropdown/default_theme.css','url')}; | ||
| 407 | push @stylesheets,{src => $self->globals->resolve_path($titlebar,'url')}; | ||
| 408 | |||
| 409 | # add stylesheets used by plugins | ||
| 410 | my @plugin_stylesheets = map ($_->stylesheets, @plugin_list); | ||
| 411 | # add a path if one isn't specified. | ||
| 412 | foreach (@plugin_stylesheets) { | ||
| 413 | if ($_ !~ /^\.{0,2}[\/\\]/) { | ||
| 414 | $_ = $self->globals->resolve_path("css/$_",'url'); | ||
| 415 | } | ||
| 416 | }; | ||
| 417 | push @stylesheets,{src => $_} foreach @plugin_stylesheets; | ||
| 418 | |||
| 419 | my @theme_stylesheets = shellwords($self->setting('stylesheet') || '/gbrowse2/css/gbrowse.css'); | ||
| 420 | for my $s ( @theme_stylesheets ) { | ||
| 421 | my ($url,$media) = $s =~ /^([^(]+)(?:\((.+)\))?/; | ||
| 422 | $media ||= 'all'; | ||
| 423 | push @stylesheets, { | ||
| 424 | src => $self->globals->resolve_path($url,'url'), | ||
| 425 | media => $media, | ||
| 426 | }; | ||
| 427 | } | ||
| 428 | |||
| 429 | # colors for "rubberband" selection | ||
| 430 | my $set_dragcolors = ''; | ||
| 431 | if (my $fill = $self->data_source->global_setting('hilite fill')) { | ||
| 432 | $fill =~ s/^(\d+,\d+,\d+)$/rgb($1)/; | ||
| 433 | $fill =~ s/^(#[0-9A-F]{2}[0-9A-F]{2}[0-9A-F]{2})[0-9A-F]{2}$/$1/; | ||
| 434 | $fill =~ s/^(\w+):[\d.]+$/$1/; | ||
| 435 | $set_dragcolors = "set_dragcolors('$fill')"; | ||
| 436 | } | ||
| 437 | my $units = $self->data_source->setting('units') || 'bp'; | ||
| 438 | my $divider = $self->data_source->unit_divider; | ||
| 439 | my $set_units = "set_dragunits('$units',$divider)"; | ||
| 440 | |||
| 441 | my @extra_headers; | ||
| 442 | push @extra_headers, $self->render_user_head; | ||
| 443 | |||
| 444 | # put all the html head arguments together | ||
| 445 | my @args = (-title => $title, | ||
| 446 | -style => \@stylesheets, | ||
| 447 | -encoding => $self->translate('CHARSET'), | ||
| 448 | -script => \@scripts, | ||
| 449 | -head => \@extra_headers, | ||
| 450 | ); | ||
| 451 | push @args,(-lang=>($self->language_code)[0]) if $self->language_code; | ||
| 452 | |||
| 453 | # add body's onload arguments, including ones used by plugins | ||
| 454 | my $autocomplete = ''; | ||
| 455 | |||
| 456 | my $plugin_onloads = join ';',map {eval{$_->body_onloads}} @plugin_list; | ||
| 457 | my $other_actions = join ';',@other_initialization; | ||
| 458 | push @args,(-onLoad => "initialize_page(); $set_dragcolors; $set_units; $plugin_onloads; $other_actions"); | ||
| 459 | return start_html(@args); | ||
| 460 | } | ||
| 461 | |||
| 462 | # Render JS Controller Settings - Renders a block of javascript that loads some of our global config settings into the main controller object for use in client-side code. | ||
| 463 | sub render_js_controller_settings { | ||
| 464 | my ( $self ) = @_; | ||
| 465 | my $globals = $self->globals; | ||
| 466 | |||
| 467 | my @export_keys = qw( | ||
| 468 | buttons | ||
| 469 | balloons | ||
| 470 | openid | ||
| 471 | js | ||
| 472 | gbrowse_help | ||
| 473 | stylesheet | ||
| 474 | ); | ||
| 475 | |||
| 476 | my $controller_globals = JSON::to_json({ | ||
| 477 | map { $_ => ( $self->globals->url_path($_) || undef ) } @export_keys | ||
| 478 | }); | ||
| 479 | |||
| 480 | my $scripts = "Controller.set_globals( $controller_globals );"; | ||
| 481 | |||
| 482 | if ($globals->user_accounts) { | ||
| 483 | my $userdb = $self->userdb; | ||
| 484 | my $openid = ($userdb->can_openid && $self->globals->user_accounts_allow_openid) ||0; | ||
| 485 | my $register = ($userdb->can_register && $self->globals->user_accounts_allow_registration)||0; | ||
| 486 | $scripts .= "Controller.can_openid = $openid;"; | ||
| 487 | $scripts .= "Controller.can_register = $register;"; | ||
| 488 | } | ||
| 489 | |||
| 490 | return script({-type=>'text/javascript'}, $scripts); | ||
| 491 | } | ||
| 492 | |||
| 493 | # Renders the settings which control the balloon styles on the page. | ||
| 494 | sub render_balloon_settings { | ||
| 495 | my $self = shift; | ||
| 496 | my $source = $self->data_source; | ||
| 497 | |||
| 498 | my $default_style = $source->setting('balloon style') || 'GBubble';; | ||
| 499 | my $custom_balloons = $source->setting('custom balloons') || ""; | ||
| 500 | my %config_values = $custom_balloons =~ /\[([^\]]+)\]([^\[]+)/g; | ||
| 501 | |||
| 502 | # default image path is for the default balloon set | ||
| 503 | my $balloon_images = $self->globals->balloon_url() || '/gbrowse2/images/balloons'; | ||
| 504 | my $default_images = "$balloon_images/$default_style"; | ||
| 505 | my $balloon_settings = $self->default_balloon_settings($balloon_images); | ||
| 506 | |||
| 507 | # handle any custom balloons/config sets | ||
| 508 | # two args that are interpreted here and not passed | ||
| 509 | # to the JavaScript: | ||
| 510 | # | ||
| 511 | # class = Balloon (could also be Box) | ||
| 512 | # config set = GPlain (GBubble is the default) | ||
| 513 | for my $balloon ( keys %config_values ) { | ||
| 514 | my %config = $config_values{$balloon} =~ /(\w+)\s*=\s*(\S+)/g; | ||
| 515 | |||
| 516 | # which balloon configuration set to use? | ||
| 517 | my $bstyle = $config{'config set'} || $default_style; | ||
| 518 | delete $config{'config set'}; | ||
| 519 | |||
| 520 | # which class to use (may be Box or Balloon) | ||
| 521 | my $bclass = $config{'class'} || 'Balloon'; | ||
| 522 | delete $config{'class'}; | ||
| 523 | |||
| 524 | # This creates a Ballon (or Box) object and loads the | ||
| 525 | # specified configuration set. | ||
| 526 | $balloon_settings .= "\nvar $balloon = new $bclass;\nBalloonConfig($balloon,'$bstyle')\n"; | ||
| 527 | |||
| 528 | # Image path must be specified | ||
| 529 | $config{images} ||= $default_images; | ||
| 530 | |||
| 531 | for my $option ( keys %config ) { | ||
| 532 | my $value | ||
| 533 | = $config{$option} =~ /^[\d.-]+$/ | ||
| 534 | ? $config{$option} | ||
| 535 | : "'$config{$option}'"; | ||
| 536 | $balloon_settings .= "$balloon.$option = $value;\n"; | ||
| 537 | } | ||
| 538 | } | ||
| 539 | |||
| 540 | $balloon_settings =~ s/^/ /gm; | ||
| 541 | return "\n<script type=\"text/javascript\">\n$balloon_settings\n</script>\n"; | ||
| 542 | } | ||
| 543 | |||
| 544 | sub default_balloon_settings { | ||
| 545 | my $self = shift; | ||
| 546 | my $balloon_images = shift; | ||
| 547 | |||
| 548 | # These are the four configured popup tooltip styles | ||
| 549 | # GBubble is the global default | ||
| 550 | # each type can be called using the [name] syntax | ||
| 551 | return <<END; | ||
| 552 | // Original GBrowse popup balloon style | ||
| 553 | var GBubble = new Balloon; | ||
| 554 | BalloonConfig(GBubble,'GBubble'); | ||
| 555 | GBubble.images = "$balloon_images/GBubble"; | ||
| 556 | GBubble.allowEventHandlers = true; | ||
| 557 | GBubble.opacity = 1; | ||
| 558 | GBubble.fontFamily = 'sans-serif'; | ||
| 559 | |||
| 560 | // A simpler popup balloon style | ||
| 561 | var GPlain = new Balloon; | ||
| 562 | BalloonConfig(GPlain,'GPlain'); | ||
| 563 | GPlain.images = "$balloon_images/GPlain"; | ||
| 564 | GPlain.allowEventHandlers = true; | ||
| 565 | GPlain.opacity = 1; | ||
| 566 | GPlain.fontFamily = 'sans-serif'; | ||
| 567 | |||
| 568 | // Like GBubble but fades in | ||
| 569 | var GFade = new Balloon; | ||
| 570 | BalloonConfig(GFade,'GFade'); | ||
| 571 | GFade.images = "$balloon_images/GBubble"; | ||
| 572 | GFade.opacity = 1; | ||
| 573 | GFade.allowEventHandlers = true; | ||
| 574 | GFade.fontFamily = 'sans-serif'; | ||
| 575 | |||
| 576 | // A formatted box | ||
| 577 | // Note: Box is a subclass of Balloon | ||
| 578 | var GBox = new Box; | ||
| 579 | BalloonConfig(GBox,'GBox'); | ||
| 580 | GBox.images = "$balloon_images/GBubble"; | ||
| 581 | GBox.allowEventHandlers = true; | ||
| 582 | GBox.evalScripts = true; | ||
| 583 | GBox.opacity = 1; | ||
| 584 | GBox.fontFamily = 'sans-serif'; | ||
| 585 | GBox.maxWidth = 1280; | ||
| 586 | GBox.stemHeight = 0; | ||
| 587 | END | ||
| 588 | } | ||
| 589 | |||
| 590 | sub render_select_menus { # for popup balloons | ||
| 591 | my $self = shift; | ||
| 592 | my $html = ''; | ||
| 593 | $html .= $self->_render_select_menu($_) | ||
| 594 | foreach (qw(DETAIL OVERVIEW REGION)); | ||
| 595 | return $html; | ||
| 596 | } | ||
| 597 | |||
| 598 | sub _render_select_menu { | ||
| 599 | my $self = shift; | ||
| 600 | my $view = shift || 'DETAIL'; | ||
| 601 | my $config_label = uc($view).' SELECT MENU'; | ||
| 602 | |||
| 603 | # HTML for the custom menu is required | ||
| 604 | my $menu_html = $self->setting($config_label => 'HTML') | ||
| 605 | || $self->setting($config_label => 'html') | ||
| 606 | || return ''; | ||
| 607 | |||
| 608 | # should not be visible | ||
| 609 | my %style = (display => 'none'); | ||
| 610 | |||
| 611 | # optional style attributes | ||
| 612 | for my $att (qw/width font background background-color border/) { | ||
| 613 | my $val = $self->setting($config_label => $att) || next; | ||
| 614 | $style{$att} = $val; | ||
| 615 | } | ||
| 616 | $style{width} .= 'px'; | ||
| 617 | my $style = join('; ', map {"$_:$style{$_}"} keys %style); | ||
| 618 | |||
| 619 | # clean up the HTML just a bit | ||
| 620 | $menu_html =~ s/\</\n\</g; | ||
| 621 | |||
| 622 | return div( { -style => $style, | ||
| 623 | -id => lc($view).'SelectMenu' }, | ||
| 624 | $menu_html ); | ||
| 625 | } | ||
| 626 | |||
| 627 | # Returns the HTML for the page's title, as displayed at the top. | ||
| 628 | sub render_title { | ||
| 629 | my $self = shift; | ||
| 630 | my $title = shift; | ||
| 631 | my $error = shift; | ||
| 632 | my $settings = $self->state; | ||
| 633 | return $settings->{head} | ||
| 634 | ? h1({-id=>'page_title',-class=>$error ? 'error' : 'normal'},$title) | ||
| 635 | : ''; | ||
| 636 | } | ||
| 637 | |||
| 638 | # Renders the search & navigation instructions & examples. | ||
| 639 | sub render_instructions { | ||
| 640 | my $self = shift; | ||
| 641 | my $settings = $self->state; | ||
| 642 | my $oligo = $self->plugins->plugin('OligoFinder') ? ', oligonucleotide (15 bp minimum)' : ''; | ||
| 643 | |||
| 644 | return $settings->{head} | ||
| 645 | ? div({-class=>'searchtitle'}, | ||
| 646 | $self->toggle('Instructions', | ||
| 647 | div({-style=>'margin-left:2em'}, | ||
| 648 | $self->setting('search_instructions') || | ||
| 649 | $self->translate('SEARCH_INSTRUCTIONS', $oligo), | ||
| 650 | $self->setting('navigation_instructions') || | ||
| 651 | $self->translate('NAVIGATION_INSTRUCTIONS'), | ||
| 652 | br(), | ||
| 653 | $self->examples(), | ||
| 654 | br(),$self->html_frag('html2',$self->state) | ||
| 655 | ) | ||
| 656 | ) | ||
| 657 | ) | ||
| 658 | : ''; | ||
| 659 | } | ||
| 660 | |||
| 661 | |||
| 662 | |||
| 663 | |||
| 664 | # Renders the HTML for the spinning "busy" signal on the top-left corner of the page. | ||
| 665 | sub render_busy_signal { | ||
| 666 | my $self = shift; | ||
| 667 | |||
| 668 | return img({ | ||
| 669 | -id => 'busy_indicator', | ||
| 670 | -src => $self->data_source->button_url.'/spinner.gif', | ||
| 671 | -style => 'position: fixed; top: 5px; left: 5px; display: none', | ||
| 672 | -alt => ($self->translate('WORKING')||'') | ||
| 673 | }); | ||
| 674 | } | ||
| 675 | |||
| 676 | # Renders the menu bar across the top of the browser. | ||
| 677 | sub render_actionmenu { | ||
| 678 | my $self = shift; | ||
| 679 | my $settings = $self->state; | ||
| 680 | |||
| 681 | my @export_links=a({-href=>'#',-onclick=>'Controller.make_image_link("GD")'}, $self->translate('IMAGE_LINK')); | ||
| 682 | push @export_links,a({-href=>'#',-onclick=>'Controller.make_image_link("GD::SVG")'}, $self->translate('SVG_LINK')) | ||
| 683 | if HAVE_SVG; | ||
| 684 | push @export_links,a({-href=>'#',-onclick=>'Controller.make_image_link("PDF")'}, $self->translate('PDF_LINK')) | ||
| 685 | if HAVE_SVG && $self->can_generate_pdf; | ||
| 686 | |||
| 687 | # Pass the gff link to a javascript function which will add the missing parameters that are determined client-side | ||
| 688 | push @export_links,a({-href=>'#',-onclick=>"Controller.gbgff_link('". $self->gff_dump_link ."')"}, $self->translate('DUMP_GFF')); | ||
| 689 | push @export_links,a({-href=>'#',-onclick=>"Controller.gbgff_link('". $self->dna_dump_link ."')"}, $self->translate('DUMP_SEQ')); | ||
| 690 | |||
| 691 | push @export_links,a({-href=>'javascript:'.$self->galaxy_link}, $self->translate('SEND_TO_GALAXY')) | ||
| 692 | if $self->data_source->global_setting('galaxy outgoing'); | ||
| 693 | |||
| 694 | my $bookmark_link = a({-href=>'#',-onclick=>'Controller.bookmark_link()'},$self->translate('BOOKMARK')),; | ||
| 695 | my $share_link = a({-href => '#', | ||
| 696 | -onMouseDown => "GBox.showTooltip(event,'url:?action=share_track;track=all')"}, | ||
| 697 | ($self->translate('SHARE_ALL') || "Share These Tracks" )), | ||
| 698 | |||
| 699 | my $help_link = a({-href=>$self->general_help(), | ||
| 700 | -target=>'_new'},$self->translate('HELP_WITH_BROWSER')); | ||
| 701 | my $about_gb_link = a({-onMouseDown => "Controller.show_info_message('about_gbrowse')", | ||
| 702 | -href => 'javascript:void(0)', | ||
| 703 | -style => 'cursor:pointer' | ||
| 704 | }, | ||
| 705 | $self->translate('ABOUT')); | ||
| 706 | my $about_dsn_link = a({-onMouseDown => "Controller.show_info_message('about_dsn')", | ||
| 707 | -href => 'javascript:void(0)', | ||
| 708 | -style => 'cursor:pointer' | ||
| 709 | }, | ||
| 710 | $self->translate('ABOUT_DSN')); | ||
| 711 | my $about_me_link = a({-onMouseDown => "Controller.show_info_message('about_me')", | ||
| 712 | -href => 'javascript:void(0)', | ||
| 713 | -style => 'cursor:pointer' | ||
| 714 | }, | ||
| 715 | $self->translate('ABOUT_ME')); | ||
| 716 | my $plugin_link = $self->plugin_links($self->plugins); | ||
| 717 | my $chrom_sizes_link = a({-href=>'?action=chrom_sizes'},$self->translate('CHROM_SIZES')); | ||
| 718 | my $reset_link = a({-href=>'?reset=1',-class=>'reset_button'}, $self->translate('RESET')); | ||
| 719 | |||
| 720 | my $login = $self->globals->user_accounts ? $self->render_login : ''; | ||
| 721 | |||
| 722 | my $file_menu = ul({-id => 'actionmenu', | ||
| 723 | -class => 'dropdown downdown-horizontal'}, | ||
| 724 | li({-class=>'dir'},$self->translate('FILE'), | ||
| 725 | ul(li($bookmark_link), | ||
| 726 | li($share_link), | ||
| 727 | li({-class=>'dir'},a({-href=>'#'},$self->translate('EXPORT')), | ||
| 728 | ul(li(\@export_links))), | ||
| 729 | $plugin_link ? li($plugin_link) : (), | ||
| 730 | li($chrom_sizes_link), | ||
| 731 | li($reset_link), | ||
| 732 | ) | ||
| 733 | ), | ||
| 734 | li({-class=>'dir'},$self->translate('HELP'), | ||
| 735 | ul({-class=>'dropdown'}, | ||
| 736 | li($help_link), | ||
| 737 | li({-class=>'divider'},''), | ||
| 738 | li($about_gb_link), | ||
| 739 | li($about_dsn_link), | ||
| 740 | li($about_me_link), | ||
| 741 | )), | ||
| 742 | ); | ||
| 743 | return div({-class=>'datatitle'},$file_menu,$login,br({-clear=>'all'})); | ||
| 744 | } | ||
| 745 | |||
| 746 | # Render Login - Returns the HTML for the login links on the top-right corner of the screen. | ||
| 747 | sub render_login { | ||
| 748 | my $self = shift; | ||
| 749 | my $settings = $self->state; | ||
| 750 | return unless $settings->{head}; | ||
| 751 | return $self->login_manager->render_login; | ||
| 752 | } | ||
| 753 | |||
| 754 | # For the subset of plugins that are named in the 'quicklink plugins' option, create quick links for them. | ||
| 755 | sub plugin_links { | ||
| 756 | my $self = shift; | ||
| 757 | my $plugins = shift; | ||
| 758 | |||
| 759 | my $quicklink_setting = $self->setting('quicklink plugins') or return ''; | ||
| 760 | my @plugins = shellwords($quicklink_setting) or return ''; | ||
| 761 | my $labels = $plugins->menu_labels; | ||
| 762 | |||
| 763 | my @result; | ||
| 764 | for my $p (@plugins) { | ||
| 765 | my $plugin = $plugins->plugin($p) or next; | ||
| 766 | my $action = "?plugin=$p;plugin_do=".$self->translate('Go'); | ||
| 767 | push @result,a({-href=>$action,-target=>'_new'},"[$labels->{$p}]"); | ||
| 768 | } | ||
| 769 | return \@result; | ||
| 770 | } | ||
| 771 | |||
| 772 | sub galaxy_form { | ||
| 773 | my $self = shift; | ||
| 774 | my $segment = shift; | ||
| 775 | |||
| 776 | my $settings = $self->state; | ||
| 777 | my $source = $self->data_source; | ||
| 778 | |||
| 779 | my $galaxy_url = $settings->{GALAXY_URL} | ||
| 780 | || $source->global_setting('galaxy outgoing') ; | ||
| 781 | return '' unless $galaxy_url; | ||
| 782 | |||
| 783 | my $URL = $source->global_setting('galaxy incoming'); | ||
| 784 | $URL ||= $self->globals->gbrowse_url(); | ||
| 785 | |||
| 786 | # Make sure to include all necessary parameters in URL to ensure that gbrowse will retrieve the data | ||
| 787 | # when Galaxy posts the URL. | ||
| 788 | my $dbkey = $source->global_setting('galaxy build name') || $source->name; | ||
| 789 | my $labels = $self->join_selected_tracks; | ||
| 790 | |||
| 791 | my $seg = $segment->seq_id.':'.$segment->start.'..'.$segment->end; | ||
| 792 | |||
| 793 | my $action = $galaxy_url =~ /\?/ ? "$galaxy_url&URL=$URL" : "$galaxy_url?URL=$URL"; | ||
| 794 | my $html = start_multipart_form(-name => 'galaxyform', | ||
| 795 | -action => $action, | ||
| 796 | -method => 'POST'); | ||
| 797 | |||
| 798 | $html .= hidden(-name=>'dbkey',-value=>$dbkey); | ||
| 799 | $html .= hidden(-name=>'gbgff',-value=>'save gff3'); | ||
| 800 | $html .= hidden(-name=>'id', -value=>$settings->{userid}); | ||
| 801 | $html .= hidden(-name=>'q',-value=>$seg); | ||
| 802 | $html .= hidden(-name=>'l',-value=>$labels); | ||
| 803 | $html .= hidden(-name=>'s',-value=>0); | ||
| 804 | $html .= hidden(-name=>'d',-value=>'edit'); | ||
| 805 | $html .= hidden(-name=>'m',-value=>'application/x-gff3'); | ||
| 806 | $html .= endform(); | ||
| 807 | |||
| 808 | return $html; | ||
| 809 | } | ||
| 810 | |||
| 811 | sub render_track_filter { | ||
| 812 | my $self = shift; | ||
| 813 | my $plugin = shift; | ||
| 814 | |||
| 815 | my $form = $plugin->configure_form(); | ||
| 816 | my $plugin_type = $plugin->type; | ||
| 817 | my $action = $self->translate('Configure_plugin'); | ||
| 818 | my $name = $plugin->name; | ||
| 819 | |||
| 820 | my $showfav = $self->translate('FAVORITES'); | ||
| 821 | my $showall = $self->translate('SHOWALL'); | ||
| 822 | |||
| 823 | return | ||
| 824 | div({-id=>'track select',-style=>'padding-top:8px'}, | ||
| 825 | start_form({-id => 'track_filterform', | ||
| 826 | -name => 'configure_plugin', | ||
| 827 | -onSubmit=> 'return false'}), | ||
| 828 | $form, | ||
| 829 | hidden(-name=>'plugin',-value=>$name), | ||
| 830 | button( | ||
| 831 | -name => 'plugin_button', | ||
| 832 | -value => $self->translate('search'), | ||
| 833 | -onClick => 'doPluginUpdate()', | ||
| 834 | ), | ||
| 835 | end_form(), | ||
| 836 | script({-type=>'text/javascript'}, | ||
| 837 | "function doPluginUpdate() { Controller.reconfigure_plugin('$action',null,null,'$plugin_type',\$('track_filterform'));updateTitle(\$('show_all_link'),0);}") | ||
| 838 | ); | ||
| 839 | } | ||
| 840 | |||
| 841 | # This surrounds the track table with a toggle | ||
| 842 | sub render_toggle_track_table { | ||
| 843 | my $self = shift; | ||
| 844 | my $source = $self->data_source; | ||
| 845 | my $filter = $self->track_filter_plugin; | ||
| 846 | my $settings = $self->state; | ||
| 847 | # $settings->{show_favorites} =0; | ||
| 848 | |||
| 849 | ## adding javascript array at the top so we can pass it into a js array -- ugly but it works | ||
| 850 | my $html = ''; | ||
| 851 | |||
| 852 | $html .= div({-style=>'font-weight:bold'}, | ||
| 853 | span({-style=>'padding-right:80px'},'<<',$self->render_select_browser_link('link')), | ||
| 854 | span({-id=>'showselectedtext',-style=>'padding-right:80px'},$self->render_show_active_tracks_link()), | ||
| 855 | span({-id => 'showfavoritestext',-style=>'padding-right:80px'}, | ||
| 856 | $self->render_select_favorites_link('link')), | ||
| 857 | span({-id => 'clearfavs'}, | ||
| 858 | $self->render_select_clear_link('link'))); | ||
| 859 | |||
| 860 | if (my $filter = $self->track_filter_plugin) { | ||
| 861 | $html .= $self->toggle({tight=>1},'track_select',div({class=>'searchtitle', | ||
| 862 | style=>"text-indent:2em;padding-top:8px; display:block;"}, | ||
| 863 | $self->render_track_filter($filter))); | ||
| 864 | } | ||
| 865 | |||
| 866 | $html .= $self->toggle({nodiv=>1},'Tracks',$self->render_track_table); | ||
| 867 | $html .= div({-style=>'text-align:center'},$self->render_select_browser_link('button')); | ||
| 868 | return $html; | ||
| 869 | } | ||
| 870 | |||
| 871 | sub render_track_table { | ||
| 872 | my $self = shift; | ||
| 873 | my $listing_class = $self->data_source->track_listing_class; | ||
| 874 | eval "require $listing_class;1" or die $@ unless $listing_class->can('new'); | ||
| 875 | my $tlr = $listing_class->new($self); | ||
| 876 | return $tlr->render_track_listing.$self->html_frag('html5',$self->state); | ||
| 877 | } | ||
| 878 | |||
| 879 | # Render Multiple Choices - | ||
| 880 | sub render_multiple_choices { | ||
| 881 | my $self = shift; | ||
| 882 | my $features = shift; | ||
| 883 | my $terms2hilite = shift; | ||
| 884 | my $karyotype = Bio::Graphics::Karyotype->new(source => $self->data_source, | ||
| 885 | language => $self->language); | ||
| 886 | $karyotype->add_hits($features); | ||
| 887 | return $karyotype->to_html($terms2hilite); | ||
| 888 | } | ||
| 889 | |||
| 890 | # Render Global Config - Returns the HTML for the Preferences page. | ||
| 891 | sub render_global_config { | ||
| 892 | my $self = shift; | ||
| 893 | my $settings = $self->state; | ||
| 894 | |||
| 895 | my @widths = split /\s+/, $self->setting('image widths'); | ||
| 896 | @widths = ( 640, 800, 1024 ) unless @widths; | ||
| 897 | my @key_positions = qw(between bottom); | ||
| 898 | push @key_positions, qw(left right) | ||
| 899 | if Bio::Graphics::Panel->can('auto_pad'); | ||
| 900 | |||
| 901 | my $feature_highlights = $settings->{h_feat} | ||
| 902 | ? join ' ', | ||
| 903 | map {"$_\@$settings->{h_feat}{$_}"} keys %{ $settings->{h_feat} } | ||
| 904 | : ''; | ||
| 905 | |||
| 906 | my $region_highlights = $settings->{h_region} | ||
| 907 | ? join ' ', @{ $settings->{h_region} } | ||
| 908 | : ''; | ||
| 909 | |||
| 910 | my %seen; | ||
| 911 | |||
| 912 | my $region_size = $settings->{region_size} || 0; | ||
| 913 | my @region_size = shellwords($self->data_source->global_setting('region sizes')); | ||
| 914 | my @region_sizes = grep {!$seen{$_}++} | ||
| 915 | sort {$b<=>$a} | ||
| 916 | grep {defined $_ && $_ > 0} ($region_size,@region_size); | ||
| 917 | my $content | ||
| 918 | = start_form( -name => 'display_settings', -id => 'display_settings' ) | ||
| 919 | . div( | ||
| 920 | table ({-border => 0, -cellspacing=>0, -width=>'100%'}, | ||
| 921 | TR( | ||
| 922 | |||
| 923 | td( b( checkbox( | ||
| 924 | |||
| 925 | -name => 'grid', | ||
| 926 | -label => $self->translate('SHOW_GRID'), | ||
| 927 | -override => 1, | ||
| 928 | -checked => $settings->{grid} || 0, | ||
| 929 | -onChange => 'Controller.set_display_option(this.name,this.checked ? 1 : 0)', | ||
| 930 | ) | ||
| 931 | ) | ||
| 932 | ), | ||
| 933 | td( b( $self->translate('Image_width') ), | ||
| 934 | br, | ||
| 935 | radio_group( | ||
| 936 | -name => 'width', | ||
| 937 | -values => \@widths, | ||
| 938 | -default => $settings->{width}, | ||
| 939 | -override => 1, | ||
| 940 | -onChange => 'Controller.set_display_option(this.name,this.value)', | ||
| 941 | ), | ||
| 942 | ), | ||
| 943 | td( span( | ||
| 944 | { -title => $self->translate('FEATURES_TO_HIGHLIGHT_HINT') }, | ||
| 945 | b( $self->translate('FEATURES_TO_HIGHLIGHT') ), | ||
| 946 | br, | ||
| 947 | textfield( | ||
| 948 | -id => 'h_feat', | ||
| 949 | -name => 'h_feat', | ||
| 950 | -value => $feature_highlights, | ||
| 951 | -size => 50, | ||
| 952 | -override => 1, | ||
| 953 | -onChange => 'Controller.set_display_option(this.name,this.value)', | ||
| 954 | ), | ||
| 955 | a({-href=>'javascript:void(0)', | ||
| 956 | -onClick=>'Controller.set_display_option("h_feat","_clear_");$("h_feat").value=""'}, | ||
| 957 | $self->translate('CLEAR_HIGHLIGHTING')) | ||
| 958 | ), | ||
| 959 | ), | ||
| 960 | ), | ||
| 961 | TR( | ||
| 962 | td( $self->data_source->cache_time | ||
| 963 | ? ( b( checkbox( | ||
| 964 | -name => 'cache', | ||
| 965 | -label => $self->translate('CACHE_TRACKS'), | ||
| 966 | -override => 1, | ||
| 967 | -checked => $settings->{cache}, | ||
| 968 | -onChange => 'Controller.set_display_option(this.name,this.checked?1:0)' | ||
| 969 | ) | ||
| 970 | ) | ||
| 971 | ) | ||
| 972 | : () | ||
| 973 | ), | ||
| 974 | |||
| 975 | td(' '), | ||
| 976 | |||
| 977 | td( span( | ||
| 978 | { -title => $self->translate('REGIONS_TO_HIGHLIGHT_HINT') }, | ||
| 979 | b( $self->translate('REGIONS_TO_HIGHLIGHT') ), | ||
| 980 | br, | ||
| 981 | textfield( | ||
| 982 | -id => 'h_region', | ||
| 983 | -name => 'h_region', | ||
| 984 | -value => $region_highlights, | ||
| 985 | -size => 50, | ||
| 986 | -override => 1, | ||
| 987 | -onChange => 'Controller.set_display_option(this.name,this.value)', | ||
| 988 | ), | ||
| 989 | a({-href=>'javascript:void(0)', | ||
| 990 | -onClick=>'Controller.set_display_option("h_region","_clear_");$("h_region").value=""' | ||
| 991 | }, | ||
| 992 | $self->translate('CLEAR_HIGHLIGHTING')) | ||
| 993 | ), | ||
| 994 | ), | ||
| 995 | ), | ||
| 996 | TR( | ||
| 997 | td( { -align => 'left' }, | ||
| 998 | b( checkbox( | ||
| 999 | -name => 'show_tooltips', | ||
| 1000 | -label => $self->translate('SHOW_TOOLTIPS'), | ||
| 1001 | -override => 1, | ||
| 1002 | -checked => $settings->{show_tooltips}, | ||
| 1003 | -onChange => 'Controller.set_display_option(this.name,this.checked?1:0)' | ||
| 1004 | ), | ||
| 1005 | ) | ||
| 1006 | ), | ||
| 1007 | td(' '), | ||
| 1008 | td( $self->setting('region segment') | ||
| 1009 | ? ( b( $self->translate('Region_size') ), | ||
| 1010 | br, | ||
| 1011 | popup_menu( | ||
| 1012 | -name => 'region_size', | ||
| 1013 | -default => $settings->{region_size}, | ||
| 1014 | -values => \@region_sizes, | ||
| 1015 | -override => 1, | ||
| 1016 | -onChange => 'Controller.set_display_option(this.name,this.value)', | ||
| 1017 | ), | ||
| 1018 | |||
| 1019 | ) | ||
| 1020 | : (), | ||
| 1021 | ), | ||
| 1022 | ), | ||
| 1023 | TR( | ||
| 1024 | td( { -colspan => 3, | ||
| 1025 | -align => 'right' | ||
| 1026 | }, | ||
| 1027 | b( submit( -name => $self->translate('Update_settings') ) ) | ||
| 1028 | ) | ||
| 1029 | ) | ||
| 1030 | ) | ||
| 1031 | ) . end_form(); | ||
| 1032 | |||
| 1033 | |||
| 1034 | return div($content); | ||
| 1035 | |||
| 1036 | } | ||
| 1037 | |||
| 1038 | # Clear Hilights - Returns the HTML for the "Clear Highligting" link. | ||
| 1039 | sub clear_highlights { | ||
| 1040 | my $self = shift; | ||
| 1041 | my $link = a({-style => 'font-size:9pt', | ||
| 1042 | -href => 'javascript:void(0)', | ||
| 1043 | -onClick => 'Controller.set_display_option("h_feat","_clear_");Controller.set_display_option("h_region","_clear_")' | ||
| 1044 | }, | ||
| 1045 | $self->translate('CLEAR_HIGHLIGHTING')); | ||
| 1046 | } | ||
| 1047 | |||
| 1048 | # Render Select Track Link - Returns the HTML for the "Select Tracks" button on the main browser page. | ||
| 1049 | sub render_select_track_link { | ||
| 1050 | my $self = shift; | ||
| 1051 | my $title = $self->translate('SELECT_TRACKS'); | ||
| 1052 | return button({-name=>$title, | ||
| 1053 | -onClick => "Controller.select_tab('track_page')", | ||
| 1054 | |||
| 1055 | } | ||
| 1056 | ); | ||
| 1057 | } | ||
| 1058 | |||
| 1059 | sub render_select_clear_link { | ||
| 1060 | my $self = shift; | ||
| 1061 | |||
| 1062 | my $title = $self->translate('CLEAR_FAV'); | ||
| 1063 | my $settings = $self->state; | ||
| 1064 | my $clear = 1; | ||
| 1065 | |||
| 1066 | warn "settings $settings->{show_favorites}" if DEBUG; | ||
| 1067 | my $showicon = img({-src => $self->data_source->button_url."/ficon.png",-border=>0}); | ||
| 1068 | return span(a({-href=>'javascript:void(0)', | ||
| 1069 | -onClick => "clearallfav($clear);", | ||
| 1070 | }, | ||
| 1071 | $title),$showicon); | ||
| 1072 | } | ||
| 1073 | |||
| 1074 | sub render_show_active_tracks_link { | ||
| 1075 | my $self = shift; | ||
| 1076 | my $active = $self->state->{active_only} ? 'true' : 'false'; | ||
| 1077 | return a({-href => 'javascript:void(0)', | ||
| 1078 | -class => $active ? 'show_active' : 'inactive', | ||
| 1079 | -onClick => "show_active_tracks(this,$active)"}, | ||
| 1080 | $self->translate('SHOW_ACTIVE_TRACKS')); | ||
| 1081 | } | ||
| 1082 | |||
| 1083 | sub render_select_favorites_link { | ||
| 1084 | my $self = shift; | ||
| 1085 | |||
| 1086 | my $showfav = $self->translate('FAVORITES'); | ||
| 1087 | my $showall = $self->translate('SHOWALL'); | ||
| 1088 | my $refresh = 'showrefresh'; | ||
| 1089 | my $settings = $self->state; | ||
| 1090 | |||
| 1091 | my $ison = $settings->{show_favorites}; | ||
| 1092 | my $title = $ison ? $showall : $showfav; | ||
| 1093 | my $showicon = img({-src => $self->data_source->button_url."/ficon_2.png",-border=>0}); | ||
| 1094 | |||
| 1095 | warn "settings $settings->{show_favorites}" if DEBUG; | ||
| 1096 | warn "ison = $settings->{show_favorites}" if DEBUG; | ||
| 1097 | return span(a({-id => 'show_all_link', | ||
| 1098 | -class => $settings->{show_favorites} ? 'favorites_only' : '', | ||
| 1099 | -href =>'javascript:void(0)', | ||
| 1100 | -onClick => "updateTitle(this)" | ||
| 1101 | },$title),$showicon); | ||
| 1102 | } | ||
| 1103 | |||
| 1104 | |||
| 1105 | # Render Select Browser Link - Returns the HTML for the "Back to Browser" button/link. | ||
| 1106 | sub render_select_browser_link { | ||
| 1107 | my $self = shift; | ||
| 1108 | my $style = shift || 'button'; | ||
| 1109 | my $settings = $self->state; | ||
| 1110 | my $title = $self->translate('BACK_TO_BROWSER'); | ||
| 1111 | if ($style eq 'button') { | ||
| 1112 | return button({-name=>$title, | ||
| 1113 | -onClick => "Controller.select_tab('main_page')", | ||
| 1114 | } | ||
| 1115 | ); | ||
| 1116 | } elsif ($style eq 'link') { | ||
| 1117 | return a({-href=>'javascript:void(0)', | ||
| 1118 | -onClick => "Controller.select_tab('main_page')"}, | ||
| 1119 | $title); | ||
| 1120 | } | ||
| 1121 | } | ||
| 1122 | |||
| 1123 | # Render Community Tracks Section - Returns the content of the "Community Tracks" tab. | ||
| 1124 | sub render_community_tracks_section { | ||
| 1125 | my $self = shift; | ||
| 1126 | my $userdata = $self->user_tracks; | ||
| 1127 | my $html = $self->is_admin? h2({-style=>'font-style:italic;background-color:yellow'}, $self->translate('ADMIN_MODE_WARNING')) : ""; | ||
| 1128 | $html .= div({-id => "community_tracks"}, $self->render_community_track_listing); | ||
| 1129 | $html = div({-style => 'margin: 1em;'}, $html); | ||
| 1130 | return $html; | ||
| 1131 | } | ||
| 1132 | |||
| 1133 | # Render Custom Tracks Section - Returns the content of the "Custom Tracks" tab. | ||
| 1134 | sub render_custom_tracks_section { | ||
| 1135 | my $self = shift; | ||
| 1136 | my $userdata = $self->user_tracks; | ||
| 1137 | my $html = $self->is_admin? h2({-style=>'font-style:italic;background-color:yellow'}, $self->translate('ADMIN_MODE_WARNING')) : ""; | ||
| 1138 | $html .= div({-id => "custom_tracks"}, $self->render_custom_track_listing); | ||
| 1139 | $html .= $self->userdata_upload; | ||
| 1140 | $html = div({-style => 'margin: 1em;'}, $html); | ||
| 1141 | return $html; | ||
| 1142 | } | ||
| 1143 | |||
| 1144 | # Userdata Upload - Renders an "Add custom tracks" links in the Uploaded Tracks section. | ||
| 1145 | sub userdata_upload { | ||
| 1146 | my $self = shift; | ||
| 1147 | my $url = url(-absolute=>1,-path_info=>1); | ||
| 1148 | |||
| 1149 | my $html = ''; | ||
| 1150 | my $upload_label = $self->translate('UPLOAD_FILE'); | ||
| 1151 | my $mirror_label = $self->translate('MIRROR_FILE'); | ||
| 1152 | my $remove_label = $self->translate('REMOVE'); | ||
| 1153 | my $new_label = $self->translate('NEW_TRACK'); | ||
| 1154 | my $from_text = $self->translate('FROM_TEXT'); | ||
| 1155 | my $from_file = $self->translate('FROM_FILE'); | ||
| 1156 | my $from_url = $self->translate('FROM_URL'); | ||
| 1157 | my $help_link = $self->annotation_help; | ||
| 1158 | $html .= p({-style=>'margin-left:10pt;font-weight:bold'}, | ||
| 1159 | $self->translate('ADD_YOUR_OWN_TRACKS') ,':', | ||
| 1160 | a({-href=>"javascript:addAnUploadField('custom_list_start', '$url', '$new_label', '$remove_label', 'edit','$help_link')"}, | ||
| 1161 | "[$from_text]"), | ||
| 1162 | a({-href=>"javascript:addAnUploadField('custom_list_start', '$url', '$mirror_label', '$remove_label', 'url','$help_link')"}, | ||
| 1163 | "[$from_url]"), | ||
| 1164 | a({-href=>"javascript:addAnUploadField('custom_list_start', '$url','$upload_label', '$remove_label' , 'upload','$help_link')", | ||
| 1165 | -id=>'file_adder', | ||
| 1166 | },"[$from_file]")); | ||
| 1167 | $html .= div({-id=>'custom_list_start'},''); | ||
| 1168 | return $html; | ||
| 1169 | } | ||
| 1170 | |||
| 1171 | # Render Community Track Listing - Returns the HTML listing of public tracks available to a user. | ||
| 1172 | sub render_community_track_listing { | ||
| 1173 | my $self = shift; | ||
| 1174 | my $globals = $self->globals; | ||
| 1175 | my $html = h1({-style => "display: inline-block; margin-right: 1em;"}, $self->translate('COMMUNITY_TRACKS')); | ||
| 1176 | my $search = $_[0] || ""; | ||
| 1177 | my $offset = $_[1] || 0; | ||
| 1178 | my $usertracks = $self->user_tracks; | ||
| 1179 | |||
| 1180 | my @requested_tracks = $usertracks->get_public_files(@_) if @_; | ||
| 1181 | |||
| 1182 | # Calculate the value for the next pagination | ||
| 1183 | my $max_files = $globals->public_files; | ||
| 1184 | my $total_tracks = $usertracks->public_count($search); | ||
| 1185 | my $track_limit = $search? @requested_tracks : $max_files; | ||
| 1186 | my $tracks_displayed = ($track_limit < (@requested_tracks? @requested_tracks : $total_tracks)) | ||
| 1187 | ? $track_limit : (@requested_tracks? @requested_tracks : $total_tracks); | ||
| 1188 | my $tracks_remaining = $total_tracks - ($offset + $tracks_displayed); | ||
| 1189 | my $tracks_before = $offset; | ||
| 1190 | |||
| 1191 | my $tracks_next = ($track_limit < $tracks_remaining)? $track_limit : $tracks_remaining; | ||
| 1192 | my $next_offset = $offset + $track_limit; | ||
| 1193 | my $tracks_previous = ($max_files < $tracks_before)? $max_files : $tracks_before; | ||
| 1194 | my $previous_offset = $offset - $globals->public_files; | ||
| 1195 | $previous_offset = 0 if $previous_offset < 0; | ||
| 1196 | |||
| 1197 | my $first_number = $offset + 1; | ||
| 1198 | my $last_number = $offset + $tracks_displayed; | ||
| 1199 | |||
| 1200 | my $autocomplete = ''; | ||
| 1201 | |||
| 1202 | if ($self->setting('autocomplete')) { | ||
| 1203 | my $spinner_url = $self->data_source->button_url.'/spinner.gif'; | ||
| 1204 | $autocomplete = <<END | ||
| 1205 | <span id="indicator2" style="display: none"> | ||
| 1206 | <img src="$spinner_url" /> | ||
| 1207 | </span> | ||
| 1208 | <div id="autocomplete_upload_filter" class="autocomplete"></div> | ||
| 1209 | END | ||
| 1210 | } | ||
| 1211 | |||
| 1212 | # Create the HTML for the title & header | ||
| 1213 | $html .= span({-style => "display: inline-block;"}, | ||
| 1214 | start_form({-action => "javascript:void(0);", | ||
| 1215 | # The return here is necessary to stop the form from ACTUALLY submitting. | ||
| 1216 | -onsubmit => "return searchPublic(\$('public_search_keyword').value);" | ||
| 1217 | }), | ||
| 1218 | input({-type => "hidden", -name => "offset", | ||
| 1219 | -value => $offset, -id => "community_display_offset"}), | ||
| 1220 | ucfirst $self->translate('FILTER') . ":", | ||
| 1221 | input({ | ||
| 1222 | -type => "text", | ||
| 1223 | -name => "keyword", | ||
| 1224 | -id => "public_search_keyword", | ||
| 1225 | -style => "width:200px", | ||
| 1226 | -value => $search || ($self->globals->user_accounts? $self->translate('ENTER_KEYWORD') . | ||
| 1227 | " " . $self->translate('OR_USER') : $self->translate('ENTER_KEYWORD')), | ||
| 1228 | -onClick => "this.value='';" | ||
| 1229 | }), | ||
| 1230 | input({-type => "submit", -value => "Search"}), | ||
| 1231 | ($tracks_previous > 0)? a({-href => '#', | ||
| 1232 | -onClick => "return searchPublic(\"$search\", $previous_offset);"}, | ||
| 1233 | "[" . $self->translate('PREVIOUS_N', $tracks_previous) . "]") . " " : "", | ||
| 1234 | button(-label=>$self->tr('CLEAR'), | ||
| 1235 | -onClick=>"\$('public_search_keyword').value='';searchPublic('',$previous_offset);"), | ||
| 1236 | ucfirst $self->translate('SHOWING'). " " | ||
| 1237 | . (($total_tracks > 0)? $self->translate('N_TO_N_OUT_OF', $first_number, $last_number) : "") . " " | ||
| 1238 | . $self->translate('N_FILES', $total_tracks) | ||
| 1239 | . ($search? (" " . $self->translate("MATCHING", $search)) : "") | ||
| 1240 | . ".", | ||
| 1241 | ($tracks_next > 0)? " " . a({-href => '#', -onClick => "return searchPublic(\"$search\", $next_offset);"}, | ||
| 1242 | "[" . $self->translate('NEXT_N', $tracks_next) . "]") : "", | ||
| 1243 | end_form(), | ||
| 1244 | $autocomplete | ||
| 1245 | ); | ||
| 1246 | |||
| 1247 | # Add the results | ||
| 1248 | if ($search || $offset) { | ||
| 1249 | $html .= @requested_tracks | ||
| 1250 | ? $self->list_tracks("public", @requested_tracks) | ||
| 1251 | : p($self->translate('NO_PUBLIC_RESULTS', $search)); | ||
| 1252 | } else { | ||
| 1253 | $html .= $self->list_tracks("public"); | ||
| 1254 | } | ||
| 1255 | return $html; | ||
| 1256 | } | ||
| 1257 | |||
| 1258 | # Render Custom Track Listing - Returns the HTML listing of public, uploaded, imported and shared tracks added to a session, and a section to add more. | ||
| 1259 | sub render_custom_track_listing { | ||
| 1260 | my $self = shift; | ||
| 1261 | my $html = h1($self->translate('UPLOADED_TRACKS')); | ||
| 1262 | |||
| 1263 | $html .= a( { | ||
| 1264 | -href => $self->annotation_help, | ||
| 1265 | -target => '_blank' | ||
| 1266 | }, | ||
| 1267 | i('['.$self->translate('HELP_FORMAT_UPLOAD').']') | ||
| 1268 | ); | ||
| 1269 | $html .= $self->list_tracks; | ||
| 1270 | return $html; | ||
| 1271 | } | ||
| 1272 | |||
| 1273 | # List Tracks - Renders a visual listing of an array of tracks. No arguments creates the standard "my tracks" listing. | ||
| 1274 | sub list_tracks { | ||
| 1275 | my $self = shift; | ||
| 1276 | my $userdata = $self->user_tracks; | ||
| 1277 | my $listing_type = shift || ""; | ||
| 1278 | # If we've been given input, use the input. | ||
| 1279 | # If we've been given the public type, use that, or default to all of the current user's tracks. | ||
| 1280 | my @tracks = @_? @_ | ||
| 1281 | : (($listing_type =~ /public/) && ($userdata->database == 1)) | ||
| 1282 | ? $userdata->get_public_files | ||
| 1283 | : $userdata->tracks; | ||
| 1284 | my $track_type = $listing_type; | ||
| 1285 | |||
| 1286 | $track_type .= " available" if $listing_type =~ /public/; | ||
| 1287 | |||
| 1288 | # Main track roll code. | ||
| 1289 | if (@tracks) { | ||
| 1290 | my $count = 0; | ||
| 1291 | my @rows = map { | ||
| 1292 | my $fileid = $_; | ||
| 1293 | my $type = $track_type || $userdata->file_type($fileid); | ||
| 1294 | |||
| 1295 | my $class = $self->track_class($count, $type); | ||
| 1296 | my $controls = $self->render_track_controls($fileid, $type); | ||
| 1297 | my $short_listing = $self->render_track_list_title($fileid, $type); | ||
| 1298 | my $details = $self->render_track_details($fileid, @tracks? 1 : 0); | ||
| 1299 | my $edit_field = div({-id => $fileid . "_editfield", -style => "display: none;"}, ''); | ||
| 1300 | $count++; | ||
| 1301 | div({ | ||
| 1302 | -id => "$fileid", | ||
| 1303 | -class => "custom_track $class", | ||
| 1304 | -style => 'padding: 0.5em', | ||
| 1305 | }, | ||
| 1306 | $controls, | ||
| 1307 | $short_listing, | ||
| 1308 | $details, | ||
| 1309 | $edit_field | ||
| 1310 | ); | ||
| 1311 | } @tracks; | ||
| 1312 | return join '', @rows; | ||
| 1313 | } else { | ||
| 1314 | return p($self->translate(($track_type =~ /public/i ? 'THERE_ARE_NO_AVAILABLE_TRACKS':'THERE_ARE_NO_TRACKS_YET'), $track_type)); | ||
| 1315 | } | ||
| 1316 | } | ||
| 1317 | |||
| 1318 | # Track Class (Count, Type) - Returns the class for a specific custom track. | ||
| 1319 | sub track_class { | ||
| 1320 | my $self = shift; | ||
| 1321 | my $count = shift; | ||
| 1322 | my $type = shift; | ||
| 1323 | $type =~ s/\s?available//; | ||
| 1324 | return $type . "_" . (($count % 2)? "even" : "odd"); | ||
| 1325 | } | ||
| 1326 | |||
| 1327 | # Render Track List Title (Track, Type) - Renders the visible HTML which is seen when the details are hidden. | ||
| 1328 | sub render_track_list_title { | ||
| 1329 | my $self = shift; | ||
| 1330 | my $fileid = shift; | ||
| 1331 | my $type = shift; | ||
| 1332 | $type =~ s/\s?available//; | ||
| 1333 | my $userdata = $self->user_tracks; | ||
| 1334 | my $globals = $self->globals; | ||
| 1335 | |||
| 1336 | my $short_name = $userdata->title($fileid); | ||
| 1337 | if ($short_name =~ /http_([^_]+).+_gbgff_.+_t_(.+)_s_/) { | ||
| 1338 | my @tracks = split /\+/, $2; | ||
| 1339 | $short_name = "Shared track from $1 (@tracks)"; | ||
| 1340 | } elsif (length $short_name > 40) { | ||
| 1341 | $short_name =~ s/^(.{40}).+/$1.../; | ||
| 1342 | } | ||
| 1343 | |||
| 1344 | my $is_mine = $userdata->is_mine($fileid); | ||
| 1345 | my $cursor = $is_mine ? 'cursor:pointer' : 'cursor:auto'; | ||
| 1346 | my $uploaddb = $userdata->database; | ||
| 1347 | |||
| 1348 | my @track_labels = $userdata->labels($fileid); | ||
| 1349 | my $track_labels = join '+', map {CGI::escape($_)} @track_labels; | ||
| 1350 | my $source_note = span({-class => "source_note"}, $type); | ||
| 1351 | my $go_there = join(' ', | ||
| 1352 | map { | ||
| 1353 | my $label = $_; | ||
| 1354 | my $go_there_script = "Controller.select_tab('main_page',false);Controller.scroll_to_matching_track('$label')"; | ||
| 1355 | my $edit_label_script = "Controller.edit_upload_track_key('$fileid', '$label', this)"; | ||
| 1356 | my $script = $is_mine ? "if (event.shiftKey || event.ctrlKey) {$edit_label_script} else {$go_there_script}" | ||
| 1357 | : $go_there_script; | ||
| 1358 | my $key = $self->data_source->setting($label=>'key'); | ||
| 1359 | $key? ( | ||
| 1360 | '['. | ||
| 1361 | span({-class => 'clickable', | ||
| 1362 | -onClick => $script, | ||
| 1363 | -contentEditable => ($is_mine ? 'true' : 'false'), | ||
| 1364 | }, | ||
| 1365 | b($key) | ||
| 1366 | ). | ||
| 1367 | ']' | ||
| 1368 | ) : '' | ||
| 1369 | } @track_labels); | ||
| 1370 | my $stat = div( | ||
| 1371 | { | ||
| 1372 | -id => $fileid . "_stat", | ||
| 1373 | -style=> "display: inline;" | ||
| 1374 | }, | ||
| 1375 | '' | ||
| 1376 | ); | ||
| 1377 | my $title = h1( | ||
| 1378 | { | ||
| 1379 | ($is_mine ? (-title => $self->tr('ADD_TITLE')) : ()), | ||
| 1380 | -style => "display: inline; font-size: 14pt;$cursor", | ||
| 1381 | -onClick => ($uploaddb && $is_mine)? "Controller.edit_upload_title('$fileid', this)" : "", | ||
| 1382 | -contentEditable => ($uploaddb && $is_mine)? 'true' : 'false', | ||
| 1383 | }, | ||
| 1384 | $short_name | ||
| 1385 | ); | ||
| 1386 | my $owner; | ||
| 1387 | if ($globals->user_accounts) { | ||
| 1388 | my $owner_name = $userdata->owner_name($fileid); | ||
| 1389 | my $users = $self->userdb; | ||
| 1390 | my ($fullname,$email) = $users->accountinfo_from_username($owner_name); | ||
| 1391 | $email ||= ''; | ||
| 1392 | my $email_link = a({-href=>"mailto:$email"},$email); | ||
| 1393 | $fullname ||= $owner_name; | ||
| 1394 | $owner = $self->translate("UPLOADED_BY") . " " . b($fullname).($email ? " <${email_link}>" : ''); | ||
| 1395 | } else { | ||
| 1396 | $owner = ''; | ||
| 1397 | } | ||
| 1398 | |||
| 1399 | return span( | ||
| 1400 | {-style => "display: inline;"}, | ||
| 1401 | $stat, | ||
| 1402 | $title, | ||
| 1403 | $owner, | ||
| 1404 | br(), | ||
| 1405 | $go_there, | ||
| 1406 | ) . $source_note; | ||
| 1407 | } | ||
| 1408 | |||
| 1409 | # Render Track Controls (Track Name, Type) - Renders the HTML for the main track controls in the custom track listing. | ||
| 1410 | sub render_track_controls { | ||
| 1411 | my $self = shift; | ||
| 1412 | my $fileid = shift; | ||
| 1413 | my $type = shift; | ||
| 1414 | my $userdata = $self->user_tracks; | ||
| 1415 | my $userid = $userdata->{userid}||''; | ||
| 1416 | my @track_labels = $userdata->labels($fileid); | ||
| 1417 | my $track_labels = join '+', map {CGI::escape($_)} @track_labels; | ||
| 1418 | my $globals = $self->globals; | ||
| 1419 | |||
| 1420 | my $buttons = $self->data_source->globals->button_url; | ||
| 1421 | |||
| 1422 | my $controls; | ||
| 1423 | # Conditional controls, based on the type of track. | ||
| 1424 | if ($userdata->is_mine($fileid)) { | ||
| 1425 | # The delete icon, | ||
| 1426 | $controls .= ' ' . img( | ||
| 1427 | { | ||
| 1428 | -src => "$buttons/trash.png", | ||
| 1429 | -style => 'cursor:pointer', | ||
| 1430 | -onMouseOver => 'GBubble.showTooltip(event,"'.$self->translate('DELETE').'",0)', | ||
| 1431 | -onClick => "deleteUpload('$fileid')" | ||
| 1432 | } | ||
| 1433 | ); | ||
| 1434 | # The sharing icon, if it's an upload. | ||
| 1435 | $controls .= ' ' . img( | ||
| 1436 | { | ||
| 1437 | -src => "$buttons/share.png", | ||
| 1438 | -style => 'cursor:pointer', | ||
| 1439 | -onMouseOver => 'GBubble.showTooltip(event,"'.$self->translate('SHARE_WITH_OTHERS').'",0)', | ||
| 1440 | -onClick => "Controller.get_sharing(event,'url:?action=share_track;track=$track_labels')" | ||
| 1441 | } | ||
| 1442 | ) if ($type =~ /upload/ && !$userdata->database); | ||
| 1443 | } | ||
| 1444 | if ($type !~ /available/) { | ||
| 1445 | if ($type =~ /(public|shared)/) { | ||
| 1446 | # The "remove" [x] link. | ||
| 1447 | $controls .= ' ' . a( | ||
| 1448 | { | ||
| 1449 | -href => "javascript: void(0)", | ||
| 1450 | -onMouseOver => 'GBubble.showTooltip(event,"'.$self->translate('REMOVE_FROM_MY_SESSION').'",0,200)', | ||
| 1451 | -onClick => "unshareFile('$fileid', '$userid')" | ||
| 1452 | }, | ||
| 1453 | "[X]" | ||
| 1454 | ); | ||
| 1455 | } | ||
| 1456 | } else { | ||
| 1457 | $userid ||= ''; | ||
| 1458 | $controls .= ' ' . a( | ||
| 1459 | { | ||
| 1460 | -href => "javascript:void(0);", | ||
| 1461 | -onClick => "shareFile('$fileid', '$userid')" | ||
| 1462 | }, | ||
| 1463 | '['.$self->translate('SHARING_ADD_USER').']' | ||
| 1464 | ); | ||
| 1465 | } | ||
| 1466 | |||
| 1467 | return span( | ||
| 1468 | { | ||
| 1469 | -class => "controls", | ||
| 1470 | -style => "display: inline; padding: 0.3em;" | ||
| 1471 | }, $controls | ||
| 1472 | ); | ||
| 1473 | } | ||
| 1474 | |||
| 1475 | # Render Track Details (Track Name, Display?) - Renders the track listing details section. | ||
| 1476 | sub render_track_details { | ||
| 1477 | my $self = shift; | ||
| 1478 | my $fileid = shift; | ||
| 1479 | my $display = shift || 0; | ||
| 1480 | my $userdata = $self->user_tracks; | ||
| 1481 | my $globals = $self->globals; | ||
| 1482 | my $random_id = 'upload_'.int rand(9999); | ||
| 1483 | my $is_mine = $userdata->is_mine($fileid); | ||
| 1484 | my $cursor = $is_mine ? 'cursor:pointer' : 'cursor:auto'; | ||
| 1485 | my $description = div( | ||
| 1486 | { | ||
| 1487 | ($is_mine ? (-title => $self->tr('ADD_DESCRIPTION')) : ()), | ||
| 1488 | -style => $cursor, | ||
| 1489 | -id => $fileid . "_description", | ||
| 1490 | -onClick => $is_mine ? "Controller.edit_upload_description('$fileid', this)" : "", | ||
| 1491 | -contentEditable => $is_mine ? 'true' : 'false', | ||
| 1492 | }, | ||
| 1493 | $userdata->description($fileid) || $self->translate($is_mine ? 'ADD_DESCRIPTION' : 'NO_DESCRIPTION') | ||
| 1494 | ); | ||
| 1495 | my $source_listing = div( | ||
| 1496 | {-style => "margin-left: 2em; display: inline-block;"}, | ||
| 1497 | $self->render_track_source_files($fileid) | ||
| 1498 | ); | ||
| 1499 | my $sharing = ($userdata->database == 1)? div( | ||
| 1500 | { | ||
| 1501 | -style => "margin-left: 2em; display: inline;", | ||
| 1502 | -class => "sharing" | ||
| 1503 | }, | ||
| 1504 | $self->render_track_sharing($fileid) | ||
| 1505 | ) : ""; | ||
| 1506 | |||
| 1507 | my $status = $userdata->status($fileid) || 'complete'; | ||
| 1508 | my $status_box = div( | ||
| 1509 | div({-id=>"${random_id}_form", -style=>"display: none;"},' '), | ||
| 1510 | div({-id=>"${random_id}_status", -style=>"display: none;"}, | ||
| 1511 | i($status), | ||
| 1512 | a( | ||
| 1513 | { | ||
| 1514 | -href =>'javascript:void(0)', | ||
| 1515 | -onClick => "Controller.monitor_upload('$random_id','$fileid')", | ||
| 1516 | }, | ||
| 1517 | $self->translate('INTERRUPTED_RESUME') | ||
| 1518 | ) | ||
| 1519 | ) | ||
| 1520 | ); | ||
| 1521 | |||
| 1522 | return div( | ||
| 1523 | { | ||
| 1524 | -style => $display? "display: block;" : "display: none;", | ||
| 1525 | -class => "details" | ||
| 1526 | }, | ||
| 1527 | i($description), | ||
| 1528 | $source_listing, | ||
| 1529 | br(), | ||
| 1530 | $sharing, | ||
| 1531 | $status_box | ||
| 1532 | ); | ||
| 1533 | } | ||
| 1534 | |||
| 1535 | # Render Track Source Files (Track) - Renders the HTML listing of a track's source files. | ||
| 1536 | sub render_track_source_files { | ||
| 1537 | my $self = shift; | ||
| 1538 | my $fileid = shift; | ||
| 1539 | my $userdata = $self->user_tracks(); | ||
| 1540 | my @source_files = $userdata->source_files($fileid); | ||
| 1541 | my ($conf_name, $conf_modified, $conf_size) = $userdata->conf_metadata($fileid); | ||
| 1542 | $conf_modified ||= 0; | ||
| 1543 | $conf_size ||=0; | ||
| 1544 | my $mirror_url = $userdata->is_mirrored($fileid); | ||
| 1545 | my $source_listing = | ||
| 1546 | b($self->translate('SOURCE_FILES')) . | ||
| 1547 | ul( | ||
| 1548 | {-style => "margin: 0; padding: 0; list-style: none;"}, | ||
| 1549 | li( | ||
| 1550 | [map { | ||
| 1551 | a( { | ||
| 1552 | -href => $mirror_url || "?userdata_download=$_->[0];track=$fileid", | ||
| 1553 | -style => "display: inline-block; width: 30em; overflow: hidden;" | ||
| 1554 | }, | ||
| 1555 | $_->[0] | ||
| 1556 | ). | ||
| 1557 | span({-style => "display: inline-block; width: 15em;"}, scalar localtime($_->[2])). | ||
| 1558 | span({-style => "display: inline-block; width: 10em;"}, $_->[1],'bytes'). | ||
| 1559 | span( | ||
| 1560 | ($_->[1] <= MAXIMUM_EDITABLE_UPLOAD && -T $_->[3] && $userdata->is_mine($fileid))? | ||
| 1561 | $mirror_url? | ||
| 1562 | a( { | ||
| 1563 | -href => "javascript:void(0)", | ||
| 1564 | -onClick => "reloadURL('$fileid','$mirror_url')" | ||
| 1565 | }, | ||
| 1566 | $self->translate('RELOAD_FROM', $mirror_url) | ||
| 1567 | ) : | ||
| 1568 | a( { | ||
| 1569 | -href => "javascript:void(0)", | ||
| 1570 | -onClick => "editUploadData('$fileid','$_->[0]')" | ||
| 1571 | }, | ||
| 1572 | $self->translate('EDIT_BUTTON') | ||
| 1573 | ) | ||
| 1574 | : ' ' | ||
| 1575 | ) | ||
| 1576 | } @source_files] | ||
| 1577 | ), | ||
| 1578 | li( | ||
| 1579 | a( { | ||
| 1580 | -href => "?userdata_download=conf;track=$fileid", | ||
| 1581 | -style => "display: inline-block; width: 30em;" | ||
| 1582 | }, | ||
| 1583 | $self->translate('CONFIGURATION') | ||
| 1584 | ). | ||
| 1585 | span({-style => "display: inline-block; width: 15em;"}, scalar localtime $conf_modified). | ||
| 1586 | span({-style => "display: inline-block; width: 10em;"}, "$conf_size bytes"). | ||
| 1587 | span( | ||
| 1588 | ($userdata->is_mine($fileid)) | ||
| 1589 | ? a({ | ||
| 1590 | -href => "javascript:void(0)", | ||
| 1591 | -onClick => "editUploadConf('$fileid')" | ||
| 1592 | }, $self->translate('EDIT_BUTTON') | ||
| 1593 | ) | ||
| 1594 | : " " | ||
| 1595 | ) | ||
| 1596 | ) | ||
| 1597 | ); | ||
| 1598 | return $source_listing; | ||
| 1599 | } | ||
| 1600 | |||
| 1601 | # Render Track Sharing (Track) - Renders the HTML listing of a track's sharing properties. | ||
| 1602 | sub render_track_sharing { | ||
| 1603 | my $self = shift; | ||
| 1604 | my $fileid = shift; | ||
| 1605 | my $globals = $self->globals; | ||
| 1606 | my $userdb = $self->userdb if $globals->user_accounts; | ||
| 1607 | my $userdata = $self->user_tracks; | ||
| 1608 | |||
| 1609 | #Building the users list. | ||
| 1610 | my $sharing_policy = $userdata->permissions($fileid); | ||
| 1611 | my @users = $userdata->shared_with($fileid); | ||
| 1612 | $_ = b(($globals->user_accounts) | ||
| 1613 | ? $userdb->username_from_userid($_) : "an anonymous user") . | ||
| 1614 | " " . | ||
| 1615 | a({-href => "javascript:void(0)", -onClick => "unshareFile('$fileid', '$_')"}, "[X]") . "" foreach @users; | ||
| 1616 | my $userlist = join (", ", @users); | ||
| 1617 | |||
| 1618 | my $sharing_content = b($self->translate('SHARING')) . br() . $self->translate('TRACK_IS') . " "; | ||
| 1619 | if ($userdata->is_mine($fileid) == 0) { | ||
| 1620 | my $count = ($sharing_policy eq "public")? $userdata->public_users($fileid) : $userdata->shared_with($fileid); | ||
| 1621 | $sharing_content .= b(($sharing_policy =~ /(casual|group)/)? lc $self->translate('SHARED_WITH_YOU') : lc $self->translate('SHARING_PUBLIC')); | ||
| 1622 | $sharing_content .= ", " . $self->translate('USED_BY') . " " . ($count? b($count) . " " . $self->translate('USERS') . "." : $self->translate('NO_ONE')) unless $sharing_policy =~ /casual/; | ||
| 1623 | } else { | ||
| 1624 | my %sharing_type_labels = ( private => $self->translate('SHARING_PRIVATE'), | ||
| 1625 | casual => $self->translate('SHARING_CASUAL') , | ||
| 1626 | group => $self->translate('SHARING_GROUP') , | ||
| 1627 | public => $self->translate('SHARING_PUBLIC') ); | ||
| 1628 | $sharing_content .= Select( | ||
| 1629 | {-onChange => "changePermissions('$fileid', this.options[this.selectedIndex].value.toLowerCase())"}, | ||
| 1630 | map { | ||
| 1631 | option( | ||
| 1632 | { | ||
| 1633 | -value => $_, | ||
| 1634 | ($sharing_policy =~ /$_/i)? (-selected => "selected") : () | ||
| 1635 | }, | ||
| 1636 | $sharing_type_labels{$_} | ||
| 1637 | ) | ||
| 1638 | } keys %sharing_type_labels | ||
| 1639 | ); | ||
| 1640 | |||
| 1641 | my $sharing_help = $self->translate('SHARING_HELP'); | ||
| 1642 | |||
| 1643 | $sharing_content .= " " . a({-href => "javascript:void(0)", | ||
| 1644 | -onMouseOver => "GBubble.showTooltip(event,'$sharing_help',0,300);"}, | ||
| 1645 | "[?]"); | ||
| 1646 | $sharing_content .= " " . $self->translate('SHARED_WITH') . | ||
| 1647 | " " . ($userlist? "$userlist" : $self->translate('NO_ONE') | ||
| 1648 | ) if ($sharing_policy =~ /(casual|group)/); | ||
| 1649 | if ($sharing_policy =~ /public/) { | ||
| 1650 | my $count = $userdata->public_users($fileid); | ||
| 1651 | $sharing_content .= " " . | ||
| 1652 | $self->translate('USED_BY') . | ||
| 1653 | " " . ($count? b($count) . | ||
| 1654 | " " . $self->translate('USERS') . "." : $self->translate('NO_ONE')); | ||
| 1655 | } | ||
| 1656 | |||
| 1657 | if ($sharing_policy =~ /casual/) { | ||
| 1658 | my $sharing_url = $userdata->sharing_link($fileid); | ||
| 1659 | my $sharing_link = a({-href => $sharing_url}, $sharing_url); | ||
| 1660 | $sharing_content .= br() . $self->translate('SHARE_WITH_THIS_LINK'); | ||
| 1661 | $sharing_content .= $sharing_link; | ||
| 1662 | } | ||
| 1663 | |||
| 1664 | if ($sharing_policy =~ /group/) { | ||
| 1665 | my $id = 'username_entry_'.int(rand(100000)); | ||
| 1666 | my $add_box = " " . input( | ||
| 1667 | { | ||
| 1668 | -length => 60, | ||
| 1669 | -style => 'width:300px', | ||
| 1670 | -class => 'username_entry', | ||
| 1671 | -id => $id, | ||
| 1672 | -value => $self->translate('ENTER_SOMETHING_HERE', | ||
| 1673 | (($globals->user_accounts) | ||
| 1674 | ? $self->translate('USERNAME_OR_USER_ID') | ||
| 1675 | : $self->translate('USER_ID'))), | ||
| 1676 | -onFocus => "this.clear()" | ||
| 1677 | }); | ||
| 1678 | my $add_autocomplete = div({-id=>"${id}_choices", | ||
| 1679 | -class=>'autocomplete usersearch'},'') if $self->setting('autocomplete'); | ||
| 1680 | my $add_link = " " . a( | ||
| 1681 | { | ||
| 1682 | -href => "javascript: void(0)", | ||
| 1683 | -onClick => "shareFile('$fileid', this.previous('input').getValue())", | ||
| 1684 | }, | ||
| 1685 | $self->translate('ADD_BUTTON') ); | ||
| 1686 | $sharing_content .= $add_box . $add_autocomplete . $add_link; | ||
| 1687 | }; | ||
| 1688 | } | ||
| 1689 | return $sharing_content; | ||
| 1690 | } | ||
| 1691 | |||
| 1692 | sub segment2link { | ||
| 1693 | my $self = shift; | ||
| 1694 | |||
| 1695 | my ($segment,$label) = @_; | ||
| 1696 | |||
| 1697 | my $source = $self->data_source; | ||
| 1698 | return a({-href=>"?name=$segment"},$segment) unless ref $segment; | ||
| 1699 | |||
| 1700 | my $ref = $segment->seq_id; | ||
| 1701 | my ($start,$stop) = ($segment->start,$segment->end); | ||
| 1702 | my $bp = $stop - $start; | ||
| 1703 | $label ||= segment_str($segment); | ||
| 1704 | $ref||=''; # get rid of uninit warnings | ||
| 1705 | return a({-href=>"?ref=$ref;start=$start;stop=$stop"},$label); | ||
| 1706 | } | ||
| 1707 | |||
| 1708 | sub tableize { | ||
| 1709 | my $self = shift; | ||
| 1710 | my ($array,$cols,$labelnames,$row_labels,$column_labels) = @_; | ||
| 1711 | return unless @$array; | ||
| 1712 | my $settings = $self->state; | ||
| 1713 | |||
| 1714 | my $columns = $cols || | ||
| 1715 | $self->data_source->global_setting('config table columns') || 3; | ||
| 1716 | my $rows = int( @$array/$columns + 0.99 ); | ||
| 1717 | |||
| 1718 | # gets the data for the defined 'category table(s)' | ||
| 1719 | my (@column_labels,@row_labels); | ||
| 1720 | if ($row_labels && $column_labels) { | ||
| 1721 | @row_labels = @$row_labels; | ||
| 1722 | @column_labels = @$column_labels; | ||
| 1723 | $rows = @row_labels; | ||
| 1724 | $columns = @column_labels; | ||
| 1725 | } | ||
| 1726 | |||
| 1727 | my $cwidth = int(100/$columns+0.5) . '%'; | ||
| 1728 | |||
| 1729 | my $html = start_table({-border=>0,-width=>'100%'}); | ||
| 1730 | |||
| 1731 | if (@column_labels) { | ||
| 1732 | $html.="<tr valign='top'><td></td>"; | ||
| 1733 | for (my $column=0;$column<$columns;$column++) { | ||
| 1734 | $html .= "<td><b>$column_labels[$column]</b> </td>"; | ||
| 1735 | } | ||
| 1736 | $html.="</tr>"; | ||
| 1737 | } | ||
| 1738 | |||
| 1739 | for (my $row=0;$row<$rows;$row++) { | ||
| 1740 | # do table headers | ||
| 1741 | $html .= qq(<tr class="searchtitle" valign="top">); | ||
| 1742 | $html .= "<td><b>$row_labels[$row]</b></td>" if @row_labels; | ||
| 1743 | for (my $column=0;$column<$columns;$column++) { | ||
| 1744 | my $label = $labelnames->[$column*$rows + $row] || ' '; | ||
| 1745 | my $checkbox = $array->[$column*$rows + $row] || ' '; | ||
| 1746 | |||
| 1747 | # de-couple the checkbox and label click behaviors | ||
| 1748 | $checkbox =~ s/\<\/?label\>//gi; | ||
| 1749 | if ($label =~/^=/) { | ||
| 1750 | $label = ' '; | ||
| 1751 | $checkbox = ' '; | ||
| 1752 | } | ||
| 1753 | my $class = $settings->{features}{$label}{visible} ? 'activeTrack' : ''; | ||
| 1754 | |||
| 1755 | $html .= td({-width=>$cwidth,-style => 'visibility:visible',-class=>$class}, | ||
| 1756 | span({ -id => "notselectedcheck_${label}", | ||
| 1757 | -class => 'notselected_check'},$checkbox)); | ||
| 1758 | } | ||
| 1759 | $html .= "</tr>\n"; | ||
| 1760 | } | ||
| 1761 | $html .= end_table(); | ||
| 1762 | } | ||
| 1763 | |||
| 1764 | sub subtrack_counts { | ||
| 1765 | my $self = shift; | ||
| 1766 | my $label = shift; | ||
| 1767 | my $stt = $self->create_subtrack_manager($label) or return; | ||
| 1768 | return $stt->counts; | ||
| 1769 | } | ||
| 1770 | |||
| 1771 | sub subtrack_table { | ||
| 1772 | my $self = shift; | ||
| 1773 | my $label = shift; | ||
| 1774 | my $stt = $self->create_subtrack_manager($label); | ||
| 1775 | return $stt->selection_table($self); | ||
| 1776 | } | ||
| 1777 | |||
| 1778 | #### generate the fragment of HTML for printing out the examples | ||
| 1779 | sub examples { | ||
| 1780 | my $self = shift; | ||
| 1781 | my $examples = $self->setting('examples') or return; | ||
| 1782 | my @examples = shellwords($examples); | ||
| 1783 | return unless @examples; | ||
| 1784 | my @urls = map { a({-href=>"?name=".escape($_)},$_) } @examples; | ||
| 1785 | return b($self->translate('Examples')).': '.join(', ',@urls).". "; | ||
| 1786 | } | ||
| 1787 | |||
| 1788 | ######################### code for the search box and navigation bar ################### | ||
| 1789 | sub plugin_menu { | ||
| 1790 | my $self = shift; | ||
| 1791 | my $settings = $self->state; | ||
| 1792 | my $plugins = $self->plugins; | ||
| 1793 | |||
| 1794 | my $labels = $plugins->menu_labels; | ||
| 1795 | |||
| 1796 | my @plugins = grep {$plugins->plugin($_)->type ne 'trackfilter'} # track filter gets its own special position | ||
| 1797 | sort {$labels->{$a} cmp $labels->{$b}} keys %$labels; | ||
| 1798 | |||
| 1799 | # Add plugin types as attribute so the javascript controller knows what to do | ||
| 1800 | # with each plug-in | ||
| 1801 | my %attributes = map { | ||
| 1802 | $_ => { | ||
| 1803 | 'plugin_type' => $plugins->plugin($_)->type(), | ||
| 1804 | 'track_name' => "plugin:".$plugins->plugin($_)->name(), | ||
| 1805 | } | ||
| 1806 | } | ||
| 1807 | keys %$labels; | ||
| 1808 | |||
| 1809 | return unless @plugins; | ||
| 1810 | |||
| 1811 | return join( | ||
| 1812 | '', | ||
| 1813 | popup_menu( | ||
| 1814 | -name => 'plugin', | ||
| 1815 | -id => 'plugin', | ||
| 1816 | -values => \@plugins, | ||
| 1817 | -labels => $labels, | ||
| 1818 | -attributes => \%attributes, | ||
| 1819 | -default => $settings->{plugin}, | ||
| 1820 | ), | ||
| 1821 | ' ', | ||
| 1822 | button( | ||
| 1823 | -name => 'plugin_action', | ||
| 1824 | -id => 'configure_plugin_button', | ||
| 1825 | -value => $self->translate('Configure'), | ||
| 1826 | -onClick => 'Controller.configure_plugin("plugin_configure_div");' | ||
| 1827 | ), | ||
| 1828 | ' ', | ||
| 1829 | button( | ||
| 1830 | -name => 'plugin_action', | ||
| 1831 | -value => $self->translate('Go'), | ||
| 1832 | -onClick => 'var select_box = document.pluginform.plugin;' | ||
| 1833 | . q{var plugin_type = select_box.options[select_box.selectedIndex].attributes.getNamedItem('plugin_type').value;} | ||
| 1834 | . 'Controller.plugin_go(' | ||
| 1835 | . 'document.pluginform.plugin.value,' | ||
| 1836 | . 'plugin_type,' . '"' | ||
| 1837 | . $self->translate('Go') . '",' | ||
| 1838 | . '"form"' . ');', | ||
| 1839 | ), | ||
| 1840 | ); | ||
| 1841 | } | ||
| 1842 | |||
| 1843 | |||
| 1844 | # plugin configuration form for balloon content | ||
| 1845 | sub plugin_configuration_form { | ||
| 1846 | my $self = shift; | ||
| 1847 | my $plugin = shift; | ||
| 1848 | |||
| 1849 | my $plugin_type = $plugin->type; | ||
| 1850 | my $plugin_name = $plugin->name; | ||
| 1851 | my $plugin_id = $plugin->id; | ||
| 1852 | |||
| 1853 | print CGI::header(-type=>'text/html', | ||
| 1854 | -cache_control =>'no-cache'); | ||
| 1855 | print start_form( | ||
| 1856 | -name => 'configure_plugin', | ||
| 1857 | -id => 'configure_plugin', | ||
| 1858 | ), | ||
| 1859 | button(-value => $self->translate('Cancel'), | ||
| 1860 | -onClick=>'Balloon.prototype.hideTooltip(1)'), | ||
| 1861 | button(-value => $self->translate('Configure_plugin'), | ||
| 1862 | -onClick=>'Controller.reconfigure_plugin(' | ||
| 1863 | . '"'.$self->translate('Configure_plugin').'"' | ||
| 1864 | . qq(, "plugin:$plugin_id") | ||
| 1865 | . qq(, "plugin_configure_div") | ||
| 1866 | . qq(, "$plugin_type") | ||
| 1867 | . qq(, this.parentNode) | ||
| 1868 | . ');Balloon.prototype.hideTooltip(1)'), | ||
| 1869 | $plugin->configure_form(), | ||
| 1870 | end_form(); | ||
| 1871 | } | ||
| 1872 | |||
| 1873 | # wrap arbitrary HTML in a named div | ||
| 1874 | sub wrap_in_div { | ||
| 1875 | my $self = shift; | ||
| 1876 | my $div_id = shift; | ||
| 1877 | return div({-id=>$div_id},@_); | ||
| 1878 | } | ||
| 1879 | |||
| 1880 | # Wrap the plugin configuration html into a form and tie it into the controller | ||
| 1881 | sub wrap_plugin_configuration { | ||
| 1882 | my $self = shift; | ||
| 1883 | my $plugin_base = shift or return ''; | ||
| 1884 | my $plugin = shift or return ''; | ||
| 1885 | my $config_html = $plugin->configure_form(); | ||
| 1886 | |||
| 1887 | my $return_html = start_form( | ||
| 1888 | -name => 'configure_plugin', | ||
| 1889 | -id => 'configure_plugin', | ||
| 1890 | -onSubmit => 'return false;', | ||
| 1891 | ); | ||
| 1892 | if ($config_html) { | ||
| 1893 | my $plugin_type = $plugin->type; | ||
| 1894 | my $plugin_name = $plugin->name; | ||
| 1895 | my $plugin_id = $plugin->id; | ||
| 1896 | my @plugin_description = $plugin->description; | ||
| 1897 | my @buttons; | ||
| 1898 | |||
| 1899 | # Cancel Button | ||
| 1900 | push @buttons, | ||
| 1901 | button( | ||
| 1902 | -name => 'plugin_button', | ||
| 1903 | -value => $self->translate('CANCEL'), | ||
| 1904 | -onClick => 'Controller.wipe_div("plugin_configure_div");' | ||
| 1905 | ); | ||
| 1906 | |||
| 1907 | # Configure Button | ||
| 1908 | |||
| 1909 | # Supplies the track name and the track div which I'm not really | ||
| 1910 | # happy with | ||
| 1911 | push @buttons, | ||
| 1912 | button( | ||
| 1913 | -name => 'plugin_button', | ||
| 1914 | -value => $self->translate('Configure_plugin'), | ||
| 1915 | -onClick => 'Controller.reconfigure_plugin("' | ||
| 1916 | . $self->translate('Configure_plugin') . '", "' | ||
| 1917 | . "plugin:$plugin_id" | ||
| 1918 | . '","plugin_configure_div","' | ||
| 1919 | . $plugin_type . '");' | ||
| 1920 | ); | ||
| 1921 | if ( $plugin_type eq 'finder' ) { | ||
| 1922 | push @buttons, | ||
| 1923 | button( | ||
| 1924 | -name => 'plugin_button', | ||
| 1925 | -value => $self->translate('Find'), | ||
| 1926 | -onClick => 'Controller.plugin_go("' | ||
| 1927 | . $plugin_base . '","' | ||
| 1928 | . $plugin_type . '","' | ||
| 1929 | . $self->translate('Find') . '","' | ||
| 1930 | . 'config' . '")', | ||
| 1931 | ); | ||
| 1932 | } | ||
| 1933 | elsif ( $plugin_type eq 'dumper' ) { | ||
| 1934 | push @buttons, | ||
| 1935 | button( | ||
| 1936 | -name => 'plugin_button', | ||
| 1937 | -value => $self->translate('Go'), | ||
| 1938 | -onClick => 'Controller.plugin_go("' | ||
| 1939 | . $plugin_base . '","' | ||
| 1940 | . $plugin_type . '","' | ||
| 1941 | . $self->translate('Go') . '","' | ||
| 1942 | . 'config' . '")', | ||
| 1943 | ); | ||
| 1944 | } | ||
| 1945 | |||
| 1946 | # Start adding to the html | ||
| 1947 | $return_html .= h1( | ||
| 1948 | $plugin_type eq 'finder' | ||
| 1949 | ? $self->translate('Find') | ||
| 1950 | : $self->translate('Configure'), | ||
| 1951 | $plugin_name, | ||
| 1952 | ); | ||
| 1953 | $return_html .= div({-style=>'font-size:small'},@plugin_description); | ||
| 1954 | |||
| 1955 | my $button_html = join( ' ', | ||
| 1956 | @buttons[ 0 .. @buttons - 2 ], | ||
| 1957 | b( $buttons[-1] ), | ||
| 1958 | ); | ||
| 1959 | |||
| 1960 | $return_html .= join '', $button_html, $config_html, p(), | ||
| 1961 | $button_html,; | ||
| 1962 | } | ||
| 1963 | else { | ||
| 1964 | $return_html .= join '', p( $self->translate('Boring_plugin') ), | ||
| 1965 | b( | ||
| 1966 | button( | ||
| 1967 | -name => 'plugin_button', | ||
| 1968 | -value => $self->translate('CANCEL'), | ||
| 1969 | -onClick => 'Controller.wipe_div("plugin_configure_div");' | ||
| 1970 | ) | ||
| 1971 | ); | ||
| 1972 | } | ||
| 1973 | $return_html .= end_form(); | ||
| 1974 | |||
| 1975 | return $return_html; | ||
| 1976 | |||
| 1977 | } | ||
| 1978 | |||
| 1979 | sub wrap_track_in_track_div { | ||
| 1980 | my $self = shift; | ||
| 1981 | my %args = @_; | ||
| 1982 | my $track_id = $args{'track_id'}; | ||
| 1983 | my $track_name = $args{'track_name'}; | ||
| 1984 | my $track_html = $args{'track_html'}; | ||
| 1985 | |||
| 1986 | # track_type used in register_track() javascript method | ||
| 1987 | my $track_type = $args{'track_type'} || 'standard'; | ||
| 1988 | |||
| 1989 | my $section = $self->data_source->get_section_from_label($track_id); | ||
| 1990 | my $class = $track_id =~ /scale/i ? 'scale' : 'track'; | ||
| 1991 | |||
| 1992 | return div( | ||
| 1993 | { -id => "track_" . $track_id, | ||
| 1994 | -class => $class, | ||
| 1995 | }, | ||
| 1996 | $track_html | ||
| 1997 | ) | ||
| 1998 | . qq[<script type="text/javascript" language="JavaScript">Controller.register_track("] | ||
| 1999 | . $track_id . q[", "] | ||
| 2000 | . $track_name . q[", "] | ||
| 2001 | . $track_type . q[", "] | ||
| 2002 | . $section | ||
| 2003 | . q[");</script>]; | ||
| 2004 | } | ||
| 2005 | |||
| 2006 | sub do_plugin_header { | ||
| 2007 | my $self = shift; | ||
| 2008 | my $plugin = shift; | ||
| 2009 | my $cookie = shift; | ||
| 2010 | my ( $mime_type, $attachment ) = $plugin->mime_type; | ||
| 2011 | print header( | ||
| 2012 | -cookie => $cookie, | ||
| 2013 | -type => $mime_type, | ||
| 2014 | -charset => $self->translate('CHARSET'), | ||
| 2015 | $attachment ? ( -attachment => $attachment ) : (), | ||
| 2016 | ); | ||
| 2017 | } | ||
| 2018 | |||
| 2019 | # Slider Table - Returns the HTML for the zooming and panning controls. | ||
| 2020 | sub slidertable { | ||
| 2021 | my $self = shift; | ||
| 2022 | my $state = $self->state; | ||
| 2023 | |||
| 2024 | # try to avoid reopening the database -- recover segment | ||
| 2025 | # and whole segment lengths from our stored state if available | ||
| 2026 | my $span = $state->{view_stop} - $state->{view_start} + 1; | ||
| 2027 | my $max = $self->thin_whole_segment->length; | ||
| 2028 | |||
| 2029 | my $buttonsDir = $self->data_source->button_url; | ||
| 2030 | |||
| 2031 | my $half_title = $self->data_source->unit_label(int $span/2); | ||
| 2032 | my $full_title = $self->data_source->unit_label($span); | ||
| 2033 | my $half = int $span/2; | ||
| 2034 | my $full = $span; | ||
| 2035 | my $fine_zoom = $self->get_zoomincrement(); | ||
| 2036 | |||
| 2037 | my $show = $self->translate('Show').' '; | ||
| 2038 | |||
| 2039 | my @lines = | ||
| 2040 | (image_button(-src => "$buttonsDir/green_l2.gif", | ||
| 2041 | -name=>"left $full", | ||
| 2042 | -title => "left $full_title", | ||
| 2043 | -onClick => "Controller.scroll('left', 1)" | ||
| 2044 | ), | ||
| 2045 | ' ', | ||
| 2046 | image_button(-src=>"$buttonsDir/green_l1.gif",-name=>"left $half", | ||
| 2047 | -title=>"left $half_title", | ||
| 2048 | -onClick => "Controller.scroll('left', 0.5)" | ||
| 2049 | ), | ||
| 2050 | ' ', | ||
| 2051 | image_button(-src=>"$buttonsDir/mminus.png", | ||
| 2052 | -name=>"zoom out $fine_zoom", | ||
| 2053 | -style=>'background-color: transparent', | ||
| 2054 | -title=>"zoom out $fine_zoom", | ||
| 2055 | -onClick => "Controller.update_coordinates(this.name)" | ||
| 2056 | ), | ||
| 2057 | ' ', | ||
| 2058 | $self->zoomBar($span,$max,$show), | ||
| 2059 | ' ', | ||
| 2060 | image_button(-src=>"$buttonsDir/mplus.png", | ||
| 2061 | -name=>"zoom in $fine_zoom", | ||
| 2062 | -style=>'background-color: transparent', | ||
| 2063 | -title=>"zoom in $fine_zoom", | ||
| 2064 | -onClick => "Controller.update_coordinates(this.name)", | ||
| 2065 | ), | ||
| 2066 | ' ', | ||
| 2067 | image_button(-src=>"$buttonsDir/green_r1.gif",-name=>"right $half", | ||
| 2068 | -title=>"right $half_title", | ||
| 2069 | -onClick => "Controller.scroll('right', 0.5)" | ||
| 2070 | ), | ||
| 2071 | ' ', | ||
| 2072 | image_button(-src=>"$buttonsDir/green_r2.gif",-name=>"right $full", | ||
| 2073 | -title=>"right $full_title", | ||
| 2074 | -onClick => "Controller.scroll('right', 1)" | ||
| 2075 | ), | ||
| 2076 | ' ', | ||
| 2077 | ); | ||
| 2078 | |||
| 2079 | my $str = join('', @lines); | ||
| 2080 | return span({-id=>'span'},$str); | ||
| 2081 | } | ||
| 2082 | |||
| 2083 | # this generates the popup zoom menu with the window sizes | ||
| 2084 | sub zoomBar { | ||
| 2085 | my $self = shift; | ||
| 2086 | my ($length,$max,$item_label) = @_; | ||
| 2087 | $item_label ||= ''; | ||
| 2088 | |||
| 2089 | my %seen; | ||
| 2090 | my @r = sort {$a<=>$b} $self->data_source->get_ranges(); | ||
| 2091 | $max *= $self->data_source->unit_divider; | ||
| 2092 | |||
| 2093 | my @ranges = grep {!$seen{$self->data_source->unit_label($_)}++ && $_<=$max} sort {$b<=>$a} @r,$length; | ||
| 2094 | my %labels = map {$_=>$item_label.$self->data_source->unit_label($_)} @ranges; | ||
| 2095 | return popup_menu(-class => 'searchtitle', | ||
| 2096 | -name => 'span', | ||
| 2097 | -values => \@ranges, | ||
| 2098 | -labels => \%labels, | ||
| 2099 | -default => $length, | ||
| 2100 | -force => 1, | ||
| 2101 | -onChange => 'Controller.update_coordinates("set span "+this.value)', | ||
| 2102 | ); | ||
| 2103 | } | ||
| 2104 | |||
| 2105 | sub render_ruler_div { | ||
| 2106 | my $self = shift; | ||
| 2107 | |||
| 2108 | my $ruler_js = <<RULER; | ||
| 2109 | <script type="text/javascript"> | ||
| 2110 | // <![CDATA[ | ||
| 2111 | createRuler(); | ||
| 2112 | // ]]> | ||
| 2113 | </script> | ||
| 2114 | RULER | ||
| 2115 | |||
| 2116 | my $settings = $self->state; | ||
| 2117 | my $width = $self->get_image_width($settings); | ||
| 2118 | my $button_url = $self->data_source->button_url; | ||
| 2119 | |||
| 2120 | return div({-id => 'ruler_track', | ||
| 2121 | -style => "position:relative; z-index: 100; width:${width}px; height:0px; margin-left:auto; margin-right:auto;"}, | ||
| 2122 | div({-id => 'ruler_handle', | ||
| 2123 | -style => "width:51px; z-index: 100;"}, | ||
| 2124 | div({-id => 'ruler_label', | ||
| 2125 | -onMouseUp => 'toggleRuler(false)', | ||
| 2126 | -style => "height:17px; cursor:pointer; text-align:center; visibility:hidden;"},'') . | ||
| 2127 | div({-id => 'ruler_icon', | ||
| 2128 | -onMouseOver => 'GBubble.showTooltip(event,"'.$self->translate('RULER_TOGGLE_TOOLTIP').'",0)', | ||
| 2129 | -onMouseUp => 'toggleRuler(true)', | ||
| 2130 | -style => "height:17px; cursor:pointer; position:absolute; top:2px; left:3px;"}, | ||
| 2131 | img({-src=>"${button_url}/ruler-icon.png",-alt=>'Ruler'}) ) . | ||
| 2132 | div({-id => 'ruler_image', | ||
| 2133 | -style => "background-image: url(${button_url}/ruler.png); cursor:move; background-size: 100%; display:none;"},'') | ||
| 2134 | )) . $ruler_js; | ||
| 2135 | } | ||
| 2136 | |||
| 2137 | sub source_menu { | ||
| 2138 | my $self = shift; | ||
| 2139 | |||
| 2140 | my $globals = $self->globals; | ||
| 2141 | my $username = $self->session->username if $self->session->private; | ||
| 2142 | my $p = eval{$self->plugins->auth_plugin}; | ||
| 2143 | |||
| 2144 | my @sources = $globals->data_sources; | ||
| 2145 | my $show_sources = $self->setting('show sources'); | ||
| 2146 | $show_sources = 1 unless defined $show_sources; # default to true | ||
| 2147 | @sources = grep {$globals->data_source_show($_,$username,$p)} @sources; | ||
| 2148 | my $sources = $show_sources && @sources > 1; | ||
| 2149 | |||
| 2150 | my %descriptions = map {$_=>$globals->data_source_description($_)} @sources; | ||
| 2151 | @sources = sort {$descriptions{$a} cmp $descriptions{$b}} @sources; | ||
| 2152 | |||
| 2153 | my %sources = map {$_=>1} @sources; | ||
| 2154 | |||
| 2155 | my $current_source = $self->data_source->name; | ||
| 2156 | if (!$sources{$current_source} && | ||
| 2157 | $globals->data_source_show($current_source,$username,$p) ) { # for regexp-based sources | ||
| 2158 | $descriptions{$current_source} = $self->data_source->description; | ||
| 2159 | @sources = sort {$descriptions{$a} cmp $descriptions{$b}} (@sources,$current_source); | ||
| 2160 | } | ||
| 2161 | |||
| 2162 | return b($self->translate('DATA_SOURCE')).br. | ||
| 2163 | ( $sources ? | ||
| 2164 | popup_menu(-name => 'source', | ||
| 2165 | -values => \@sources, | ||
| 2166 | -labels => \%descriptions, | ||
| 2167 | -default => $self->data_source->name, | ||
| 2168 | -onChange => 'this.form.submit()', | ||
| 2169 | ) | ||
| 2170 | : $globals->data_source_description($self->session->source) | ||
| 2171 | ); | ||
| 2172 | } | ||
| 2173 | |||
| 2174 | # This is the content of the popup balloon that describes the track and gives configuration settings | ||
| 2175 | |||
| 2176 | # This is currently somewhat hacky, hard to extend and needs to be generalized. | ||
| 2177 | # NOTE: to add new configuration rows, the name of the form element must begin with "conf_" and | ||
| 2178 | # the rest must correspond to a valid glyph option. | ||
| 2179 | sub track_config { | ||
| 2180 | my $self = shift; | ||
| 2181 | my $label = shift; | ||
| 2182 | my $revert_to_defaults = shift; | ||
| 2183 | |||
| 2184 | eval 'require Bio::Graphics::Browser2::TrackConfig' | ||
| 2185 | unless Bio::Graphics::Browser2::Render::TrackConfig->can('new'); | ||
| 2186 | my $c = Bio::Graphics::Browser2::Render::TrackConfig->new($self); | ||
| 2187 | return $c->config_dialog($label,$revert_to_defaults); | ||
| 2188 | } | ||
| 2189 | |||
| 2190 | sub cit_link { | ||
| 2191 | my $self = shift; | ||
| 2192 | my $label = shift; | ||
| 2193 | return "?display_citation=$label"; | ||
| 2194 | } | ||
| 2195 | |||
| 2196 | sub track_citation { | ||
| 2197 | my $self = shift; | ||
| 2198 | my $label = shift; | ||
| 2199 | |||
| 2200 | my $state = $self->state(); | ||
| 2201 | my $data_source = $self->data_source(); | ||
| 2202 | |||
| 2203 | my $length = $self->thin_segment->length; | ||
| 2204 | my $slabel = $data_source->semantic_label($label,$length); | ||
| 2205 | my $key = $self->label2key($slabel); | ||
| 2206 | |||
| 2207 | # citation info: | ||
| 2208 | my $cit_txt = citation( $data_source, $label, $self->language ) | ||
| 2209 | || $self->tr('NO_TRACK_CITATION') || ''; | ||
| 2210 | my $cit_html; | ||
| 2211 | my $cit_link = ''; | ||
| 2212 | |||
| 2213 | # For verbose citations, add a link to a new window | ||
| 2214 | if (length $cit_txt > 512) { | ||
| 2215 | $cit_link = "?display_citation=$label"; | ||
| 2216 | $cit_link =~ s!gbrowse\?!gbrowse/$state->{source}/\?!; | ||
| 2217 | $cit_link = a( | ||
| 2218 | { | ||
| 2219 | -href => $cit_link, | ||
| 2220 | -target => "citation", #'_NEW', | ||
| 2221 | -onclick => 'GBox.hideTooltip(1)' | ||
| 2222 | }, | ||
| 2223 | 'Click here to display in new window...'); | ||
| 2224 | $cit_link = p($cit_link); | ||
| 2225 | } | ||
| 2226 | $cit_html = div($cit_link||br,$cit_txt); | ||
| 2227 | my $id = $self->tr('TRACK_ID',$label); | ||
| 2228 | my $download = a({-href=>"?l=$label;f=save+datafile"},$self->tr('DOWNLOAD_TRACK_DATA_ALL')); | ||
| 2229 | my $title = div({-style => 'background:gainsboro;padding:5px;font-weight:bold'},$key,br(),$id,br(),$download); | ||
| 2230 | return join '',div({-style=>'text-align:center;font-size:small'},$title,$cit_html); | ||
| 2231 | } | ||
| 2232 | |||
| 2233 | sub download_track_menu { | ||
| 2234 | my $self = shift; | ||
| 2235 | my $track = shift; | ||
| 2236 | my $view_start = shift; | ||
| 2237 | my $view_stop = shift; | ||
| 2238 | |||
| 2239 | my $state = $self->state(); | ||
| 2240 | my $data_source = $self->data_source(); | ||
| 2241 | |||
| 2242 | my $segment; | ||
| 2243 | if ($track =~ /:overview$/) { | ||
| 2244 | $segment = $self->thin_whole_segment; | ||
| 2245 | } elsif ($track =~ /:region$/) { | ||
| 2246 | $segment = $self->thin_region_segment; | ||
| 2247 | } else { | ||
| 2248 | $segment = $self->thin_segment; | ||
| 2249 | $segment->{start} = $view_start || $segment->{start}; | ||
| 2250 | $segment->{stop} = $view_stop || $segment->{stop}; | ||
| 2251 | $segment->{end} = $view_stop || $segment->{end}; | ||
| 2252 | } | ||
| 2253 | |||
| 2254 | my $seqid = $segment->seq_id; | ||
| 2255 | my $start = $segment->start; | ||
| 2256 | my $end = $segment->end; | ||
| 2257 | my $key = $self->label2key($track); | ||
| 2258 | |||
| 2259 | my $unload = 'window.onbeforeunload=void(0)'; | ||
| 2260 | my $byebye = 'Balloon.prototype.hideTooltip(1)'; | ||
| 2261 | |||
| 2262 | my $segment_str = segment_str($segment); | ||
| 2263 | my $glyph = $data_source->setting($track=>'glyph') || 'generic'; | ||
| 2264 | |||
| 2265 | my @format_options = Bio::Graphics::Browser2::TrackDumper->available_formats($data_source,$track); | ||
| 2266 | my %foptions = map {$_=>1} @format_options; | ||
| 2267 | my $default = $foptions{$state->{preferred_dump_format}||''} ? $state->{preferred_dump_format} | ||
| 2268 | : $glyph =~ /vista/ && $foptions{vista} ? 'vista' | ||
| 2269 | : $foptions{gff3} ? 'gff3' | ||
| 2270 | : $foptions{bed} ? 'bed' | ||
| 2271 | : $foptions{sam} ? 'sam' | ||
| 2272 | : $foptions{vista} ? 'vista' | ||
| 2273 | : 'fasta'; | ||
| 2274 | my @radios = radio_group(-name => 'format', | ||
| 2275 | -values => \@format_options, | ||
| 2276 | -default => $default, | ||
| 2277 | -labels => {fasta => 'FASTA', | ||
| 2278 | gff3 => 'GFF3', | ||
| 2279 | genbank => 'Genbank', | ||
| 2280 | vista => 'WIG (peaks+signal)', | ||
| 2281 | vista_wiggle => 'WIG (signal)', | ||
| 2282 | vista_peaks => 'WIG (peaks)', | ||
| 2283 | bed => 'WIG', | ||
| 2284 | sam => 'SAM alignment format'}); | ||
| 2285 | my $options = "gbgff=1;l=$track;s=0;f=save+gff3;'+\$('dump_form').serialize()"; | ||
| 2286 | my $html = ''; | ||
| 2287 | $html .= div({-align=>'center'}, | ||
| 2288 | div({-style => 'background:gainsboro;padding:5px;font-weight:bold'},$key). | ||
| 2289 | hr(). | ||
| 2290 | start_form({-id=>'dump_form'}). | ||
| 2291 | div($self->tableize(\@radios,3)). | ||
| 2292 | end_form(). | ||
| 2293 | hr(). | ||
| 2294 | button(-value => $self->translate('DOWNLOAD_TRACK_DATA_REGION',$segment_str), | ||
| 2295 | -onClick => "$unload;window.location='?q=$seqid:$start..$end;$options;$byebye", | ||
| 2296 | ),br(), | ||
| 2297 | |||
| 2298 | button(-value => $self->translate('DOWNLOAD_TRACK_DATA_CHROM',$seqid), | ||
| 2299 | -onClick => "$unload;window.location='?q=$seqid;$options;$byebye", | ||
| 2300 | ),br(), | ||
| 2301 | |||
| 2302 | button(-value=> $self->translate('DOWNLOAD_TRACK_DATA_ALL'), | ||
| 2303 | -onClick => "$unload;location.href='?$options;$byebye", | ||
| 2304 | )). | ||
| 2305 | button(-style=>"background:pink;float:right",-onClick=>"$byebye",-name=>$self->translate('CANCEL')); | ||
| 2306 | return $html; | ||
| 2307 | } | ||
| 2308 | |||
| 2309 | # this is the content of the popup balloon that describes how to share a track | ||
| 2310 | sub share_track { | ||
| 2311 | my $self = shift; | ||
| 2312 | my $label = shift; | ||
| 2313 | |||
| 2314 | my $state = $self->state(); | ||
| 2315 | my $source = $self->data_source; | ||
| 2316 | my $name = $source->name; | ||
| 2317 | |||
| 2318 | (my $lbase = $label) =~ s/:\w+$//; | ||
| 2319 | |||
| 2320 | my $description; | ||
| 2321 | my $labels; | ||
| 2322 | my $usertracks_present; | ||
| 2323 | |||
| 2324 | my @visible | ||
| 2325 | = grep { $state->{features}{$_}{visible} && !/:(overview|region)$/ } | ||
| 2326 | @{ $state->{tracks} }; | ||
| 2327 | |||
| 2328 | if ( $label eq 'all' ) { | ||
| 2329 | for my $l (@visible) { | ||
| 2330 | $usertracks_present ||= $source->is_usertrack($l); | ||
| 2331 | } | ||
| 2332 | $labels = join '+', map { CGI::escape($_) } @visible; | ||
| 2333 | $description = 'all selected tracks'; | ||
| 2334 | } else { | ||
| 2335 | $description = $self->setting( $label => 'key' ) | ||
| 2336 | || $self->setting( $lbase => 'key') | ||
| 2337 | || $label; | ||
| 2338 | $usertracks_present ||= $source->is_usertrack($label); | ||
| 2339 | $labels = $label; | ||
| 2340 | } | ||
| 2341 | |||
| 2342 | my $base = url(-full=>1,-path_info=>1); | ||
| 2343 | |||
| 2344 | my $gbgff; | ||
| 2345 | my $segment = $label =~ /:region$/ ? '$region' | ||
| 2346 | :$label =~ /:overview$/ ? '$overview' | ||
| 2347 | :'$segment'; | ||
| 2348 | my $session = $self->session; | ||
| 2349 | my $upload_id = $session->uploadsid; | ||
| 2350 | if ( $label =~ /^(http|ftp)/ ) { # reexporting an imported track! | ||
| 2351 | $gbgff = $source->setting($label=>'remote feature'); | ||
| 2352 | $gbgff ||= $source->setting($lbase=>'remote feature'); | ||
| 2353 | } else { | ||
| 2354 | $gbgff = $base; | ||
| 2355 | $gbgff .= "?gbgff=1;q=$segment;t=$labels;s=1;format=gff3"; | ||
| 2356 | $gbgff .= ";uuid=$upload_id" if $usertracks_present; | ||
| 2357 | } | ||
| 2358 | |||
| 2359 | my $das_types = join( ';', | ||
| 2360 | map { "type=" . CGI::escape($_) } | ||
| 2361 | grep { length $_ > 0 } | ||
| 2362 | map { shellwords( $self->setting( $_ => 'feature' ) ) } | ||
| 2363 | grep { $self->setting( $_ => 'das category' ) } | ||
| 2364 | $label eq 'all' | ||
| 2365 | ? @visible | ||
| 2366 | : $label ); | ||
| 2367 | my $das = url( -full => 1, -path_info => 1 ); | ||
| 2368 | $das =~ s/gbrowse/das/; | ||
| 2369 | $das =~ s/$name/$name|$label/ if $label ne 'all'; | ||
| 2370 | $das .= "features"; | ||
| 2371 | $das .= "?$das_types"; | ||
| 2372 | |||
| 2373 | my $return_html = start_html(); | ||
| 2374 | $return_html .= h1( $self->translate('SHARE', $description)); | ||
| 2375 | |||
| 2376 | my $tsize = 72; | ||
| 2377 | |||
| 2378 | if ($source->is_usertrack($label)) { | ||
| 2379 | my $usertracks = $self->user_tracks; | ||
| 2380 | my $file = $usertracks->get_track_upload_id($label); | ||
| 2381 | my $permissions = $usertracks->permissions($file); | ||
| 2382 | my $is_mine = $usertracks->is_mine($file); | ||
| 2383 | if ($is_mine || $permissions eq "public" || $permissions eq "casual") { | ||
| 2384 | my $permissions_changed; | ||
| 2385 | if ($permissions !~ /(casual|public)/) { | ||
| 2386 | $usertracks->permissions($file, "casual"); | ||
| 2387 | $permissions_changed = 1; | ||
| 2388 | } | ||
| 2389 | if ($is_mine) { | ||
| 2390 | $return_html .= p(($permissions_changed? | ||
| 2391 | $self->translate('SHARE_CUSTOM_TRACK_CHANGED', "casual") | ||
| 2392 | : $self->translate('SHARE_CUSTOM_TRACK_NO_CHANGE', $permissions)) | ||
| 2393 | . $self->translate('SHARE_INSTRUCTIONS_BOOKMARK')); | ||
| 2394 | $return_html .= p($self->translate('OTHER_SHARE_METHODS')); | ||
| 2395 | } elsif ($permissions =~ /(casual|public)/) { | ||
| 2396 | $return_html .= p($self->translate('SHARE_SHARED_TRACK', $permissions) | ||
| 2397 | . $self->translate('SHARE_INSTRUCTIONS_BOOKMARK')); | ||
| 2398 | } | ||
| 2399 | |||
| 2400 | $return_html .= textfield( | ||
| 2401 | -style => 'background-color: wheat', | ||
| 2402 | -readonly => 1, | ||
| 2403 | -size => $tsize, | ||
| 2404 | -value => $usertracks->sharing_link($file), | ||
| 2405 | -onClick => 'this.select()', | ||
| 2406 | ).br(); | ||
| 2407 | } else { | ||
| 2408 | $return_html .= p($self->translate('CANT_SHARE')); | ||
| 2409 | } | ||
| 2410 | } else { | ||
| 2411 | if ($label ne 'all' && $label !~ /^(http|ftp)/) { | ||
| 2412 | my $shared = "$base?label=$label"; | ||
| 2413 | |||
| 2414 | $return_html .= p( | ||
| 2415 | $self->translate('SHARE_INSTRUCTIONS_BOOKMARK'),br(), | ||
| 2416 | textfield( | ||
| 2417 | -style => 'background-color: wheat', | ||
| 2418 | -readonly => 1, | ||
| 2419 | -size => $tsize, | ||
| 2420 | -value => $shared, | ||
| 2421 | -onClick => 'this.select()' | ||
| 2422 | ) | ||
| 2423 | ) | ||
| 2424 | } | ||
| 2425 | |||
| 2426 | $return_html .= | ||
| 2427 | p( | ||
| 2428 | $self->translate( | ||
| 2429 | $label eq 'all' | ||
| 2430 | ? 'SHARE_INSTRUCTIONS_ALL_TRACKS' | ||
| 2431 | : 'SHARE_INSTRUCTIONS_ONE_TRACK' | ||
| 2432 | ).br(). | ||
| 2433 | textfield( | ||
| 2434 | -style => 'background-color: wheat', | ||
| 2435 | -readonly => 1, | ||
| 2436 | -size => $tsize, | ||
| 2437 | -value => $gbgff, | ||
| 2438 | -onClick => 'this.select()')); | ||
| 2439 | |||
| 2440 | if ($das_types) { | ||
| 2441 | $return_html .= p( | ||
| 2442 | $self->translate( | ||
| 2443 | $label eq 'all' | ||
| 2444 | ? 'SHARE_DAS_INSTRUCTIONS_ALL_TRACKS' | ||
| 2445 | : 'SHARE_DAS_INSTRUCTIONS_ONE_TRACK' | ||
| 2446 | ) | ||
| 2447 | ) | ||
| 2448 | . p( textfield( | ||
| 2449 | -style => 'background-color: wheat', | ||
| 2450 | -readonly => 1, | ||
| 2451 | -size => $tsize, | ||
| 2452 | -value => $das, | ||
| 2453 | -onFocus => 'this.select()', | ||
| 2454 | -onSelect => 'this.select()') | ||
| 2455 | ); | ||
| 2456 | } | ||
| 2457 | } | ||
| 2458 | |||
| 2459 | $return_html .= | ||
| 2460 | button( | ||
| 2461 | -name => $self->translate('OK'), | ||
| 2462 | -onClick => 'Balloon.prototype.hideTooltip(1)' | ||
| 2463 | ); | ||
| 2464 | |||
| 2465 | $return_html .= end_html(); | ||
| 2466 | return div({-style=>'width:600px'},$return_html); | ||
| 2467 | } | ||
| 2468 | |||
| 2469 | ################### various utilities ################### | ||
| 2470 | |||
| 2471 | sub html_frag { | ||
| 2472 | my $self = shift; | ||
| 2473 | my $fragname = shift; | ||
| 2474 | my $a = $self->data_source->global_setting($fragname); | ||
| 2475 | return $a->(@_) if ref $a eq 'CODE'; | ||
| 2476 | return $a || ''; | ||
| 2477 | } | ||
| 2478 | |||
| 2479 | |||
| 2480 | ############################## toggle code ######################## | ||
| 2481 | sub toggle { | ||
| 2482 | my $self = shift; | ||
| 2483 | |||
| 2484 | my %args = (); | ||
| 2485 | if (ref $_[0]) { | ||
| 2486 | %args = %{shift()}; | ||
| 2487 | } | ||
| 2488 | |||
| 2489 | my $title = shift; | ||
| 2490 | my @body = @_; | ||
| 2491 | |||
| 2492 | my $page_settings = $self->state; | ||
| 2493 | |||
| 2494 | my $id = "\L${title}_panel\E"; | ||
| 2495 | my $label = $self->translate($title) || ''; | ||
| 2496 | my $state = $self->data_source->section_setting($title) or return ''; | ||
| 2497 | return '' if $state eq 'off'; | ||
| 2498 | my $visible = exists $page_settings->{section_visible}{$id} ? | ||
| 2499 | $page_settings->{section_visible}{$id} : $state eq 'open'; | ||
| 2500 | |||
| 2501 | return $self->toggle_section({on=>$visible,%args}, | ||
| 2502 | $id, | ||
| 2503 | b($label), | ||
| 2504 | @body); | ||
| 2505 | } | ||
| 2506 | |||
| 2507 | sub toggle_section { | ||
| 2508 | my $self = shift; | ||
| 2509 | my %config = ref $_[0] eq 'HASH' ? %{shift()} : (); | ||
| 2510 | my ($name,$section_title,@section_body) = @_; | ||
| 2511 | |||
| 2512 | my $visible = $config{on}; | ||
| 2513 | |||
| 2514 | my $buttons = $self->data_source->button_url; | ||
| 2515 | my $plus = "$buttons/plus.png"; | ||
| 2516 | my $minus = "$buttons/minus.png"; | ||
| 2517 | my $break = div({-id=>"${name}_break", | ||
| 2518 | -style=>$visible ? 'display:none' : 'display:block' | ||
| 2519 | },' '); | ||
| 2520 | |||
| 2521 | my $show_ctl = div({-id=>"${name}_show", | ||
| 2522 | -class=>'ctl_hidden', | ||
| 2523 | -style=>$visible ? 'display:none' : 'display:inline', | ||
| 2524 | -onClick=>"visibility('$name',1)" | ||
| 2525 | }, | ||
| 2526 | img({-src=>$plus,-alt=>'+'}).' '.span({-class=>'tctl'},$section_title)); | ||
| 2527 | my $hide_ctl = div({-id=>"${name}_hide", | ||
| 2528 | -class=>'ctl_visible', | ||
| 2529 | -style=>$visible ? 'display:inline' : 'display:none', | ||
| 2530 | -onClick=>"visibility('$name',0)" | ||
| 2531 | }, | ||
| 2532 | img({-src=>$minus,-alt=>'-'}).' '.span({-class=>'tctl',-id=>"${name}_title"},$section_title)); | ||
| 2533 | my $content = div({-id => $name, | ||
| 2534 | -style=>$visible ? 'display:inline' : 'display:none', | ||
| 2535 | -class => 'el_visible'}, | ||
| 2536 | @section_body); | ||
| 2537 | my @class = (-class=>'toggleable'); | ||
| 2538 | my @result = $config{nodiv} ? (div({-style=>'float:left',@class}, | ||
| 2539 | $show_ctl.$hide_ctl),$content) | ||
| 2540 | :$config{tight}? (div({-style=>'float:left;position:absolute;z-index:10',@class}, | ||
| 2541 | $show_ctl.$hide_ctl).$break,$content) | ||
| 2542 | : div({@class},$show_ctl.$hide_ctl,$content); | ||
| 2543 | return wantarray ? @result : "@result"; | ||
| 2544 | } | ||
| 2545 | |||
| 2546 | sub can_generate_pdf { | ||
| 2547 | my $self = shift; | ||
| 2548 | my $source = $self->data_source; | ||
| 2549 | |||
| 2550 | return $CAN_PDF if defined $CAN_PDF; | ||
| 2551 | return $CAN_PDF = $source->global_setting('generate pdf') | ||
| 2552 | if defined $source->global_setting('generate pdf'); | ||
| 2553 | |||
| 2554 | return $CAN_PDF=0 unless `which inkscape`; | ||
| 2555 | # see whether we have the needed .inkscape and .gnome2 directories | ||
| 2556 | my $home = (getpwuid($<))[7]; | ||
| 2557 | my $user = (getpwuid($<))[0]; | ||
| 2558 | my $inkscape_dir = File::Spec->catfile($home,'.config','inkscape'); | ||
| 2559 | my $gnome2_dir = File::Spec->catfile($home,'.gnome2'); | ||
| 2560 | if (-e $inkscape_dir && -w $inkscape_dir | ||
| 2561 | && -e $gnome2_dir && -w $gnome2_dir) { | ||
| 2562 | return $CAN_PDF=1; | ||
| 2563 | } else { | ||
| 2564 | print STDERR | ||
| 2565 | join(' ', | ||
| 2566 | qq(GBROWSE NOTICE: To enable PDF generation, please enter the directory "$home"), | ||
| 2567 | qq(and run the commands:), | ||
| 2568 | qq("sudo mkdir -p .config/inkscape .gnome2"), | ||
| 2569 | qq(and "sudo chown $user .config/inkscape .gnome2". ), | ||
| 2570 | qq(To turn off this message add "generate pdf = 0"), | ||
| 2571 | qq(to the [GENERAL] section of your GBrowse.conf configuration file.) | ||
| 2572 | ); | ||
| 2573 | return $CAN_PDF=0; | ||
| 2574 | } | ||
| 2575 | } | ||
| 2576 | |||
| 2577 | # Truncated version (of track_config) for displaying citation only: | ||
| 2578 | sub display_citation { | ||
| 2579 | my $self = shift; | ||
| 2580 | my $label = shift; | ||
| 2581 | my $state = $self->state(); | ||
| 2582 | my $data_source = $self->data_source(); | ||
| 2583 | my $segment = $self->thin_segment; | ||
| 2584 | my $length = $segment ? $segment->length : 0; | ||
| 2585 | my $slabel = $data_source->semantic_label($label,$length); | ||
| 2586 | |||
| 2587 | my $key = $self->label2key($slabel); | ||
| 2588 | |||
| 2589 | my @stylesheets; | ||
| 2590 | my @style = shellwords($self->setting('stylesheet') || '/gbrowse2/gbrowse.css'); | ||
| 2591 | for my $s (@style) { | ||
| 2592 | my ($url,$media) = $s =~ /^([^\(]+)(?:\((.+)\))?/; | ||
| 2593 | $media ||= 'all'; | ||
| 2594 | push @stylesheets, CGI::Link({-rel=>'stylesheet', | ||
| 2595 | -type=>'text/css', | ||
| 2596 | -href=>$self->globals->resolve_path($url,'url'), | ||
| 2597 | -media=>$media}); | ||
| 2598 | } | ||
| 2599 | |||
| 2600 | my $return_html = start_html(-title => $key, -head => \@stylesheets); | ||
| 2601 | my $cit_txt = citation( $data_source, $label, $self->language ) || $self->translate('NO_CITATION'); | ||
| 2602 | |||
| 2603 | if (my ($lim) = $slabel =~ /\:(\d+)$/) { | ||
| 2604 | $key .= " (at >$lim bp)"; | ||
| 2605 | } | ||
| 2606 | |||
| 2607 | my $citation = div({-class => 'searchbody', -style => 'padding:10px;width:70%'}, h4($key), $cit_txt); | ||
| 2608 | |||
| 2609 | |||
| 2610 | $return_html | ||
| 2611 | .= table( TR( td( { -valign => 'top' }, $citation ) ) ); | ||
| 2612 | $return_html .= end_html(); | ||
| 2613 | return $return_html; | ||
| 2614 | } | ||
| 2615 | |||
| 2616 | sub format_autocomplete { | ||
| 2617 | my $self = shift; | ||
| 2618 | my $features = shift; | ||
| 2619 | my $partial = shift; | ||
| 2620 | my %names; | ||
| 2621 | for my $f (@$features) { | ||
| 2622 | my ($name) = grep {/$partial/i} ($f->display_name,eval{$f->aliases}); | ||
| 2623 | $names{$name}++; | ||
| 2624 | } | ||
| 2625 | my $html = "<ul>\n"; | ||
| 2626 | for my $n (sort keys %names) { | ||
| 2627 | $n =~ s/($partial)/<b>$1<\/b>/i; | ||
| 2628 | $html .= "<li>$n</li>\n"; | ||
| 2629 | } | ||
| 2630 | $html .= "</ul>\n"; | ||
| 2631 | return $html; | ||
| 2632 | } | ||
| 2633 | |||
| 2634 | sub format_upload_autocomplete { | ||
| 2635 | my $self = shift; | ||
| 2636 | my $matches = shift; | ||
| 2637 | my $partial = shift; | ||
| 2638 | my %names; | ||
| 2639 | for my $f (@$matches) { | ||
| 2640 | my ($name) = grep {/$partial/i} $f; | ||
| 2641 | $names{$name}++; | ||
| 2642 | } | ||
| 2643 | my $html = "<ul>\n"; | ||
| 2644 | for my $n (sort keys %names) { | ||
| 2645 | $n =~ s/($partial)/<b>$1<\/b>/i; | ||
| 2646 | $html .= "<li>$n</li>\n"; | ||
| 2647 | } | ||
| 2648 | $html .= "</ul>\n"; | ||
| 2649 | return $html; | ||
| 2650 | } | ||
| 2651 | 1; |