CGI-ProgressBar

 view release on metacpan or  search on metacpan

lib/CGI/ProgressBar.pm  view on Meta::CPAN

		<form name='$self->{progress_bar}->{layer_id}->{form}' action='noneEver'>
			<input name='$self->{progress_bar}->{layer_id}->{number}' type='text' size='6' value='0' class='pblib_number'
			/><span class='pblib_number'> / $self->{progress_bar}->{to}</span>
		</form>
		</td></tr></table>
		</td></tr></table>" if $self->{progress_bar}->{label};
	$html .= "</div>\n";
	$html .="<!-- end progress bar $self->{progress_bar}->{layer_id}->{container} -->\n\n" if $^W;
	$html .= "\n<script language='javascript' type='text/javascript'>\n// <!--";
	$html .= "\t progress bar produced by ".__PACKAGE__." at ".scalar(localtime)."\n" if $^W;
	$html .= "
	var pblib_at = $self->{progress_bar}->{from};
	pblib_progress_clear();
	function pblib_progress_clear() {
		for (var i = 1; i <= $self->{progress_bar}->{blocks}; i++)
			document.getElementById('$self->{progress_bar}->{layer_id}->{block}'+i).className='pblib_block_off';
		pblib_at = ".($self->{progress_bar}->{from}).";
	}
	function pblib_progress_update() {
		pblib_at += $self->{progress_bar}->{_interval};
		if (pblib_at > $self->{progress_bar}->{blocks}){
			pblib_progress_clear();
		} else {
			for (var i = 1; i <= Math.ceil(pblib_at); i++){
				document.getElementById('$self->{progress_bar}->{layer_id}->{block}'+i).className='pblib_block_on';
			}\n";
	$html .= "document.".$self->{progress_bar}->{layer_id}->{form}.".".$self->{progress_bar}->{layer_id}->{number}.".value++\n" if $self->{progress_bar}->{label};
	$html .= "}\n//-->\n</script>\n";

	return $html;
}

sub CGI::_init_css {
	my ($self, @crud) = CGI::self_or_default;
	$CSS = "
	.pblib_bar {
		border: 1px solid black;
		padding:    1px;
		background: white;
		display: block;
		text-align:left;
		width: ".($self->{progress_bar}->{width})."px;
	}
	.pblib_block_on,
	.pblib_block_off {
		display: block;
	".( $self->{progress_bar}->{orientation} eq 'vertical'?
		"float:none;
		 width: 100%;
		 height: ".($self->{progress_bar}->{block_wi})."px;"
	  : "float:left;
	     width: ".($self->{progress_bar}->{block_wi})."px;"
	)."
	}
	.pblib_block_off { border:1px solid white; background: white; }
	.pblib_block_on  { border:1px solid blue;  background: navy; }
	";
	if ($self->{progress_bar}->{label}){
		$CSS .=".pblib_number {
		text-align: right;
		border: 1px solid transparent;
		}";
	}
	$self->{progress_bar}->{css} = $CSS;
}

=head1 BUGS, CAVEATS, TODO

=over 4

=item One bar per page

This may change.

=item Parameter passing doesn't match F<CGI.pm>

But it will in the next release if you ask me for it.

=item C<colors> not implimented

I'd like to see here something like the C<Tk::ProgressBar::colors>;
not because I've ever used it, but because it might be cool.

=item Horizontal orientation only

You can get around this by adjusting the CSS, but you'd rather not.
And even if you did, the use of C<-label> might not look very nice
unless you did something quite fancy. So the next version (or so)
will support an C<-orientation> option.

=item Inline CSS and JS

Because it's easiest for me. I suppose some kind of over-loading of
the C<CGI::start_html> would be possible, but then I'd have to check
it, and maybe update it, every time F<CGI.pm> was updated, which I
don't fancy.

=cut

1;
__END__

=head1 CGI UPLOAD HOOK

I'm not convinced it works yet, even in F<CGI.pm> verion 3.15.

If anyone knows otherwise, please mail me: I have spent an hour
on the below, and it seems that the hook is called more times
than necessary....

=head2 PROCESS

The script has to both upload and process a file.

The hook script is called when the object is constructed,
thus before any headers can be output. There the hook needs
to output its own headers, and we only output headers for
the 'select file' page when the hook has not been called.

The first tiem the hook is called, then, it outputs HTTP
headers and begins the page. This is fine.



( run in 2.581 seconds using v1.01-cache-2.11-cpan-39bf76dae61 )