1 # XXX should support non-Javascript mode?
2 package Webmin::DynamicText;
5 =head2 new Webmin::DynamicText(&start-function, &args)
6 A page element for displaying text that takes time to generate, such as from
7 a long-running script. Uses a non-editable text box, updated via Javascript.
8 The function will be called when it is time to start producing output, with this
9 object as a parameter. It must call the add_line function on the object for each
14 my ($self, $func, $args) = @_;
15 $self = { 'func' => $func,
17 'name' => "dynamic".++$dynamic_count,
24 =head2 set_message(text)
25 Sets the text describing what we are waiting for
29 my ($self, $message) = @_;
30 $self->{'message'} = $message;
36 return $self->{'message'};
40 Returns the HTML for the text box
46 if ($self->get_message()) {
47 $rv .= $self->get_message()."<p>\n";
49 $rv .= "<form name=form_$self->{'name'}>";
50 $rv .= "<textarea name=$self->{'name'} rows=$self->{'rows'} cols=$self->{'cols'} wrap=off disabled=true>";
51 $rv .= "</textarea>\n";
57 Called by the page to begin the dynamic output.
62 &{$self->{'func'}}($self, @$args);
66 Called by the function to add a line of text to this output
70 my ($self, $line) = @_;
72 $line = "e_escape($line);
73 print "<script>window.document.forms[\"form_$self->{'name'}\"].$self->{'name'}.value += \"$line\"+\"\\n\";</script>\n";
77 If called with a non-zero arg, generation of the page should wait until this
78 text box is complete. Otherwise, the page will be generated completely before the
79 start function is called
83 my ($self, $wait) = @_;
84 $self->{'wait'} = $wait;
90 return $self->{'wait'};
93 =head2 set_page(Webmin::Page)
94 Called when this dynamic text box is added to a page
98 my ($self, $page) = @_;
99 $self->{'page'} = $page;
104 my ($self, $rows) = @_;
105 $self->{'rows'} = $rows;
110 my ($self, $cols) = @_;
111 $self->{'cols'} = $cols;
114 =head2 needs_unbuffered()
115 Must return 1 if the page needs to be in un-buffered and no-table mode