Copy Asset Helper (self only).
This commit is contained in:
parent
ed8f2c4a8f
commit
7298af49ea
3 changed files with 161 additions and 0 deletions
82
lib/WebGUI/AssetHelper/Copy.pm
Normal file
82
lib/WebGUI/AssetHelper/Copy.pm
Normal file
|
|
@ -0,0 +1,82 @@
|
||||||
|
package WebGUI::AssetHelper::Copy;
|
||||||
|
|
||||||
|
use strict;
|
||||||
|
use Class::C3;
|
||||||
|
use base qw/WebGUI::AssetHelper/;
|
||||||
|
|
||||||
|
=head1 LEGAL
|
||||||
|
|
||||||
|
-------------------------------------------------------------------
|
||||||
|
WebGUI is Copyright 2001-2009 Plain Black Corporation.
|
||||||
|
-------------------------------------------------------------------
|
||||||
|
Please read the legal notices (docs/legal.txt) and the license
|
||||||
|
(docs/license.txt) that came with this distribution before using
|
||||||
|
this software.
|
||||||
|
-------------------------------------------------------------------
|
||||||
|
http://www.plainblack.com info@plainblack.com
|
||||||
|
-------------------------------------------------------------------
|
||||||
|
|
||||||
|
=head1 NAME
|
||||||
|
|
||||||
|
Package WebGUI::AssetHelper::Copy
|
||||||
|
|
||||||
|
=head1 DESCRIPTION
|
||||||
|
|
||||||
|
Copy an Asset to the Clipboard, with no children.
|
||||||
|
|
||||||
|
=head1 METHODS
|
||||||
|
|
||||||
|
These methods are available from this class:
|
||||||
|
|
||||||
|
=cut
|
||||||
|
|
||||||
|
#-------------------------------------------------------------------
|
||||||
|
|
||||||
|
=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 process ( $class, $asset )
|
||||||
|
|
||||||
|
Copies the asset to the clipboard. There are no privilege or safety checks, since all operations
|
||||||
|
are done on the copy.
|
||||||
|
|
||||||
|
=cut
|
||||||
|
|
||||||
|
sub process {
|
||||||
|
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;
|
||||||
|
|
||||||
|
my $message = sprintf($i18n->get('copied asset'), $asset->getTitle);
|
||||||
|
|
||||||
|
my $payload = {
|
||||||
|
message => $message,
|
||||||
|
};
|
||||||
|
|
||||||
|
if (WebGUI::VersionTag->autoCommitWorkingIfEnabled($session, {
|
||||||
|
allowComments => 1,
|
||||||
|
returnUrl => $asset->getUrl,
|
||||||
|
}) eq 'redirect') {
|
||||||
|
return undef;
|
||||||
|
$payload->{open_tab} = $session->http->getRedirectLocation;
|
||||||
|
};
|
||||||
|
|
||||||
|
return $payload;
|
||||||
|
}
|
||||||
|
|
||||||
|
1;
|
||||||
|
|
@ -1376,6 +1376,12 @@ Couldn't open %-s because %-s <br />
|
||||||
context => q{%s will be replaced by the title of the asset.},
|
context => q{%s will be replaced by the title of the asset.},
|
||||||
},
|
},
|
||||||
|
|
||||||
|
'copied asset' => {
|
||||||
|
message => q{Asset %s was copied to the clipboard.},
|
||||||
|
lastUpdated => 0,
|
||||||
|
context => q{%s will be replaced by the title of the asset.},
|
||||||
|
},
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
1;
|
1;
|
||||||
|
|
|
||||||
73
t/AssetHelper/Copy.t
Normal file
73
t/AssetHelper/Copy.t
Normal file
|
|
@ -0,0 +1,73 @@
|
||||||
|
# vim:syntax=perl
|
||||||
|
#-------------------------------------------------------------------
|
||||||
|
# WebGUI is Copyright 2001-2009 Plain Black Corporation.
|
||||||
|
#-------------------------------------------------------------------
|
||||||
|
# Please read the legal notices (docs/legal.txt) and the license
|
||||||
|
# (docs/license.txt) that came with this distribution before using
|
||||||
|
# this software.
|
||||||
|
#------------------------------------------------------------------
|
||||||
|
# http://www.plainblack.com info@plainblack.com
|
||||||
|
#------------------------------------------------------------------
|
||||||
|
|
||||||
|
# Write a little about what this script tests.
|
||||||
|
#
|
||||||
|
#
|
||||||
|
|
||||||
|
use FindBin;
|
||||||
|
use strict;
|
||||||
|
use lib "$FindBin::Bin/../lib";
|
||||||
|
use Test::More;
|
||||||
|
use Test::Deep;
|
||||||
|
use WebGUI::Test; # Must use this before any other WebGUI modules
|
||||||
|
use WebGUI::Session;
|
||||||
|
use WebGUI::Asset;
|
||||||
|
use WebGUI::AssetHelper::Copy;
|
||||||
|
|
||||||
|
#----------------------------------------------------------------------------
|
||||||
|
# Init
|
||||||
|
my $session = WebGUI::Test->session;
|
||||||
|
|
||||||
|
|
||||||
|
#----------------------------------------------------------------------------
|
||||||
|
# Tests
|
||||||
|
|
||||||
|
plan tests => 3; # Increment this number for each test you create
|
||||||
|
|
||||||
|
#----------------------------------------------------------------------------
|
||||||
|
# put your tests here
|
||||||
|
|
||||||
|
my $output;
|
||||||
|
my $home = WebGUI::Asset->getDefault($session);
|
||||||
|
|
||||||
|
$output = WebGUI::AssetHelper::Copy->process($home);
|
||||||
|
cmp_deeply(
|
||||||
|
$output,
|
||||||
|
{
|
||||||
|
message => re('was copied to the clipboard'),
|
||||||
|
},
|
||||||
|
'AssetHelper/Copy redirects the back to the copied asset'
|
||||||
|
);
|
||||||
|
|
||||||
|
my $clippies = $home->getAssetsInClipboard();
|
||||||
|
is @{ $clippies }, 1, '... only copied 1 asset to the clipboard, no children';
|
||||||
|
|
||||||
|
foreach my $asset (@{ $clippies }) {
|
||||||
|
$asset->purge;
|
||||||
|
}
|
||||||
|
|
||||||
|
$session->setting->set('skipCommitComments', 0);
|
||||||
|
|
||||||
|
$output = WebGUI::AssetHelper::Copy->process($home);
|
||||||
|
cmp_deeply(
|
||||||
|
$output,
|
||||||
|
{
|
||||||
|
message => re('was copied to the clipboard'),
|
||||||
|
open_tab => $home->getUrl,
|
||||||
|
},
|
||||||
|
'AssetHelper/Copy opens a tab for commit comments'
|
||||||
|
);
|
||||||
|
|
||||||
|
foreach my $asset (@{ $clippies }) {
|
||||||
|
$asset->purge;
|
||||||
|
}
|
||||||
|
#vim:ft=perl
|
||||||
Loading…
Add table
Add a link
Reference in a new issue