From 6081ea37658576127bc52eae8f66707cf4ca1574 Mon Sep 17 00:00:00 2001 From: Doug Bell Date: Wed, 4 Aug 2010 11:56:01 -0500 Subject: [PATCH] fix progressbar to work inside new admin console This is a horrible hack and needs to be fixed to shore up the ProgressBar's API before API freeze --- lib/WebGUI/ProgressBar.pm | 45 ++++++++++++++++++++++++++++----------- 1 file changed, 32 insertions(+), 13 deletions(-) diff --git a/lib/WebGUI/ProgressBar.pm b/lib/WebGUI/ProgressBar.pm index c15c00f78..39fa859c6 100644 --- a/lib/WebGUI/ProgressBar.pm +++ b/lib/WebGUI/ProgressBar.pm @@ -77,14 +77,26 @@ The URL to send the user to. sub finish { my $self = shift; my $url = shift; - my $text = sprintf(< -parent.location.href='%s'; +window.location.href='%s'; EOJS - local $| = 1; - $self->session->output->print($text . $self->{_foot}, 1); # skipMacros - return 'chunked'; + $self->session->output->print($text . $self->{_foot}, 1); # skipMacros + return 'chunked'; + } + else { + # We're in admin mode, close the dialog + my $text = sprintf(< +parent.admin.closeModalDialog(); + +EOJS + $self->session->output->print( $text, 1); # skipMacros + return 'chunked'; + } } #------------------------------------------------------------------- @@ -152,7 +164,7 @@ A message to be displayed in the status bar. my $prefix = ' '; @@ -162,15 +174,18 @@ sub update { my $message = shift; $message =~ s/'/\\'/g; ##Encode single quotes for JSON; $self->session->log->preventDebugOutput; - my $counter = $self->{_counter} += 1; - - my $text = $prefix . sprintf($format, $counter, $message) . $suffix; + + if ( $self->{_total} ) { + $self->{_counter} += 1; + } + + # Calculate percent progress. If we don't know our total yet, we haven't progressed any! + my $progress = $self->{_total} ? int( $self->{_counter} / $self->{_total} * 100 ) : 0; + + my $text = $prefix . sprintf($format, $progress, $message) . $suffix; local $| = 1; # Tell modperl not to buffer the output $self->session->output->print($text, 1); #skipMacros - if ($self->{_counter} > 600) { - $self->{_counter} = 1; - } return ''; } @@ -205,6 +220,10 @@ See start(). See start(). +=head3 admin + +If true, will send the correct JS to close the dialog box. + =head3 wrap A hashref of subroutine names to code references. While code is being called, @@ -259,7 +278,7 @@ sub run { die $e if $e; - return $self->finish($url || $self->session->url->page); + return $self->finish( $url || ( !$args->{admin} && $self->session->url->page ) ); } 1;