<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">package Webmin::DynamicWait;
use WebminCore;

=head2 new Webmin::DynamicWait(&amp;start-function, [&amp;args])
A page element indicating that something is happening.
=cut
sub new
{
my ($self, $func, $args) = @_;
$self = { 'func' =&gt; $func,
	  'args' =&gt; $args,
	  'name' =&gt; "dynamic".++$dynamic_count,
	  'width' =&gt; 80,
	  'delay' =&gt; 20 };
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-&gt;{'message'} = $message;
}

sub get_message
{
my ($self) = @_;
return $self-&gt;{'message'};
}

=head2 html()
Returns the HTML for the text field used to indicate progress
=cut
sub html
{
my ($self) = @_;
my $rv;
if ($self-&gt;get_message()) {
	$rv .= $self-&gt;get_message()."&lt;p&gt;\n";
	}
$rv .= "&lt;form name=form_$self-&gt;{'name'}&gt;";
$rv .= "&lt;input name=$self-&gt;{'name'} size=$self-&gt;{'width'} disabled=true style='font-family: courier'&gt;";
$rv .= "&lt;/form&gt;";
return $rv;
}

=head2 start()
Called by the page to begin the progress. Also starts a process to update the
Javascript text box
=cut
sub start
{
my ($self) = @_;
$self-&gt;{'pid'} = fork();
if (!$self-&gt;{'pid'}) {
	my $pos = 0;
	while(1) {
		select(undef, undef, undef, $self-&gt;{'delay'}/1000.0);
		my $str = (" " x $pos) . ("x" x 10);
		print "&lt;script&gt;window.document.forms[\"form_$self-&gt;{'name'}\"].$self-&gt;{'name'}.value = \"$str\";&lt;/script&gt;\n";
		$pos++;
		$pos = 0 if ($pos == $self-&gt;{'width'});
		}
	exit;
	}
&amp;{$self-&gt;{'func'}}($self, @{$self-&gt;{'args'}});
}

=head2 stop()
Called back by the function when whatever we were waiting for is done
=cut
sub stop
{
my ($self) = @_;
if ($self-&gt;{'pid'}) {
	kill('TERM', $self-&gt;{'pid'});
	}
my $str = (" " x ($self-&gt;{'width'}/2 - 2)) . "DONE";
print "&lt;script&gt;window.document.forms[\"form_$self-&gt;{'name'}\"].$self-&gt;{'name'}.value = \"$str\";&lt;/script&gt;\n";
}

=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-&gt;{'wait'} = $wait;
}

sub get_wait
{
my ($self) = @_;
return $self-&gt;{'wait'};
}

=head2 set_page(Webmin::Page)
Called when this dynamic text box is added to a page
=cut
sub set_page
{
my ($self, $page) = @_;
$self-&gt;{'page'} = $page;
}

sub set_width
{
my ($self, $width) = @_;
$self-&gt;{'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;

</pre></body></html>