Tree view buttons now work. Changed progress bar helpers to use fork. Added forkId option to AssetHelpers. Added updateAsset service to Admin.
This commit is contained in:
parent
399aa5368b
commit
b27bc19e4d
14 changed files with 757 additions and 277 deletions
|
|
@ -3,6 +3,7 @@ package WebGUI::AssetHelper::Copy;
|
|||
use strict;
|
||||
use Class::C3;
|
||||
use base qw/WebGUI::AssetHelper/;
|
||||
use Scalar::Util qw( blessed );
|
||||
|
||||
=head1 LEGAL
|
||||
|
||||
|
|
@ -34,69 +35,54 @@ These methods are available from this class:
|
|||
|
||||
=head2 process ( $asset )
|
||||
|
||||
Open a progress dialog for the copy operation
|
||||
Fork the copy operation
|
||||
|
||||
=cut
|
||||
|
||||
sub process {
|
||||
my ($self, $asset) = @_;
|
||||
my $session = $self->session;
|
||||
|
||||
# Should we autocommit?
|
||||
my $commit = $session->setting->get('versionTagMode') eq 'autoCommit';
|
||||
|
||||
# Fork the copy. Forking makes sure it won't get interrupted
|
||||
my $fork = WebGUI::Fork->start(
|
||||
$session, blessed( $self ), 'copy', { assetId => $asset->getId, commit => $commit },
|
||||
);
|
||||
|
||||
return {
|
||||
openDialog => '?op=assetHelper;helperId=' . $self->id . ';method=copy;assetId=' . $asset->getId,
|
||||
forkId => $fork->getId,
|
||||
};
|
||||
}
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 www_copy ( $asset )
|
||||
=head2 copy ( $process, $args )
|
||||
|
||||
Perform the copy operation, showing the progress.
|
||||
Perform the copy stuff in a forked process
|
||||
|
||||
=cut
|
||||
|
||||
sub www_copy {
|
||||
my ( $self, $asset ) = @_;
|
||||
my $session = $asset->session;
|
||||
my $i18n = WebGUI::International->new($session, 'Asset');
|
||||
sub copy {
|
||||
my ($process, $args) = @_;
|
||||
my $session = $process->session;
|
||||
my $asset = WebGUI::Asset->newById($session, $args->{assetId});
|
||||
my $tree = WebGUI::ProgressTree->new($session, [ $asset->getId ] );
|
||||
$process->update(sub { $tree->json });
|
||||
my $newAsset = $asset->duplicate({ state => "clipboard" });
|
||||
|
||||
return $session->response->stream( sub {
|
||||
my ( $session ) = @_;
|
||||
my $pb = WebGUI::ProgressBar->new($session);
|
||||
my @stack;
|
||||
# If we aren't committing, add to a tag
|
||||
if ( !$args->{commit} ) {
|
||||
$newAsset->update({
|
||||
status => "pending",
|
||||
tagId => WebGUI::VersionTag->getWorking( $session )->getId,
|
||||
});
|
||||
}
|
||||
$newAsset->update({ title => $newAsset->getTitle . ' (copy)'});
|
||||
|
||||
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 { message => 'Your asset is now copied!' };
|
||||
},
|
||||
wrap => {
|
||||
'WebGUI::Asset::duplicate' => sub {
|
||||
my ($bar, $original, $asset, @args) = @_;
|
||||
my $name = join '/', @stack, $asset->getTitle;
|
||||
$bar->update($name);
|
||||
return $asset->$original(@args);
|
||||
},
|
||||
}
|
||||
);
|
||||
} );
|
||||
$tree->success($asset->getId);
|
||||
$process->update(sub { $tree->json });
|
||||
}
|
||||
|
||||
1;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue