spew forth more data!

This commit is contained in:
JT Smith 2009-06-18 22:36:42 +00:00
parent 08bd0855b5
commit 0a004d72a0
3 changed files with 72 additions and 110 deletions

View file

@ -169,7 +169,7 @@ sub getAssetsInClipboard {
#-------------------------------------------------------------------
=head2 paste ( assetId )
=head2 paste ( assetId , [ outputSub ] )
Returns 1 if can paste an asset to a Parent. Sets the Asset to published. Otherwise returns 0.
@ -177,17 +177,23 @@ Returns 1 if can paste an asset to a Parent. Sets the Asset to published. Otherw
Alphanumeric ID tag of Asset.
=head3 outputSub
A reference to a subroutine that output messages should be sent to.
=cut
sub paste {
my $self = shift;
my $assetId = shift;
my $outputSub = shift;
my $pastedAsset = WebGUI::Asset->newByDynamicClass($self->session,$assetId);
return 0 unless ($self->get("state") eq "published");
return 0 unless ($pastedAsset->canPaste()); ##Allow pasted assets to have a say about pasting.
# Don't allow a shortcut to create an endless loop
return 0 if ($pastedAsset->get("className") eq "WebGUI::Asset::Shortcut" && $pastedAsset->get("shortcutToAssetId") eq $self->getId);
$outputSub->("pasting ".$pastedAsset->getTitle) if defined $outputSub;
if ($self->getId eq $pastedAsset->get("parentId") || $pastedAsset->setParent($self)) {
$pastedAsset->publish(['clipboard','clipboard-limbo']); # Paste only clipboard items
$pastedAsset->updateHistory("pasted to parent ".$self->getId);
@ -196,6 +202,7 @@ sub paste {
my $updateAssets = $pastedAsset->getLineage(['self', 'descendants'], {returnObjects => 1});
foreach (@{$updateAssets}) {
$outputSub->("indexing ".$_->getTitle) if defined $outputSub;
$_->indexContent();
}
@ -508,50 +515,16 @@ sub www_pasteList {
my $pb = WebGUI::ProgressBar->new($session);
##Need to store the list of assetIds for the status subroutine
my @assetIds = $form->param('assetId');
$session->scratch->set('assetPasteList', JSON::to_json(\@assetIds));
if ($form->param('proceed') eq 'manageAssets') {
$session->scratch->set('assetPasteReturnUrl', $self->getUrl('op=assetManager'));
}
else {
$session->scratch->set('assetPasteReturnUrl', $self->getUrl);
}
##Need to set the URL that should be displayed when it is done
my $i18n = WebGUI::International->new($session, 'Asset');
$pb->setIcon($session->url->extras('adminConsole/assets.gif'));
return $pb->render({
title => $i18n->get('Paste Assets'),
statusUrl => $self->getUrl('func=pasteListStatus'),
});
}
#-------------------------------------------------------------------
=head2 www_pasteListStatus ( )
Pastes a selection of assets. If canEdit is False, returns an insufficient privileges page.
Returns the user to the manageAssets screen.
=cut
sub www_pasteListStatus {
my $self = shift;
my $session = $self->session;
my $pb = WebGUI::ProgressBar->new($session);
if (! $self->canEdit ) {
return $session->privilege->insufficient('no style')."return to site";
}
my $assetIds = $session->scratch->get('assetPasteList') || '[]';
$session->scratch->delete('assetPasteList');
my @assetIds = @{ JSON::from_json($assetIds) };
my $i18n = WebGUI::International->new($session, 'Asset');
$pb->start($i18n->get('Paste Assets'), $session->url->extras('adminConsole/assets.gif'));
ASSET: foreach my $clipId (@assetIds) {
my $pasteAsset = WebGUI::Asset->newPending($session, $clipId);
next ASSET unless $pasteAsset && $pasteAsset->canEdit;
$pb->print(sprintf $i18n->get("Pasting %s"), $pasteAsset->getTitle);
$self->paste($clipId);
#$pb->update(sprintf $i18n->get("Pasting %s"), $pasteAsset->getTitle);
$self->paste($clipId, sub {$pb->update(@_);});
}
$pb->redirect( $session->scratch->get('assetPasteReturnUrl') );
return "redirect";
return $pb->finish( ($form->param('proceed') eq 'manageAssets') ? $self->getUrl('op=assetManager') : $self->getUrl );
}

View file

@ -28,6 +28,11 @@ Render a progress bar for the user inside a nice style.
use WebGUI::ProgressBar;
my $pb = WebGUI::ProgressBar->new($session);
$pb->start($title, $iconUrl);
$pb->update($message);
$pb->finish($redirectUrl);
=head1 METHODS
These methods are available from this class:
@ -49,6 +54,7 @@ A reference to the current session.
sub new {
my $class = shift;
my $session = shift;
my $recordCount = shift;
my $self = {};
$self->{_session} = $session;
$self->{_counter} = 1;
@ -58,34 +64,7 @@ sub new {
#-------------------------------------------------------------------
=head2 print ( $message )
Sends a message and increments the status bar.
=head3 $message
A message to be displayed in the status bar.
=cut
sub print {
my $self = shift;
my $message = shift; ##JS string escaping?
$self->session->log->preventDebugOutput;
$self->{_counter} += 1;
my $text = sprintf(<<EOJS, $self->{_counter}, $message);
<script>
parent.document.getElementById("progressMeter").style.width='%dpx';
parent.document.getElementById("progressStatus").innerHTML='%s';
</script>
EOJS
$self->session->output->print($text);
return '';
}
#-------------------------------------------------------------------
=head2 redirect ( $url )
=head2 finish ( $url )
Redirects the user out of the status page.
@ -95,7 +74,7 @@ The URL to send the user to.
=cut
sub redirect {
sub finish {
my $self = shift;
my $url = shift;
my $text = sprintf(<<EOJS, $url);
@ -103,39 +82,8 @@ sub redirect {
parent.location.href='%s';
</script>
EOJS
$self->session->output->print($text);
return '';
}
#-------------------------------------------------------------------
=head2 render ( $options )
Returns a templated progress bar implemented in CSS and JS.
=head3 options
A hashref of options to configure the progress bar
=head3 title
A title to display above the progress bar.
=head3 statusUrl
The URL that the progress bar should use to get status information.
=cut
sub render {
my $self = shift;
my $options = shift;
$self->session->http->setCacheControl("none");
my %var = %{ $options };
$var{"icon"} = $self->{_icon};
my $template = WebGUI::Asset::Template->new($self->session, 'YP9WaMPJHvCJl-YwrLVcPw');
my $output = $template->process(\%var);
return $self->session->style->process($output,"PBtmpl0000000000000137");
$self->session->output->print($text . $self->{_foot});
return 'redirect';
}
#-------------------------------------------------------------------
@ -153,24 +101,65 @@ sub session {
#-------------------------------------------------------------------
=head2 setIcon ( icon )
=head2 start ( title, icon )
Sets the _function icon to parameter.
Returns a templated progress bar implemented in CSS and JS.
=head3 title
A title to display above the progress bar.
=head3 icon
A string representing the location of the icon.
The url to the icon you want to display.
=cut
sub setIcon {
my $self = shift;
my $icon = shift;
if ($icon) {
$self->{_icon} = $icon;
}
sub start {
my ($self, $title, $icon) = @_;
$self->session->http->setCacheControl("none");
my %var = (
title => $title,
icon => $icon
);
my $template = WebGUI::Asset::Template->new($self->session, 'YP9WaMPJHvCJl-YwrLVcPw');
my $output = $self->session->style->process($template->process(\%var).'~~~', "PBtmpl0000000000000137");
my ($head, $foot) = split '~~~', $output;
$self->session->http->sendHeader;
$self->session->output->print($head);
$self->{_foot} = $foot;
return '';
}
#-------------------------------------------------------------------
=head2 update ( $message )
Sends a message and increments the status bar.
=head3 $message
A message to be displayed in the status bar.
=cut
sub update {
my $self = shift;
my $message = shift; ##JS string escaping?
$self->session->log->preventDebugOutput;
$self->{_counter} += 1;
my $text = sprintf(<<EOJS, $self->{_counter}, $message);
<script>
document.getElementById("progressMeter").style.width='%dpx';
document.getElementById("progressStatus").innerHTML='%s';
</script>
EOJS
$self->session->output->print($text);
if ($self->{_counter} > 600) {
$self->{_counter} = 1;
}
return '';
}
1;