Handle hostnames with upper-case letters
[webmin.git] / Webmin / DynamicBar.pm
1 package Webmin::DynamicBar;
2 use WebminCore;
3
4 =head2 new Webmin::DynamicBar(&start-function, max)
5 A page element for displaying progress towards some goal, like the download of
6 a file.
7 =cut
8 sub new
9 {
10 my ($self, $func, $max) = @_;
11 $self = { 'func' => $func,
12           'name' => "dynamic".++$dynamic_count,
13           'width' => 80,
14           'max' => $max };
15 bless($self);
16 return $self;
17 }
18
19 =head2 set_message(text)
20 Sets the text describing what we are waiting for
21 =cut
22 sub set_message
23 {
24 my ($self, $message) = @_;
25 $self->{'message'} = $message;
26 }
27
28 sub get_message
29 {
30 my ($self) = @_;
31 return $self->{'message'};
32 }
33
34 =head2 html()
35 Returns the HTML for the text field
36 =cut
37 sub html
38 {
39 my ($self) = @_;
40 my $rv;
41 if ($self->get_message()) {
42         $rv .= $self->get_message()."<p>\n";
43         }
44 $rv .= "<form name=form_$self->{'name'}>";
45 $rv .= "<input name=bar_$self->{'name'} size=$self->{'width'} disabled=true style='font-family: courier'>";
46 $rv .= "&nbsp;";
47 $rv .= "<input name=pc_$self->{'name'} size=3 disabled=true style='font-family: courier'>%";
48 $rv .= "</form>";
49 return $rv;
50 }
51
52 =head2 start()
53 Called by the page to begin the progress
54 =cut
55 sub start
56 {
57 my ($self) = @_;
58 &{$self->{'func'}}($self);
59 }
60
61 =head2 update(pos)
62 Called by the function to update the position of the bar.
63 =cut
64 sub update
65 {
66 my ($self, $pos) = @_;
67 my $pc = int(100*$pos/$self->{'max'});
68 if ($pc != $self->{'lastpc'}) {
69         my $xn = int($self->{'width'}*$pos/$self->{'max'});
70         my $xes = "X" x $xn;
71         print "<script>window.document.forms[\"form_$self->{'name'}\"].pc_$self->{'name'}.value = \"$pc\";</script>\n";
72         print "<script>window.document.forms[\"form_$self->{'name'}\"].bar_$self->{'name'}.value = \"$xes\";</script>\n";
73         $self->{'lastpc'} = $pc;
74         }
75 }
76
77 =head2 set_wait(wait)
78 If called with a non-zero arg, generation of the page should wait until this
79 the progress is complete. Otherwise, the page will be generated completely before
80 the start function is called
81 =cut
82 sub set_wait
83 {
84 my ($self, $wait) = @_;
85 $self->{'wait'} = $wait;
86 }
87
88 sub get_wait
89 {
90 my ($self) = @_;
91 return $self->{'wait'};
92 }
93
94 =head2 set_page(Webmin::Page)
95 Called when this dynamic text box is added to a page
96 =cut
97 sub set_page
98 {
99 my ($self, $page) = @_;
100 $self->{'page'} = $page;
101 }
102
103 sub set_width
104 {
105 my ($self, $width) = @_;
106 $self->{'width'} = $width;
107 }
108
109 =head2 needs_unbuffered()
110 Must return 1 if the page needs to be in un-buffered and no-table mode
111 =cut
112 sub needs_unbuffered
113 {
114 return 0;
115 }
116
117
118 1;
119