/
HTML.pm
2891 lines (2545 loc) · 99.2 KB
/
HTML.pm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
package Bio::Graphics::Browser2::Render::HTML;
use strict;
use warnings;
use base 'Bio::Graphics::Browser2::Render';
use Bio::Graphics::Browser2::Shellwords;
use Bio::Graphics::Browser2::SubtrackTable;
use Bio::Graphics::Browser2::Render::SnapshotManager;
use Bio::Graphics::Karyotype;
use Bio::Graphics::Browser2::Render::TrackConfig;
use Bio::Graphics::Browser2::Util qw[citation url_label segment_str];
use JSON;
use Digest::MD5 'md5_hex';
use Carp qw(croak cluck);
use CGI qw(:standard escape start_table end_table);
use Text::Tabs;
use POSIX qw(floor);
use constant JS => '/gbrowse2/js';
use constant ANNOTATION_EDIT_ROWS => 25;
use constant ANNOTATION_EDIT_COLS => 100;
use constant MAXIMUM_EDITABLE_UPLOAD => 1_000_000; # bytes
use constant DEBUG => 0;
use constant HAVE_SVG => eval "require GD::SVG; 1";
our $CAN_PDF;
# Render HTML Start - Returns the HTML for the browser's <head> section.
sub render_html_start {
my $self = shift;
my ($title,@actions) = @_;
my $dsn = $self->data_source;
my $html = $self->render_html_head($dsn,$title,@actions);
$html .= $self->render_js_controller_settings();
$html .= $self->render_balloon_settings();
$html .= "<div id='main'>";
$html .= $self->render_select_menus();
return $html;
}
# Render Top - Returns the HTML for the top banner of the page.
sub render_top {
my $self = shift;
my ($title,$features) = @_;
my $err = $self->render_error_div;
my $html = '';
$features ||= [];
$html .= $self->render_title($title,$self->state->{name}
&& @$features == 0);
# ***Render the snapshot title***
$html .= $self->render_snapshotTitle;
$html .= $self->html_frag('html1',$self->state);
return $err
. $self->toggle({nodiv=>1},'banner','',$html);
}
# Render Error DIV - Returns the HTML for the error display at the top of the page.
sub render_error_div {
my $self = shift;
my $error = $self->error_message;
my $display = $error ? 'block' : 'none';
my $button = button({-onClick=>'Controller.hide_error()',
-name=>'Ok'});
return div({-class=>'errorpanel',
-style=>"display:${display}",
-id=>'errordiv'},
table(
TR(
td(span({-class=>'error',-id=>'errormsg'},$error || 'no error')),
td({-align=>'right'},$button)
),
),
div({-class=>'errorpanel',
-style=>"display:none;margin: 6px 6px 6px 6px",
-id =>'errordetails'},
'no details'
)
).br();
}
sub render_login_required {
my $self = shift;
my $action = shift;
return div(
h1($self->translate('LOGIN_REQUIRED'),
button(-name => $self->translate('LOGIN'),
-onClick => $action)
));
}
# Render Tabbed Pages - Returns the HTML containing the tabs & the page DIVs to hold the content.
sub render_tabbed_pages {
my $self = shift;
# ***Add the title for the snapshots***
my ($main_html,$tracks_html,$community_tracks_html,$custom_tracks_html,$settings_html,$snapshot_html) = @_;
my $uses_database = $self->user_tracks->database;
my $main_title = $self->translate('MAIN_PAGE');
my $tracks_title = $self->translate('SELECT_TRACKS');
my $community_tracks_title = $self->translate('COMMUNITY_TRACKS_PAGE') if $uses_database;
my $custom_tracks_title = $self->translate('CUSTOM_TRACKS_PAGE');
my $settings_title = $self->translate('SETTINGS_PAGE');
# *** Snapshot title ***
my $snapshot_title = $self->translate('SNAPSHOT_SELECT');
my $html = '';
$html .= div({-id=>'tabbed_section', -class=>'tabbed'},
div({-id=>'tabbed_menu',-class=>'tabmenu'},
span({id=>'main_page_select'}, $main_title),
span({id=>'track_page_select'}, $tracks_title),
$uses_database? span({id=>'community_tracks_page_select'}, $community_tracks_title) : "",
span({id=>'custom_tracks_page_select'}, $custom_tracks_title),
span({id=>'settings_page_select'}, $settings_title),
# *** Snapshot span ***
span({id=>'saved_snapshots_page_select'}, $snapshot_title),
),
div({-id=>'main_page', -class=>'tabbody'}, $main_html),
div({-id=>'track_page', -class=>'tabbody'}, $tracks_html),
$uses_database?div({-id=>'community_tracks_page',-class=>'tabbody'}, $community_tracks_html) : "",
div({-id=>'custom_tracks_page', -class=>'tabbody'}, $custom_tracks_html),
div({-id=>'settings_page', -class=>'tabbody'}, $settings_html),
# *** Snapshot div ***
div({-id=>'saved_snapshots_page', -class=>'tabbody'}, $snapshot_html),
);
return $html;
}
# Render User Head - Returns any HTML for the <head> section specified by the user in GBrowse.conf.
sub render_user_head {
my $self = shift;
my $settings = $self->state;
return '' unless $settings->{head};
my $a = $self->data_source->global_setting('head');
return $a->(@_) if ref $a eq 'CODE';
return $a || '';
}
# Render User Header - Returns any HTML for the top of the browser (the header) as specified by the user in GBrowse.conf.
sub render_user_header {
my $self = shift;
my $settings = $self->state;
return '' unless $settings->{head};
my $a = $self->data_source->global_setting('header');
return $a->(@_) if ref $a eq 'CODE';
return $a || '';
}
# Render Bottom - Returns any HTML included in the footer specified by the user in GBrowse.conf.
sub render_bottom {
my $self = shift;
my $features = shift; # not used
my $a = $self->data_source->global_setting('footer');
my $value = ref $a eq 'CODE' ? $a->(@_) : $a;
$value ||= '';
return $value."</div>".end_html();
}
# Render Navbar - Returns the HTML for the navigation bar along the top of the main browser page (in the "Search" node).
sub render_navbar {
my $self = shift;
my $segment = shift;
warn "render_navbar()" if DEBUG;
my $settings = $self->state;
my $source = '/'.$self->session->source.'/';
# *** Added button to close the snapshot div ***
my $close = $self->translate('CLOSE');
my $searchform = join '',(
start_form(
-name => 'searchform',
-id => 'searchform',
),
hidden(-name=>'force_submit',-value=>0),
hidden(-name=>'plugin_find', -value=>0),
div({ -id => 'search_form_objects' },
$self->render_search_form_objects(),
),
end_form
);
my $search = $self->setting('no search')
? '' : b($self->translate('Landmark')).':'.br().$searchform.$self->examples();
my $plugin_form = div({-id=>'plugin_form'},$self->plugin_form());
# *** Checks the state to see if a snapshot is active and assigns it ***
my $isSnapshotActive = $settings->{snapshot_active};
my $source_form = div({-id=>'source_form'},$self->source_form());
# *** Creates a variable to store the snapshot form ***
my $snapshot_form = div({-id=>'snapshot_form'},$self->snapshot_form());
my $sliderform = div({-id=>'slider_form'},$self->sliderform($segment));
# *** Creates the save session button and assigns it to save_prompt ***
my $saveSessionButton = div({-id=>'unsessionbutton', -style=>"position:absolute; right:67px; top: 160px"},$self->render_select_saveSession());
my $saveSessionStyle = "position:absolute;right:20px;top:185px;width:200px;height:45px;background-color:#B4CDCD;z-index:1; border-style:solid;display:none;";
my $save_prompt = div({-id => 'save_snapshot',-style=>"$saveSessionStyle"},
$snapshot_form,
a({-href=>'#', -onClick=>"Controller.hide_snapshot_prompt()", -style=>"position:relative;top:2px"},$close)
);
return $self->toggle('Search',
div({-class=>'searchbody'},
table({-border=>0,-width=>'100%'},
TR(td({-width=>'50%'},$search),td($plugin_form)),
TR(td({-align=>'left'},
$source_form,
),
td({-align=>'left'},
$sliderform || ' '
),
)
),
# *** Makes the save session button and prompt toggle
$saveSessionButton,
$save_prompt,
$self->html_frag('html3',$self->state)
)
)
. div( { -id => "plugin_configure_div"},'');
}
# Plugin Form - Returns the HTML for the plugin form in the main navigation bar.
sub plugin_form {
my $self = shift;
my $settings = $self->state;
return $settings->{GALAXY_URL}
? button(-name => $self->translate('SEND_TO_GALAXY'),
-onClick => $self->galaxy_link).
button(-name => $self->translate('CANCEL'),
-onClick => $self->galaxy_clear.";Controller.update_sections(['plugin_form'])",
)
: join '',(
start_form(-name=>'pluginform',
-id=>'pluginform',
-onSubmit=>'return false'),
$self->plugin_menu(),
end_form);
}
# Source Form - Returns the HTML for the source chooser in the main navigation bar.
sub source_form {
my $self = shift;
join '',(
start_form(-name=>'sourceform',
-id=>'sourceform',
-onSubmit=>''),
$self->source_menu(),
end_form
);
}
# *** Create the snapshot_form ***
sub snapshot_form {
my $self = shift;
# %% Adding form %%
div({
-id=>'snapshot_form',},
input({
-type => "text",
-name => "snapshot_name",
-id => "snapshot_name",
-onKeyPress=>"Controller.submitWithEnter(event);",
-style => "width:180px",
-value => $self->translate('SNAPSHOT_FORM'),
-onClick => "this.value='';"}),
);
}
# Slider Form - Returns the HTML for the zooming controls with the "Flip" checkbox.
sub sliderform {
my $self = shift;
my $segment = shift;
my $settings = $self->state;
if ($segment) {
return
join '',(
start_form(-name=>'sliderform',-id=>'sliderform',-onSubmit=>'return false'),
b($self->translate('Scroll'). ': '),
$self->slidertable($segment),
b(
checkbox(-name=>'flip',
-checked=>$settings->{flip},-value=>1,
-label=>$self->translate('Flip'),-override=>1,
-onClick => 'Controller.update_coordinates(this.name + " " + this.checked)',
)
),
hidden(-name=>'navigate',-value=>1,-override=>1),
end_form
);
}
else {
return '';
}
}
# Render Search For Objects - Returns the "Landmark or Region" search box on the browser tab.
sub render_search_form_objects {
my $self = shift;
my $settings = $self->state;
# avoid exposing the internal database ids to the public
my $search_value = $settings->{name} =~ /^id:/ && $self->region->features
? eval{$self->region->features->[0]->display_name}
: $settings->{name};
my $html = textfield(
-name => 'name',
-id => 'landmark_search_field',
-size => 25,
-default => $search_value,
-override=>1,
);
if ($self->setting('autocomplete')) {
my $spinner_url = $self->data_source->button_url.'/spinner.gif';
$html .= <<END
<span id="indicator1" style="display: none">
<img src="$spinner_url" alt="$self->translate('WORKING')" />
</span>
<div id="autocomplete_choices" class="autocomplete"></div>
END
}
$html .= submit( -name => $self->translate('Search') );
return $html;
}
# Render HTML Head - Returns the HTML for the beginning of the page (for CGI's start HTML function).
sub render_html_head {
my $self = shift;
my ($dsn,$title,@other_initialization) = @_;
my @plugin_list = $self->plugins->plugins;
my $uses_database = $self->user_tracks->database;
# *** Store the snapshot session information in variables ***
my $settings = $self->state;
my $snapshotSessions = $settings->{snapshots};
my @snapshotNames = keys %$snapshotSessions;
my $snapshotsString = join(',',@snapshotNames);
return if $self->{started_html}++;
$title =~ s/<[^>]+>//g; # no markup in the head
# pick scripts
my $js = $dsn->globals->js_url;
my @scripts;
# Set any onTabLoad functions
my $main_page_onLoads = "";
my $track_page_onLoads = '';
my $community_track_page_onLoads = '';
my $custom_track_page_onLoads = "";
my $settings_page_onLoads = "";
# Get plugin onTabLoad functions for each tab, if any
my %plugin_onLoads = map ($_->onLoads, @plugin_list);
$main_page_onLoads .= $plugin_onLoads{'main_page'} if $plugin_onLoads{'main_page'};
$track_page_onLoads .= $plugin_onLoads{'track_page'} if $plugin_onLoads{'track_page'};
$custom_track_page_onLoads .= $plugin_onLoads{'custom_track_page'} if $plugin_onLoads{'custom_track_page'} && $uses_database;
$community_track_page_onLoads .= $plugin_onLoads{'community_track_page'} if $plugin_onLoads{'community_track_page'};
$settings_page_onLoads .= $plugin_onLoads{'settings_page'} if $plugin_onLoads{'settings_page'};
my $onTabScript .= "function onTabLoad(tab_id) {\n";
$onTabScript .= "if (tab_id == 'main_page_select') {$main_page_onLoads}\n";
$onTabScript .= "if (tab_id == 'track_page_select') {$track_page_onLoads}\n";
$onTabScript .= "if (tab_id == 'community_track_page_select') {$community_track_page_onLoads}\n" if $uses_database;
$onTabScript .= "if (tab_id == 'custom_track_page_select') {$custom_track_page_onLoads}\n";
$onTabScript .= "if (tab_id == 'settings_page_select') {$settings_page_onLoads}\n";
$onTabScript .= "};";
push (@scripts,({type=>"text/javascript"}, $onTabScript));
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
push (@scripts,({src=>$url}));
# drag-and-drop functions from scriptaculous
push @scripts,{src=>"$js/$_"}
foreach qw(
prototype.js
scriptaculous.js
subtracktable.js
);
if ($self->setting('autocomplete')) {
push @scripts,{src=>"$js/$_"}
foreach qw(controls.js autocomplete.js);
}
if ($self->globals->user_accounts) {
push @scripts,{src=>"$js/$_"}
foreach qw(login.js);
}
# our own javascript files
push @scripts,{src=>"$js/$_"}
# *** Using toggle.js for snapshots ***
#*** Using SnapshotManager for snapshots ***
foreach qw(
buttons.js
toggle.js
trackFavorites.js
karyotype.js
rubber.js
overviewSelect.js
detailSelect.js
regionSelect.js
track.js
balloon.js
balloon.config.js
GBox.js
ajax_upload.js
tabs.js
track_configure.js
track_pan.js
ruler.js
controller.js
snapshotManager.js
);
# add scripts needed by plugins. Looks in /js folder unless specified.
my @plugin_scripts = map ($_->scripts, @plugin_list);
# add a path if one isn't specified.
foreach (@plugin_scripts) {
if ($_ !~ /^\.{0,2}[\/\\]/) {
$_ = "$js/$_";
}
};
push @scripts,{src=>"$_"} foreach @plugin_scripts;
# pick stylesheets. Looks in /css folder unless specified.
my @stylesheets;
my $titlebar = 'css/titlebar-default.css';
my $stylesheet = $self->setting('stylesheet')||'/gbrowse2/css/gbrowse.css';
push @stylesheets,{src => $self->globals->resolve_path('css/tracks.css','url')};
push @stylesheets,{src => $self->globals->resolve_path('css/subtracktable.css','url')};
push @stylesheets,{src => $self->globals->resolve_path('css/karyotype.css','url')};
push @stylesheets,{src => $self->globals->resolve_path('css/dropdown/dropdown.css','url')};
push @stylesheets,{src => $self->globals->resolve_path('css/dropdown/default_theme.css','url')};
push @stylesheets,{src => $self->globals->resolve_path($titlebar,'url')};
# add stylesheets used by plugins
my @plugin_stylesheets = map ($_->stylesheets, @plugin_list);
# add a path if one isn't specified.
foreach (@plugin_stylesheets) {
if ($_ !~ /^\.{0,2}[\/\\]/) {
$_ = $self->globals->resolve_path("css/$_",'url');
}
};
push @stylesheets,{src => $_} foreach @plugin_stylesheets;
my @theme_stylesheets = shellwords($self->setting('stylesheet') || '/gbrowse2/css/gbrowse.css');
for my $s ( @theme_stylesheets ) {
my ($url,$media) = $s =~ /^([^(]+)(?:\((.+)\))?/;
$media ||= 'all';
push @stylesheets, {
src => $self->globals->resolve_path($url,'url'),
media => $media,
};
}
# colors for "rubberband" selection
my $set_dragcolors = '';
if (my $fill = $self->data_source->global_setting('hilite fill')) {
$fill =~ s/^(\d+,\d+,\d+)$/rgb($1)/;
$fill =~ s/^(#[0-9A-F]{2}[0-9A-F]{2}[0-9A-F]{2})[0-9A-F]{2}$/$1/;
$fill =~ s/^(\w+):[\d.]+$/$1/;
$set_dragcolors = "set_dragcolors('$fill')";
}
my $units = $self->data_source->setting('units') || 'bp';
my $divider = $self->data_source->unit_divider;
my $set_units = "set_dragunits('$units',$divider)";
my @extra_headers;
push @extra_headers, $self->render_user_head;
# put all the html head arguments together
my @args = (-title => $title,
-style => \@stylesheets,
-encoding => $self->translate('CHARSET'),
-script => \@scripts,
-head => \@extra_headers,
);
push @args,(-lang=>($self->language_code)[0]) if $self->language_code;
# add body's onload arguments, including ones used by plugins
my $autocomplete = '';
my $plugin_onloads = join ';',map {eval{$_->body_onloads}} @plugin_list;
my $other_actions = join ';',@other_initialization;
# *** Usings the Sortable commands from script.aculo.us and prototype for snapshots table ***
push @args,(-onLoad => "initialize_page(); $set_dragcolors; $set_units; $plugin_onloads; $other_actions;Sortable.create('snapshotTable',{tag:'div',only:'draggable'});Controller.checkSnapshot()");
return start_html(@args);
}
# 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.
sub render_js_controller_settings {
my ( $self ) = @_;
my $globals = $self->globals;
my @export_keys = qw(
buttons
balloons
openid
js
gbrowse_help
stylesheet
);
my $controller_globals = JSON::to_json({
map { $_ => ( $self->globals->url_path($_) || undef ) } @export_keys
});
my $scripts = "Controller.set_globals( $controller_globals );";
if ($globals->user_accounts) {
my $userdb = $self->userdb;
my $openid = ($userdb->can_openid && $self->globals->user_accounts_allow_openid) ||0;
my $register = ($userdb->can_register && $self->globals->user_accounts_allow_registration)||0;
$scripts .= "Controller.can_openid = $openid;";
$scripts .= "Controller.can_register = $register;";
}
return script({-type=>'text/javascript'}, $scripts);
}
# Renders the settings which control the balloon styles on the page.
sub render_balloon_settings {
my $self = shift;
my $source = $self->data_source;
my $default_style = $source->setting('balloon style') || 'GBubble';;
my $custom_balloons = $source->setting('custom balloons') || "";
my %config_values = $custom_balloons =~ /\[([^\]]+)\]([^\[]+)/g;
# default image path is for the default balloon set
my $balloon_images = $self->globals->balloon_url() || '/gbrowse2/images/balloons';
my $default_images = "$balloon_images/$default_style";
my $balloon_settings = $self->default_balloon_settings($balloon_images);
# handle any custom balloons/config sets
# two args that are interpreted here and not passed
# to the JavaScript:
#
# class = Balloon (could also be Box)
# config set = GPlain (GBubble is the default)
for my $balloon ( keys %config_values ) {
my %config = $config_values{$balloon} =~ /(\w+)\s*=\s*(\S+)/g;
# which balloon configuration set to use?
my $bstyle = $config{'config set'} || $default_style;
delete $config{'config set'};
# which class to use (may be Box or Balloon)
my $bclass = $config{'class'} || 'Balloon';
delete $config{'class'};
# This creates a Ballon (or Box) object and loads the
# specified configuration set.
$balloon_settings .= "\nvar $balloon = new $bclass;\nBalloonConfig($balloon,'$bstyle')\n";
# Image path must be specified
$config{images} ||= $default_images;
for my $option ( keys %config ) {
my $value
= $config{$option} =~ /^[\d.-]+$/
? $config{$option}
: "'$config{$option}'";
$balloon_settings .= "$balloon.$option = $value;\n";
}
}
$balloon_settings =~ s/^/ /gm;
return "\n<script type=\"text/javascript\">\n$balloon_settings\n</script>\n";
}
sub default_balloon_settings {
my $self = shift;
my $balloon_images = shift;
# These are the four configured popup tooltip styles
# GBubble is the global default
# each type can be called using the [name] syntax
return <<END;
// Original GBrowse popup balloon style
var GBubble = new Balloon;
BalloonConfig(GBubble,'GBubble');
GBubble.images = "$balloon_images/GBubble";
GBubble.allowEventHandlers = true;
GBubble.opacity = 1;
GBubble.fontFamily = 'sans-serif';
// A simpler popup balloon style
var GPlain = new Balloon;
BalloonConfig(GPlain,'GPlain');
GPlain.images = "$balloon_images/GPlain";
GPlain.allowEventHandlers = true;
GPlain.opacity = 1;
GPlain.fontFamily = 'sans-serif';
// Like GBubble but fades in
var GFade = new Balloon;
BalloonConfig(GFade,'GFade');
GFade.images = "$balloon_images/GBubble";
GFade.opacity = 1;
GFade.allowEventHandlers = true;
GFade.fontFamily = 'sans-serif';
// A formatted box
// Note: Box is a subclass of Balloon
var GBox = new Box;
BalloonConfig(GBox,'GBox');
GBox.images = "$balloon_images/GBubble";
GBox.allowEventHandlers = true;
GBox.evalScripts = true;
GBox.opacity = 1;
GBox.fontFamily = 'sans-serif';
GBox.maxWidth = 1280;
GBox.stemHeight = 0;
END
}
sub render_select_menus { # for popup balloons
my $self = shift;
my $html = '';
$html .= $self->_render_select_menu($_)
foreach (qw(DETAIL OVERVIEW REGION));
return $html;
}
sub _render_select_menu {
my $self = shift;
my $view = shift || 'DETAIL';
my $config_label = uc($view).' SELECT MENU';
# HTML for the custom menu is required
my $menu_html = $self->setting($config_label => 'HTML')
|| $self->setting($config_label => 'html')
|| return '';
# should not be visible
my %style = (display => 'none');
# optional style attributes
for my $att (qw/width font background background-color border/) {
my $val = $self->setting($config_label => $att) || next;
$style{$att} = $val;
}
$style{width} .= 'px';
my $style = join('; ', map {"$_:$style{$_}"} keys %style);
# clean up the HTML just a bit
$menu_html =~ s/\</\n\</g;
return div( { -style => $style,
-id => lc($view).'SelectMenu' },
$menu_html );
}
# Returns the HTML for the page's title, as displayed at the top.
sub render_title {
my $self = shift;
my $title = shift;
my $error = shift;
my $settings = $self->state;
return $settings->{head}
? h1({-id=>'page_title',-class=>$error ? 'error' : 'normal'},$title)
: '';
}
# *** Function to render the snapshot title ***
sub render_snapshotTitle {
my $self = shift;
my $error = shift;
my $currentSnapshot = $self->translate('CURRENT_SNAPSHOT');
my $settings = $self->state;
my $title = ($settings->{snapshot_active}) ? $settings->{current_session} : " ";
if ($settings->{snapshot_active}){
return h1({-id=>'snapshot_page_title',-class=>'normal'},"Current Snapshot : $title");
}else{
return h1({-id=>'snapshot_page_title',-class=>'normal', -style=>'display: none;'},"Current Snapshot : $title");}
}
# Renders the search & navigation instructions & examples.
sub render_instructions {
my $self = shift;
my $settings = $self->state;
my $oligo = $self->plugins->plugin('OligoFinder') ? ', oligonucleotide (15 bp minimum)' : '';
return $settings->{head}
? div({-class=>'searchtitle'},
$self->toggle('Instructions',
div({-style=>'margin-left:2em'},
$self->setting('search_instructions') ||
$self->translate('SEARCH_INSTRUCTIONS', $oligo),
$self->setting('navigation_instructions') ||
$self->translate('NAVIGATION_INSTRUCTIONS'),
br(),
$self->examples(),
br(),$self->html_frag('html2',$self->state)
)
)
)
: '';
}
# Renders the HTML for the spinning "busy" signal on the top-left corner of the page.
sub render_busy_signal {
my $self = shift;
return img({
-id => 'busy_indicator',
-src => $self->data_source->button_url.'/spinner.gif',
-style => 'position: fixed; top: 5px; left: 5px; display: none',
-alt => ($self->translate('WORKING')||'')
});
}
# Renders the menu bar across the top of the browser.
sub render_actionmenu {
my $self = shift;
my $settings = $self->state;
my @export_links=a({-href=>'#',-onclick=>'Controller.make_image_link("GD")'}, $self->translate('IMAGE_LINK'));
push @export_links,a({-href=>'#',-onclick=>'Controller.make_image_link("GD::SVG")'}, $self->translate('SVG_LINK'))
if HAVE_SVG;
push @export_links,a({-href=>'#',-onclick=>'Controller.make_image_link("PDF")'}, $self->translate('PDF_LINK'))
if HAVE_SVG && $self->can_generate_pdf;
# Pass the gff link to a javascript function which will add the missing parameters that are determined client-side
push @export_links,a({-href=>'#',-onclick=>"Controller.gbgff_link('". $self->gff_dump_link ."')"}, $self->translate('DUMP_GFF'));
push @export_links,a({-href=>'#',-onclick=>"Controller.gbgff_link('". $self->dna_dump_link ."')"}, $self->translate('DUMP_SEQ'));
push @export_links,a({-href=>'javascript:'.$self->galaxy_link}, $self->translate('SEND_TO_GALAXY'))
if $self->data_source->global_setting('galaxy outgoing');
my $bookmark_link = a({-href=>'#',-onclick=>'Controller.bookmark_link()'},$self->translate('BOOKMARK')),;
my $share_link = a({-href => '#',
-onMouseDown => "GBox.showTooltip(event,'url:?action=share_track;track=all')"},
($self->translate('SHARE_ALL') || "Share These Tracks" )),
my $help_link = a({-href=>$self->general_help(),
-target=>'_new'},$self->translate('HELP_WITH_BROWSER'));
my $about_gb_link = a({-onMouseDown => "Controller.show_info_message('about_gbrowse')",
-href => 'javascript:void(0)',
-style => 'cursor:pointer'
},
$self->translate('ABOUT'));
my $about_dsn_link = a({-onMouseDown => "Controller.show_info_message('about_dsn')",
-href => 'javascript:void(0)',
-style => 'cursor:pointer'
},
$self->translate('ABOUT_DSN'));
my $about_me_link = a({-onMouseDown => "Controller.show_info_message('about_me')",
-href => 'javascript:void(0)',
-style => 'cursor:pointer'
},
$self->translate('ABOUT_ME'));
my $plugin_link = $self->plugin_links($self->plugins);
my $chrom_sizes_link = a({-href=>'?action=chrom_sizes'},$self->translate('CHROM_SIZES'));
my $reset_link = a({-href=>'?reset=1',-class=>'reset_button'}, $self->translate('RESET'));
my $login = $self->globals->user_accounts ? $self->render_login : '';
my $file_menu = ul({-id => 'actionmenu',
-class => 'dropdown downdown-horizontal'},
li({-class=>'dir'},$self->translate('FILE'),
ul(li($bookmark_link),
li($share_link),
li({-class=>'dir'},a({-href=>'#'},$self->translate('EXPORT')),
ul(li(\@export_links))),
$plugin_link ? li($plugin_link) : (),
li($chrom_sizes_link),
li($reset_link),
)
),
li({-class=>'dir'},$self->translate('HELP'),
ul({-class=>'dropdown'},
li($help_link),
li({-class=>'divider'},''),
li($about_gb_link),
li($about_dsn_link),
li($about_me_link),
)),
);
return div({-class=>'datatitle'},$file_menu,$login,br({-clear=>'all'}));
}
# Render Login - Returns the HTML for the login links on the top-right corner of the screen.
sub render_login {
my $self = shift;
my $settings = $self->state;
return unless $settings->{head};
return $self->login_manager->render_login;
}
# For the subset of plugins that are named in the 'quicklink plugins' option, create quick links for them.
sub plugin_links {
my $self = shift;
my $plugins = shift;
my $quicklink_setting = $self->setting('quicklink plugins') or return '';
my @plugins = shellwords($quicklink_setting) or return '';
my $labels = $plugins->menu_labels;
my @result;
for my $p (@plugins) {
my $plugin = $plugins->plugin($p) or next;
my $action = "?plugin=$p;plugin_do=".$self->translate('Go');
push @result,a({-href=>$action,-target=>'_new'},"[$labels->{$p}]");
}
return \@result;
}
sub galaxy_form {
my $self = shift;
my $segment = shift;
my $settings = $self->state;
my $source = $self->data_source;
my $galaxy_url = $settings->{GALAXY_URL}
|| $source->global_setting('galaxy outgoing') ;
return '' unless $galaxy_url;
my $URL = $source->global_setting('galaxy incoming');
$URL ||= $self->globals->gbrowse_url();
# Make sure to include all necessary parameters in URL to ensure that gbrowse will retrieve the data
# when Galaxy posts the URL.
my $dbkey = $source->global_setting('galaxy build name') || $source->name;
my $labels = $self->join_selected_tracks;
my $seg = $segment->seq_id.':'.$segment->start.'..'.$segment->end;
my $action = $galaxy_url =~ /\?/ ? "$galaxy_url&URL=$URL" : "$galaxy_url?URL=$URL";
my $html = start_multipart_form(-name => 'galaxyform',
-action => $action,
-method => 'POST');
$html .= hidden(-name=>'dbkey',-value=>$dbkey);
$html .= hidden(-name=>'gbgff',-value=>'save gff3');
$html .= hidden(-name=>'id', -value=>$settings->{userid});
$html .= hidden(-name=>'q',-value=>$seg);
$html .= hidden(-name=>'l',-value=>$labels);
$html .= hidden(-name=>'s',-value=>0);
$html .= hidden(-name=>'d',-value=>'edit');
$html .= hidden(-name=>'m',-value=>'application/x-gff3');
$html .= endform();
return $html;
}
sub render_track_filter {
my $self = shift;
my $plugin = shift;
my $form = $plugin->configure_form();
my $plugin_type = $plugin->type;
my $action = $self->translate('Configure_plugin');
my $name = $plugin->name;
my $showfav = $self->translate('FAVORITES');
my $showall = $self->translate('SHOWALL');
return
div({-id=>'track select',-style=>'padding-top:8px'},
start_form({-id => 'track_filterform',
-name => 'configure_plugin',
-onSubmit=> 'return false'}),
$form,
hidden(-name=>'plugin',-value=>$name),
button(
-name => 'plugin_button',
-value => $self->translate('search'),
-onClick => 'doPluginUpdate()',
),
end_form(),
script({-type=>'text/javascript'},
"function doPluginUpdate() { Controller.reconfigure_plugin('$action',null,null,'$plugin_type',\$('track_filterform'));updateTitle(\$('show_all_link'),0);}")
);
}
# This surrounds the track table with a toggle
sub render_toggle_track_table {
my $self = shift;
my $source = $self->data_source;
my $filter = $self->track_filter_plugin;
my $settings = $self->state;
# $settings->{show_favorites} =0;
## adding javascript array at the top so we can pass it into a js array -- ugly but it works
my $html = '';
$html .= div({-style=>'font-weight:bold'},
span({-style=>'padding-right:80px'},'<<',$self->render_select_browser_link('link')),
span({-id => 'showfavoritestext',-style=>'padding-right:80px'},
$self->render_select_favorites_link('link')),
span({-id => 'clearfavs'},
$self->render_select_clear_link('link')));
if (my $filter = $self->track_filter_plugin) {
$html .= $self->toggle({tight=>1},'track_select',div({class=>'searchtitle',
style=>"text-indent:2em;padding-top:8px; display:block;"},
$self->render_track_filter($filter)));
}
$html .= $self->toggle('Tracks',$self->render_track_table);
$html .= div({-style=>'text-align:center'},$self->render_select_browser_link('button'));
return $html;
}
sub render_track_table {
my $self = shift;
my $listing_class = $self->data_source->track_listing_class;
eval "require $listing_class;1" or die $@ unless $listing_class->can('new');
my $tlr = $listing_class->new($self);
return $tlr->render_track_listing.$self->html_frag('html5',$self->state);
}
# Render Multiple Choices -
sub render_multiple_choices {
my $self = shift;
my $features = shift;
my $terms2hilite = shift;
my $karyotype = Bio::Graphics::Karyotype->new(source => $self->data_source,
language => $self->language);
$karyotype->add_hits($features);
return $karyotype->to_html($terms2hilite);
}
# Render Global Config - Returns the HTML for the Preferences page.
sub render_global_config {
my $self = shift;
my $settings = $self->state;
my @widths = split /\s+/, $self->setting('image widths');
@widths = ( 640, 800, 1024 ) unless @widths;
my @key_positions = qw(between bottom);
push @key_positions, qw(left right)
if Bio::Graphics::Panel->can('auto_pad');
my $feature_highlights = $settings->{h_feat}
? join ' ',
map {"$_\@$settings->{h_feat}{$_}"} keys %{ $settings->{h_feat} }
: '';
my $region_highlights = $settings->{h_region}
? join ' ', @{ $settings->{h_region} }
: '';
my %seen;
my $region_size = $settings->{region_size} || 0;
my @region_size = shellwords($self->data_source->global_setting('region sizes'));
my @region_sizes = grep {!$seen{$_}++}
sort {$b<=>$a}
grep {defined $_ && $_ > 0} ($region_size,@region_size);
my $content
= start_form( -name => 'display_settings', -id => 'display_settings' )
. div(
table ({-border => 0, -cellspacing=>0, -width=>'100%'},
TR(
td( b( checkbox(
-name => 'grid',
-label => $self->translate('SHOW_GRID'),
-override => 1,
-checked => $settings->{grid} || 0,
-onChange => 'Controller.set_display_option(this.name,this.checked ? 1 : 0)',
)
)
),
td( b( $self->translate('Image_width') ),
br,
radio_group(
-name => 'width',
-values => \@widths,
-default => $settings->{width},
-override => 1,
-onChange => 'Controller.set_display_option(this.name,this.value)',
),
),
td( span(
{ -title => $self->translate('FEATURES_TO_HIGHLIGHT_HINT') },
b( $self->translate('FEATURES_TO_HIGHLIGHT') ),
br,