1 package Webmin::DynamicWait;
4 =head2 new Webmin::DynamicWait(&start-function, [&args])
5 A page element indicating that something is happening.
9 my ($self, $func, $args) = @_;
10 $self = { 'func' => $func,
12 'name' => "dynamic".++$dynamic_count,
19 =head2 set_message(text)
20 Sets the text describing what we are waiting for
24 my ($self, $message) = @_;
25 $self->{'message'} = $message;
31 return $self->{'message'};
35 Returns the HTML for the text field used to indicate progress
41 if ($self->get_message()) {
42 $rv .= $self->get_message()."<p>\n";
44 $rv .= "<form name=form_$self->{'name'}>";
45 $rv .= "<input name=$self->{'name'} size=$self->{'width'} disabled=true style='font-family: courier'>";
51 Called by the page to begin the progress. Also starts a process to update the
57 $self->{'pid'} = fork();
58 if (!$self->{'pid'}) {
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";
65 $pos = 0 if ($pos == $self->{'width'});
69 &{$self->{'func'}}($self, @{$self->{'args'}});
73 Called back by the function when whatever we were waiting for is done
79 kill('TERM', $self->{'pid'});
81 my $str = (" " x ($self->{'width'}/2 - 2)) . "DONE";
82 print "<script>window.document.forms[\"form_$self->{'name'}\"].$self->{'name'}.value = \"$str\";</script>\n";
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
92 my ($self, $wait) = @_;
93 $self->{'wait'} = $wait;
99 return $self->{'wait'};
102 =head2 set_page(Webmin::Page)
103 Called when this dynamic text box is added to a page
107 my ($self, $page) = @_;
108 $self->{'page'} = $page;
113 my ($self, $width) = @_;
114 $self->{'width'} = $width;
117 =head2 needs_unbuffered()
118 Must return 1 if the page needs to be in un-buffered and no-table mode