forked from webmin/webmin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDynamicBar.pm
119 lines (105 loc) · 2.35 KB
/
DynamicBar.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
package WebminUI::DynamicBar;
use WebminCore;
=head2 new WebminUI::DynamicBar(&start-function, max)
A page element for displaying progress towards some goal, like the download of
a file.
=cut
sub new
{
my ($self, $func, $max) = @_;
$self = { 'func' => $func,
'name' => "dynamic".++$dynamic_count,
'width' => 80,
'max' => $max };
bless($self);
return $self;
}
=head2 set_message(text)
Sets the text describing what we are waiting for
=cut
sub set_message
{
my ($self, $message) = @_;
$self->{'message'} = $message;
}
sub get_message
{
my ($self) = @_;
return $self->{'message'};
}
=head2 html()
Returns the HTML for the text field
=cut
sub html
{
my ($self) = @_;
my $rv;
if ($self->get_message()) {
$rv .= $self->get_message()."<p>\n";
}
$rv .= "<form name=form_$self->{'name'}>";
$rv .= "<input name=bar_$self->{'name'} size=$self->{'width'} disabled=true style='font-family: courier'>";
$rv .= " ";
$rv .= "<input name=pc_$self->{'name'} size=3 disabled=true style='font-family: courier'>%";
$rv .= "</form>";
return $rv;
}
=head2 start()
Called by the page to begin the progress
=cut
sub start
{
my ($self) = @_;
&{$self->{'func'}}($self);
}
=head2 update(pos)
Called by the function to update the position of the bar.
=cut
sub update
{
my ($self, $pos) = @_;
my $pc = int(100*$pos/$self->{'max'});
if ($pc != $self->{'lastpc'}) {
my $xn = int($self->{'width'}*$pos/$self->{'max'});
my $xes = "X" x $xn;
print "<script>window.document.forms[\"form_$self->{'name'}\"].pc_$self->{'name'}.value = \"$pc\";</script>\n";
print "<script>window.document.forms[\"form_$self->{'name'}\"].bar_$self->{'name'}.value = \"$xes\";</script>\n";
$self->{'lastpc'} = $pc;
}
}
=head2 set_wait(wait)
If called with a non-zero arg, generation of the page should wait until this
the progress is complete. Otherwise, the page will be generated completely before
the start function is called
=cut
sub set_wait
{
my ($self, $wait) = @_;
$self->{'wait'} = $wait;
}
sub get_wait
{
my ($self) = @_;
return $self->{'wait'};
}
=head2 set_page(WebminUI::Page)
Called when this dynamic text box is added to a page
=cut
sub set_page
{
my ($self, $page) = @_;
$self->{'page'} = $page;
}
sub set_width
{
my ($self, $width) = @_;
$self->{'width'} = $width;
}
=head2 needs_unbuffered()
Must return 1 if the page needs to be in un-buffered and no-table mode
=cut
sub needs_unbuffered
{
return 0;
}
1;