Repository navigation
Expand file tree
/
Copy pathTabView.pm
More file actions
383 lines (292 loc) · 9.57 KB
/
Copy pathTabView.pm
File metadata and controls
383 lines (292 loc) · 9.57 KB
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
package WebComponent::TabView;
# TabView - component for a tabular view
# $Id: TabView.pm,v 1.22 2011-01-22 17:54:36 redwards Exp $
use strict;
use warnings;
use Data::Dumper;
use base qw( WebComponent );
1;
=pod
=head1 NAME
TabView - component for a tabular view
=head1 DESCRIPTION
WebComponent for a tabular view
=head1 METHODS
=over 4
=item * B<new> ()
Called when the object is initialized. Expands SUPER::new.
=cut
sub new {
my $self = shift->SUPER::new(@_);
$self->{tabs} = [];
$self->{subtabs} = {};
$self->{sub_default} = {};
$self->{width} = 300;
$self->{height} = 200;
$self->{default} = 0;
$self->{orientation} = "horizontal";
$self->{dynamic} = 0;
return $self;
}
=item * B<output> ()
Returns the html output of the TabView component.
=cut
sub output {
my ($self) = @_;
# open surrounding table
my $width = "width: " . $self->width() . "px;";
my $height = "height: " . $self->height() . "px;";
my ($tabview, $hidden)=("", "");
if ($self->dynamic()) {
# only supported for horizontal tabs
if ($self->orientation() eq 'horizontal') {
$tabview .= "<input type='hidden' id='tab_view_dynamic_" . $self->id . "' value='yes' />";
if (@{$self->{tabs}} == 0) {
$hidden = 'display: none;';
}
} else {
if (@{$self->{tabs}} == 0) {
die "Using tabular view without tabs.";
}
}
} else {
if (@{$self->{tabs}} == 0) {
die "Using tabular view without tabs.";
}
}
$tabview .= "<input type='hidden' id='" . $self->{_id} . "' value='" . $self->id() . "' />";
$tabview .= "<table style='$height $width $hidden border-spacing: 0px;border-collapse: expression(\"separate\", cellSpacing = \"0px\");' id='tab_view_table_" . $self->id . "'>";
# create tabview titles
my $first = 1;
my $i = 0;
my $class;
# check total number of tabs
my $total = 0;
foreach my $tab (@{$self->{tabs}}) {
$total ++;
if (exists($self->{subtabs}->{$i})) {
$total += scalar(@{$self->{subtabs}->{$i}});
}
$i++;
}
$i = 0;
# check for horizontal or vertical tabview
if ($self->orientation eq "horizontal") {
$tabview .= "<tr>";
foreach my $tab (@{$self->{tabs}}) {
if ($i == $self->default()) {
$class = "tab_view_title_selected";
} else {
$class = "tab_view_title";
}
my $onclick = " onclick='tab_view_select(\"" . $self->id . "\", \"" . $i . "\");'";
if ($tab->{disabled}) {
$onclick = "";
}
$tabview .= "<td class='$class' name='" . $self->id . "_tabs' id='" . $self->id . "_tab_" . $i . "'$onclick>" . $tab->{name} . "</td>";
$i++;
}
$tabview .= "<td class='tab_view_title_filler'> </td></tr>";
# create content cell
$tabview .= "<tr><td colspan='" . ($total + 1) . "' class='tab_view_content_td'>";
$first = 1;
$i = 0;
foreach my $tab (@{$self->{tabs}}) {
if ($i == $self->default()) {
$class = "tab_view_content_selected";
} else {
$class = "tab_view_content";
}
my $div_id = $self->id . "_content_" . $i;
$tabview .= "<div style='height: 100%; width: 100%;' class='$class' name='" . $self->id . "_contents' id='" . $div_id . "'>" . $tab->{content} . "</div>";
# Format a hidden form for JS to call execute_ajax on
if( $tab->{'ajax'} ){
$tabview .= "<input type=\"hidden\" id=\"".$self->id."_tabajax_".$i."\" value=\"0;".$tab->{ajax}->[0].";".$div_id.";".$tab->{ajax}->[1];
if(@{$tab->{'ajax'}} == 3) { $tabview .= ";".$tab->{ajax}->[2]."\" >"; }
else { $tabview .= "\" >"; }
}
$i++;
}
$tabview .= "</td></tr>";
} else {
$i = 0;
foreach my $tab (@{$self->{tabs}}) {
$tabview .= "<tr>";
if ($i == $self->default()) {
$class = "tab_view_title_vertical_selected";
} else {
$class = "tab_view_title_vertical";
}
my $onclick = " onclick='tab_view_select(\"" . $self->id . "\", \"" . $i . "\", \"vert\");'";
if ($tab->{disabled}) {
$onclick = "";
}
$tabview .= "<td class='$class' name='" . $self->id . "_tabs' id='" . $self->id . "_tab_" . $i . "'$onclick>" . $tab->{name} . "</td>";
if ($first) {
$first = 0;
$tabview .= "<td width=100% rowspan='" . ($total + 1) . "' class='tab_view_content_vertical_td'>";
my $h = 0;
foreach my $tab2 (@{$self->{tabs}}) {
my $class2 = "tab_view_content";
if ($h == $self->default()) {
$class2 = "tab_view_content_vertical_selected";
}
# check for subtabs
if (exists($self->{subtabs}->{$h})) {
my $f = 0;
foreach my $subtab2 (@{$self->{subtabs}->{$h}}) {
my $class2 = "tab_view_content";
if ($h == $self->default && $f == $self->sub_default($h)) {
$class2 = "tab_view_content_vertical_selected";
}
$tabview .= "<div style='height: 100%; width: 100%;' class='$class2' name='" . $self->id . "_contents' id='" . $self->id . "_content_" . $h . "_" . $f . "'>" . $subtab2->{content} . "</div>";
$f++;
}
}
else{
$tabview .= "<div style='height: 100%; width: 100%;' class='$class2' name='" . $self->id . "_contents' id='" . $self->id . "_content_" . $h . "'>" . $tab2->{content} . "</div>";
}
$h++;
}
$tabview .= "</td>";
}
$tabview .= "</tr>";
# Add sub tab labels
if (exists($self->{subtabs}->{$i})) {
my $g = 0;
foreach my $subtab (@{$self->{subtabs}->{$i}}) {
my $onclick = " onclick='tab_view_select(\"" . $self->id . "\", \"" . $i . "\", \"sub\", \"" . $g . "\");'";
if ($subtab->{disabled}) {
$onclick = '';
}
$tabview .= "<tr><td class='$class' id='" . $self->id . "_subtab_" . $i . "_" . $g . "'$onclick>" . $subtab->{name} . "</td>";
$g++;
}
}
$i++;
}
$tabview .= "<tr><td class='tab_view_title_vertical_filler'> </td></tr>";
}
# close table
$tabview .= "</table>";
# on load select the default tab
my $ori = ", \"1\"";
if ($self->orientation eq "horizontal") {
$ori = "";
}
my $onload = " onload='initialize_tab_view(\"" . $self->id . "\");";
if ($hidden eq '') {
$onload .= " tab_view_select(\"" . $self->id . "\", \"" . $self->default() . "\"$ori);'";
} else {
$onload .= "'";
}
$tabview .= "\n<img src='$Conf::cgi_url/Html/clear.gif' $onload>\n";
return $tabview;
}
=item * B<add_tab> (I<tab_name>, I<tab_content>, I<disabled>)
Adds a tab to the tab view
=cut
sub add_tab {
my $self = shift;
my $tab_name = shift;
my $tab_content = shift;
my $ajax;
my $disabled;
foreach my $i (@_) {
if(ref($i) eq 'ARRAY') {
$ajax = $i;
} else { $disabled = $i }
}
unless (defined($tab_name) && defined($tab_content)) {
die "tab_name or tab_content not set in add_tab (name:$tab_name\ncontent:$tab_content)";
}
push(@{$self->{tabs}}, { name => $tab_name, content => $tab_content, ajax => $ajax || 0, disabled => $disabled || 0 });
return 1;
}
=item * B<add_sub_tab> (I<supertab>, I<tab_name>, I<tab_content>, I<disabled>)
Adds a sub-tab to the tab view
=cut
sub add_sub_tab {
my ($self, $supertab, $tab_name, $tab_content, $disabled) = @_;
unless (defined($supertab) && defined($tab_name) && defined($tab_content)) {
die "supertab, tab_name or tab_content not set in add_sub_tab";
}
unless (exists($self->{subtabs}->{$supertab})) {
$self->{subtabs}->{$supertab} = [];
}
push(@{$self->{subtabs}->{$supertab}}, { name => $tab_name, content => $tab_content, disabled => $disabled || 0 });
return 1;
}
=item * B<width> (I<width>)
Getter / Setter for the width attribute.
This determines the width of the component in pixels.
=cut
sub width {
my ($self, $width) = @_;
if (defined($width)) {
$self->{width} = $width;
}
return $self->{width};
}
=item * B<height> (I<height>)
Getter / Setter for the height attribute.
This determines the height of the component in pixels. The height
of the tab headers will still be added to this value.
=cut
sub height {
my ($self, $height) = @_;
if (defined($height)) {
$self->{height} = $height;
}
return $self->{height};
}
=item * B<default> (I<default>)
Getter / Setter for the default attribute.
This determines the which tab is initially in front.
=cut
sub default {
my ($self, $default) = @_;
if (defined($default)) {
$self->{default} = $default;
}
return $self->{default};
}
sub sub_default {
my ($self, $super, $sub) = @_;
unless (defined($super)) {
$super = 0;
}
if (defined($sub)) {
$self->{sub_default}->{$super} = $sub;
}
my $sub_default = 0;
if (exists($self->{sub_default}->{$super})) {
$sub_default = $self->{sub_default}->{$super};
}
return $sub_default;
}
=item * B<orientation> (I<orientation>)
Getter / Setter for the orientation attribute.
This determines the orientation of the tab view. This can be either
'horizontal' or 'vertical'. Default is 'horizontal'.
=cut
sub orientation {
my ($self, $orientation) = @_;
if (defined($orientation)) {
$self->{orientation} = $orientation;
}
return $self->{orientation};
}
sub dynamic {
my ($self, $dynamic) = @_;
if (defined($dynamic)) {
$self->{dynamic} = $dynamic;
}
return $self->{dynamic};
}
sub require_css {
return "$Conf::cgi_url/Html/TabView.css";
}
sub require_javascript {
return ["$Conf::cgi_url/Html/TabView.js"];
}