copy asset pop-up menu

This commit is contained in:
James Tolley 2007-07-11 00:07:17 +00:00
parent de4da68884
commit f33e7533f4
5 changed files with 79 additions and 21 deletions

View file

@ -1102,7 +1102,24 @@ sub getToolbar {
$toolbar .= $self->session->icon->locked('func=manageRevisions',$self->get("url")) if ($userUiLevel >= $uiLevels->{"revisions"});
}
$toolbar .= $self->session->icon->cut('func=cut',$self->get("url")) if ($userUiLevel >= $uiLevels->{"cut"});
$toolbar .= $self->session->icon->copy('func=copy',$self->get("url")) if ($userUiLevel >= $uiLevels->{"copy"});
# if this asset has children, create a more full-featured menu for copying
if ($self->getChildCount) {
my $copy = '<script type="text/javascript">
//<![CDATA[
var contextMenu = new contextMenu_createWithImage("'.$self->session->icon->getBaseURL().'copy.gif","'.$self->getId.'_2","'.$i18n->get('copy').'",true);';
$copy .= 'contextMenu.addLink("'.$self->getUrl("func=copy").'","'.$i18n->get("this asset only").'");';
$copy .= 'contextMenu.addLink("'.$self->getUrl("func=copy;with=children").'","'.$i18n->get("with children").'");';
$copy .= 'contextMenu.addLink("'.$self->getUrl("func=copy;with=descendants").'","'.$i18n->get("with descendants").'");';
$copy .= 'contextMenu.print();
//]]>
</script>';
$toolbar .= $copy;
}
else {
$toolbar .= $self->session->icon->copy('func=copy',$self->get("url")) if ($userUiLevel >= $uiLevels->{"copy"});
}
$toolbar .= $self->session->icon->shortcut('func=createShortcut',$self->get("url")) if ($userUiLevel >= $uiLevels->{"shortcut"} && !($self->get("className") =~ /Shortcut/));
$self->session->style->setLink($self->session->url->extras('contextMenu/contextMenu.css'), {rel=>"stylesheet",type=>"text/css"});
$self->session->style->setScript($self->session->url->extras('contextMenu/contextMenu.js'), {type=>"text/javascript"});

View file

@ -45,22 +45,24 @@ Duplicates this asset and the entire subtree below it. Returns the root of the
=cut
sub duplicateBranch {
my $self = shift;
my $newAsset = $self->duplicate({skipAutoCommitWorkflows=>1});
my $contentPositions = $self->get("contentPositions");
my $assetsToHide = $self->get("assetsToHide");
my $self = shift;
my $childrenOnly = shift || 0;
foreach my $child (@{$self->getLineage(["children"],{returnObjects=>1})}) {
my $newChild = $child->duplicateBranch;
$newChild->setParent($newAsset);
my ($oldChildId, $newChildId) = ($child->getId, $newChild->getId);
$contentPositions =~ s/\Q${oldChildId}\E/${newChildId}/g if ($contentPositions);
$assetsToHide =~ s/\Q${oldChildId}\E/${newChildId}/g if ($assetsToHide);
}
my $newAsset = $self->duplicate({skipAutoCommitWorkflows=>1});
my $contentPositions = $self->get("contentPositions");
my $assetsToHide = $self->get("assetsToHide");
$newAsset->update({contentPositions=>$contentPositions}) if $contentPositions;
$newAsset->update({assetsToHide=>$assetsToHide}) if $assetsToHide;
return $newAsset;
foreach my $child (@{$self->getLineage(["children"],{returnObjects=>1})}) {
my $newChild = $childrenOnly ? $child->duplicate({skipAutoCommitWorkflows=>1}) : $child->duplicateBranch;
$newChild->setParent($newAsset);
my ($oldChildId, $newChildId) = ($child->getId, $newChild->getId);
$contentPositions =~ s/\Q${oldChildId}\E/${newChildId}/g if ($contentPositions);
$assetsToHide =~ s/\Q${oldChildId}\E/${newChildId}/g if ($assetsToHide);
}
$newAsset->update({contentPositions=>$contentPositions}) if $contentPositions;
$newAsset->update({assetsToHide=>$assetsToHide}) if $assetsToHide;
return $newAsset;
}

View file

@ -185,10 +185,23 @@ Duplicates self, cuts duplicate, returns self->getContainer->www_view if canEdit
sub www_copy {
my $self = shift;
return $self->session->privilege->insufficient() unless $self->canEdit;
my $newAsset = $self->duplicate({skipAutoCommitWorkflows => 1});
$newAsset->update({ title=>$self->getTitle.' (copy)'});
$newAsset->cut;
return $self->session->asset($self->getContainer)->www_view;
# with: 'children' || 'descendants' || ''
my $with = $self->session->form->get('with') || '';
if ($with) {
my $childrenOnly = $with eq 'children';
my $newAsset = $self->duplicateBranch($childrenOnly);
$newAsset->update({ title=>$self->getTitle.' (copy)'});
$newAsset->cut;
return $self->session->asset($self->getContainer)->www_view;
}
else {
my $newAsset = $self->duplicate({skipAutoCommitWorkflows => 1});
$newAsset->update({ title=>$self->getTitle.' (copy)'});
$newAsset->cut;
return $self->session->asset($self->getContainer)->www_view;
}
}
#-------------------------------------------------------------------

View file

@ -241,6 +241,24 @@ our $I18N = {
context => q|Used in asset context menus.|
},
'this asset only' => {
message => q|This&nbsp;Asset&nbsp;Only|,
lastUpdated => 0,
context => q|Used in the small pop-up copy menu.|
},
'with children' => {
message => q|With&nbsp;Children|,
lastUpdated => 0,
context => q|Used in the small pop-up copy menu.|
},
'with descendants' => {
message => q|With&nbsp;Descendants|,
lastUpdated => 0,
context => q|Used in the small pop-up copy menu.|
},
'create shortcut' => {
message => q|Create Shortcut|,
lastUpdated => 0,

View file

@ -47,10 +47,11 @@ function contextMenu_hide(){
return false;
}
function contextMenu_createWithImage(imagePath, id, name){
function contextMenu_createWithImage(imagePath, id, name, addContext){
contextMenu_items.push(id);
this.id = id;
this.name = name;
this.addContext = addContext;
this.type = "image";
this.imagePath=imagePath;
this.linkLabels = new Array();
@ -80,7 +81,14 @@ function contextMenu_draw(){
}
output += '</div>';
if (this.type == "image") {
output += '<img src="' + this.imagePath + '" id="contextMenu_' + this.id + '" onclick="return contextMenu_renderLeftClick(\'contextMenu_' + this.id + '_menu\',event)" alt="' + this.name + '" title="' + this.name + '" align="absmiddle" />';
if (this.addContext)
output += '<p style="display: inline; vertical-align: middle;"><a href="javascript:void(0)">';
output += '<img src="' + this.imagePath + '" id="contextMenu_' + this.id + '_2" onclick="return contextMenu_renderLeftClick(\'contextMenu_' + this.id + '_menu\',event)" alt="' + this.name + '" title="' + this.name + '" align="absmiddle" ';
if (this.addContext)
output += 'style="border: 0px none; vertical-align: middle;"';
output += ' />';
if (this.addContext)
output += '</a></p>';
} else {
output += '<a href="#" id="contextMenu_' + this.id + '" onclick="return contextMenu_renderLeftClick(\'contextMenu_' + this.id + '_menu\',event)">' + this.name + '</a>';
}