Handle hostnames with upper-case letters
[webmin.git] / Webmin / DynamicWait.pm
1 package Webmin::DynamicWait;
2 use WebminCore;
3
4 =head2 new Webmin::DynamicWait(&start-function, [&args])
5 A page element indicating that something is happening.
6 =cut
7 sub new
8 {
9 my ($self, $func, $args) = @_;
10 $self = { 'func' => $func,
11           'args' => $args,
12           'name' => "dynamic".++$dynamic_count,
13           'width' => 80,
14           'delay' => 20 };
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 used to indicate progress
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=$self->{'name'} size=$self->{'width'} disabled=true style='font-family: courier'>";
46 $rv .= "</form>";
47 return $rv;
48 }
49
50 =head2 start()
51 Called by the page to begin the progress. Also starts a process to update the
52 Javascript text box
53 =cut
54 sub start
55 {
56 my ($self) = @_;
57 $self->{'pid'} = fork();
58 if (!$self->{'pid'}) {
59         my $pos = 0;
60         while(1) {
61                 select(undef, undef, undef, $self->{'delay'}/1000.0);
62                 my $str = (" " x $pos) . ("x" x 10);
63                 print "<script>window.document.forms[\"form_$self->{'name'}\"].$self->{'name'}.value = \"$str\";</script>\n";
64                 $pos++;
65                 $pos = 0 if ($pos == $self->{'width'});
66                 }
67         exit;
68         }
69 &{$self->{'func'}}($self, @{$self->{'args'}});
70 }
71
72 =head2 stop()
73 Called back by the function when whatever we were waiting for is done
74 =cut
75 sub stop
76 {
77 my ($self) = @_;
78 if ($self->{'pid'}) {
79         kill('TERM', $self->{'pid'});
80         }
81 my $str = (" " x ($self->{'width'}/2 - 2)) . "DONE";
82 print "<script>window.document.forms[\"form_$self->{'name'}\"].$self->{'name'}.value = \"$str\";</script>\n";
83 }
84
85 =head2 set_wait(wait)
86 If called with a non-zero arg, generation of the page should wait until this
87 the progress is complete. Otherwise, the page will be generated completely before
88 the start function is called
89 =cut
90 sub set_wait
91 {
92 my ($self, $wait) = @_;
93 $self->{'wait'} = $wait;
94 }
95
96 sub get_wait
97 {
98 my ($self) = @_;
99 return $self->{'wait'};
100 }
101
102 =head2 set_page(Webmin::Page)
103 Called when this dynamic text box is added to a page
104 =cut
105 sub set_page
106 {
107 my ($self, $page) = @_;
108 $self->{'page'} = $page;
109 }
110
111 sub set_width
112 {
113 my ($self, $width) = @_;
114 $self->{'width'} = $width;
115 }
116
117 =head2 needs_unbuffered()
118 Must return 1 if the page needs to be in un-buffered and no-table mode
119 =cut
120 sub needs_unbuffered
121 {
122 return 0;
123 }
124
125
126
127
128 1;
129