]> git.proxmox.com Git - pve-manager.git/blame - lib/PVE.old/HTMLTable.pm
imported from svn 'pve-manager/pve2'
[pve-manager.git] / lib / PVE.old / HTMLTable.pm
CommitLineData
aff192e6
DM
1package PVE::HTMLTable;
2
3use strict;
4use vars qw(@ISA);
5
6sub new {
7 my ($type, $width) = @_;
8
9 my $self = {};
10
11 $self->{rowcount} = 0;
12 $self->{link_edit} = '';
13 $self->{width} = $width;
14 bless($self);
15
16 return $self;
17}
18sub link_edit {
19 my ($self, $v) = @_;
20 if (defined($v)) {
21 $self->{link_edit} = $v;
22 }
23 $self->{link_edit};
24}
25
26sub add_headline {
27 my ($self,$headinfo) = @_;
28 $self->{headline} = $headinfo;
29}
30
31sub set_param {
32 my ($self, $v) = @_;
33 if (defined($v)) {
34 $self->{rowdata}->{$self->{rowcount}}->{param} = $self->{rowdata}->{$self->{rowcount}}->{param} . "&" . $v;
35 }
36 return "";
37}
38sub get_param {
39 my ($self, $row) = @_;
40 if (defined($row)) {
41 return $self->{rowdata}->{$row}->{param};
42 } else {
43 return "";
44 }
45}
46sub set_row_link {
47 my ($self,$lnk,$row) = @_;
48 my $i;
49 if (!(defined($row))) { $row = $self->{rowcount}; }
50 $self->{rowdata}->{$row}->{lnk} = $lnk;
51 return $self;
52}
53
54sub set_col_span {
55 my ($self,$span,$row) = @_;
56 if (!(defined($row))) { $row = $self->{rowcount}; }
57 $self->{rowdata}->{$row}->{span} = $span;
58 return $self;
59}
60
61sub add_row {
62 my ($self,$id,@row) = @_;
63 my $i;
64
65 $self->{rowdata}->{$self->{rowcount}}->{len} = $#row;
66 $self->{rowdata}->{$self->{rowcount}}->{id} = $id;
67
68 for $i (0 .. $#row) {
69 $self->{rowdata}->{$self->{rowcount}}->{"$i"} = $row[$i];
70 }
71 $self->{rowcount} = $self->{rowcount} + 1;
72 return $self;
73}
74
75sub out_header {
76 my ($self, $width) = @_;
77
78 # NOTE: width = 100% if not specified
79 # but you can also pass 0 or '' to avoid that behaviour
80
81 if (!defined ($width)) { $width='100%'; }
82
83 my $htmlout = "<table class='normal' cellspacing=0 cellpadding=3";
84
85 $htmlout .= " style='width:$width;'" if $width;
86
87 $htmlout .= ">";
88
89 return $htmlout;
90}
91
92sub out_headline {
93 my ($self) = @_;
94
95 return "" if !$self->{headline};
96
97 my @headinfo = @{$self->{headline}};
98
99 my $htmlout = "<thead><tr>";
100 for my $i (0 .. ($#headinfo/3)) {
101 my ($span, $width, $text) = ($headinfo[$i*3], $headinfo[($i*3)+1],$headinfo[($i*3)+2]);
102 $htmlout .= "<th colspan=$span ";
103 $htmlout .= " style='width:$width;'" if $width;
104 $htmlout .= ">$text</th>";
105 }
106 $htmlout .= "</tr></thead>";
107 return $htmlout;
108}
109
110
111sub out_footer {
112 my ($self) = @_;
113
114 return "</table>";
115}
116
117sub out_celldata {
118 my ($self,$row,$col) = @_;
119 my $data = $self->{rowdata}->{"$row"}->{"$col"};
120 return $data;
121}
122
123sub out_table {
124 my ($self, $width, $sel) = @_;
125
126 my $htmlout = "";
127 my $col1 = "#EDEDED";
128 my $col2 = "#FFFFFF";
129 my $col3 = "#FFF3BF";
130 # Tableheader
131 $htmlout .= $self->out_header($width);
132
133 # Tableheadline
134 $htmlout .= $self->out_headline ();
135
136 $htmlout .= "<tbody>";
137
138 #Tablecontent
139 for my $i (0 .. ($self->{rowcount}-1)) {
140 my $col = $i % 2 ? $col2 : $col1;
141
142 $col = $col3 if defined ($sel) && $sel == $i;
143
144 $htmlout .= "<tr style='background-color:$col;'";
145
146 my $rid = $self->{rowdata}->{$i}->{id};
147 $htmlout .= " id='$rid'" if $rid;
148
149 if (defined($self->{rowdata}->{$i}->{lnk})) {
150 $htmlout .= " class='link' onClick='goTo(\"$self->{rowdata}->{$i}->{lnk}\");'";
151 }
152
153 $htmlout .= ">";
154
155 my @wa = @{$self->{width}};
156 my $span = $self->{rowdata}->{$i}->{span};
157 for my $c (0 .. $self->{rowdata}->{"$i"}->{len}) {
158 my $sw = "";
159 if (defined ($span) && (@$span[$c] > 1)) {
160 $sw = "colspan=@$span[$c]";
161 }
162 my $wtxt = $wa[$c] ? "width:$wa[$c];" : '';
163 $htmlout .= "<td $sw style='$wtxt'>".$self->out_celldata($i, $c)."</td>";
164
165 $c += @$span[$c] - 1 if $sw;
166 }
167 $htmlout .= "</tr>\n";
168 }
169
170 $htmlout .= "</tbody>";
171
172 # Tablefooter
173 $htmlout .= $self->out_footer();
174
175 return $htmlout;
176}
177
1781;