From 8bd28e101ff10a0d38d9540298b3a4c1c824a880 Mon Sep 17 00:00:00 2001 From: Doug Bell Date: Wed, 4 Aug 2010 12:07:55 -0500 Subject: [PATCH] update Copy to work with ProgressBar and streaming ProgressBar needs to handle streaming itself. When it does, all AssetHelpers that use ProgressBar will need to remove their own streaming handlers and just use ProgressBar's --- lib/WebGUI/AssetHelper/Copy.pm | 99 ++++++++++++++++++---------------- 1 file changed, 54 insertions(+), 45 deletions(-) diff --git a/lib/WebGUI/AssetHelper/Copy.pm b/lib/WebGUI/AssetHelper/Copy.pm index 5ff8be80c..ceb26dba8 100644 --- a/lib/WebGUI/AssetHelper/Copy.pm +++ b/lib/WebGUI/AssetHelper/Copy.pm @@ -32,62 +32,71 @@ These methods are available from this class: #------------------------------------------------------------------- -=head2 duplicate ( $class, $asset ) - -Duplicates the asset. Extracted out so that it can be subclassed by copy with children, -and copy with descendants. - -=cut - -sub duplicate { - my ($class, $asset) = @_; - return $asset->duplicate; -} - -#------------------------------------------------------------------- - -=head2 getMessage ( ) - -Returns the name of the i18n message to use - -=cut - -sub getMessage { - return 'copied asset'; -} - -#------------------------------------------------------------------- - =head2 process ( $class, $asset ) -Copies the asset to the clipboard. There are no privilege or safety checks, since all operations -are done on the copy. +Open a progress dialog for the copy operation =cut sub process { my ($class, $asset) = @_; + + return { + openDialog => '?op=assetHelper;className=' . $class . ';method=copy;assetId=' . $asset->getId, + }; +} + +#---------------------------------------------------------------------------- + +=head2 www_copy ( $class, $asset ) + +Perform the copy operation, showing the progress. + +=cut + +sub www_copy { + my ( $class, $asset ) = @_; my $session = $asset->session; my $i18n = WebGUI::International->new($session, 'Asset'); - my $newAsset = $class->duplicate($asset); - $newAsset->update({ title=>sprintf("%s (%s)",$asset->getTitle,$i18n->get('copy'))}); - $newAsset->cut; + return $session->response->stream( sub { + my ( $session ) = @_; + my $pb = WebGUI::ProgressBar->new($session); + my @stack; - my $message = sprintf($i18n->get($class->getMessage()), $asset->getTitle); - - my $payload = { - message => $message, - }; - - if (WebGUI::VersionTag->autoCommitWorkingIfEnabled($session, { - allowComments => 1, - returnUrl => $asset->getUrl, - }) eq 'redirect') { - $payload->{openDialog} = $session->http->getRedirectLocation; - }; - - return $payload; + return $pb->run( + admin => 1, + total => 2, + title => $i18n->get('Copy Assets'), + icon => $session->url->extras('adminConsole/assets.gif'), + code => sub { + my $bar = shift; + my $newAsset = $asset->duplicate; + $bar->update($i18n->get('cut')); + my $title = sprintf("%s (%s)", $asset->getTitle, $i18n->get('copy')); + $newAsset->update({ title => $title }); + $newAsset->cut; + my $result = WebGUI::VersionTag->autoCommitWorkingIfEnabled( + $session, { + allowComments => 1, + returnUrl => $asset->getUrl, + } + ); + if ( $result eq 'redirect' ) { + return $asset->getUrl; + } + return; + }, + wrap => { + 'WebGUI::Asset::duplicate' => sub { + my ($bar, $original, $asset, @args) = @_; + my $name = join '/', @stack, $asset->getTitle; + $bar->update($name); + return $asset->$original(@args); + }, + } + ); + } ); } 1;