diff --git a/lib/WebGUI/AssetHelper/Cut.pm b/lib/WebGUI/AssetHelper/Cut.pm new file mode 100644 index 000000000..7046e5b49 --- /dev/null +++ b/lib/WebGUI/AssetHelper/Cut.pm @@ -0,0 +1,69 @@ +package WebGUI::AssetHelper::Cut; + +use Class::C3; +use base qw/WebGUI::AssetHelper/; +use WebGUI::Asset; + +=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::Cut + +=head1 DESCRIPTION + +Cuts an Asset to the Clipboard. + +=head1 METHODS + +These methods are available from this class: + +=cut + +#------------------------------------------------------------------- + +=head2 process ( $class, $asset ) + +Cuts the asset to the clipboard. If the user cannot edit the asset, or the asset is a +system asset, it returns an error message. + +=cut + +sub process { + my ($class, $asset) = @_; + my $session = $asset->session; + + my $i18n = WebGUI::International->new($session, 'WebGUI'); + if (! $asset->canEdit) { + return { error => $i18n->get('38'), }; + } + elsif ( $asset->get('isSystem') ) { + return { error => $i18n->get('41'), }; + } + + my $success = $asset->cut(); + if (! $success) { + return { error => $i18n->get('41'), }; + } + + my $parent = $asset->getContainer; + if ($asset->getId eq $parent->getId) { + $parent = $asset->getParent; + } + return { + message => sprintf($i18n->get('cut asset', 'Asset'), $asset->getTitle), + redirect => $parent->getUrl, + }; +} + +1; diff --git a/lib/WebGUI/i18n/English/Asset.pm b/lib/WebGUI/i18n/English/Asset.pm index 1ddb45db8..a0a412ce9 100644 --- a/lib/WebGUI/i18n/English/Asset.pm +++ b/lib/WebGUI/i18n/English/Asset.pm @@ -1370,6 +1370,12 @@ Couldn't open %-s because %-s
context => q{}, }, + 'cut asset' => { + message => q{Asset %s was cut to the clipboard.}, + lastUpdated => 0, + context => q{%s will be replaced by the title of the asset.}, + }, + }; 1;