Complete asset manager rewrite.

This commit is contained in:
Doug Bell 2008-05-26 22:07:16 +00:00
parent dc30ecccbe
commit f3996eb316
14 changed files with 1189 additions and 331 deletions

View file

@ -1256,7 +1256,7 @@ sub getToolbar {
$output .= 'contextMenu.addLink("'.$self->getUrl("func=demote").'","'.$i18n->get("demote").'");';
}
if ($userUiLevel >= $uiLevels->{"manage"}) {
$output .= 'contextMenu.addLink("'.$self->getUrl("func=manageAssets").'","'.$i18n->get("manage").'");';
$output .= 'contextMenu.addLink("'.$self->getUrl("op=manageAssets").'","'.$i18n->get("manage").'");';
}
$output .= 'contextMenu.print();
//]]>
@ -1409,302 +1409,6 @@ sub logView {
return undef;
}
#-------------------------------------------------------------------
=head2 manageAssets ( )
Main page to manage assets. Renders an AdminConsole with a list of assets. If canEdit returns False, renders an insufficient privilege page. Is called by www_manageAssets
=cut
sub manageAssets {
my $self = shift;
my $i18n = WebGUI::International->new($self->session, "Asset");
my $userUILevel = $self->session->user->profileField("uiLevel");
my $uiLevels = $self->session->config->get("assetToolbarUiLevel");
my $ancestors = $self->getLineage(["self","ancestors"],{returnObjects=>1});
my @crumbtrail;
foreach my $ancestor (@{$ancestors}) {
if ($ancestor->getId eq $self->getId) {
my $title = $self->getTitle;
$title =~ s/\'/\\\'/g;
my $more = '<script type="text/javascript">
var ct_contextMenu = new contextMenu_createWithLink("ct_'.$self->getId.'","'.$title.'");';
$more .= 'ct_contextMenu.addLink("'.$self->getUrl("func=changeUrl;proceed=manageAssets").'","'.$i18n->get("change url").'");'
if $userUILevel >= $uiLevels->{"changeUrl"};
$more .= 'ct_contextMenu.addLink("'.$self->getUrl("func=editBranch").'","'.$i18n->get("edit branch").'");'
if $userUILevel >= $uiLevels->{"editBranch"};
$more .= 'ct_contextMenu.addLink("'.$self->getUrl("func=createShortcut;proceed=manageAssets").'","'.$i18n->get("create shortcut").'");'
if $userUILevel >= $uiLevels->{"shortcut"};
$more .= 'ct_contextMenu.addLink("'.$self->getUrl("func=manageRevisions").'","'.$i18n->get("revisions").'");'
if $userUILevel >= $uiLevels->{"revisions"};
$more .= 'ct_contextMenu.addLink("'.$self->getUrl.'","'.$i18n->get("view").'"); '."\n"
if $userUILevel >= $uiLevels->{"view"};
$more .= 'ct_contextMenu.addLink("'.$self->getUrl("func=edit;proceed=manageAssets").'","'.$i18n->get("edit").'");'
if $userUILevel >= $uiLevels->{"edit"} && !$self->isLocked;
$more .= 'ct_contextMenu.addLink("'.$self->getUrl("func=lock;proceed=manageAssets").'","'.$i18n->get("lock").'");'
if $userUILevel >= $uiLevels->{"lock"} && !$self->isLocked;
if (defined $self->session->config->get("exportPath") && $userUILevel >= $uiLevels->{"export"}) {
$more .= 'ct_contextMenu.addLink("'.$self->getUrl("func=export").'","'.$i18n->get("Export","Icon").'");';
}
$more .= "\nct_contextMenu.print();\n</script>\n";
push(@crumbtrail,$more);
} else {
push(@crumbtrail,'<a href="'.$ancestor->getUrl("func=manageAssets").'">'.$ancestor->getTitle.'</a>');
}
}
my $output = '<div class="am-crumbtrail">'.join(" &gt; ",@crumbtrail).'</div>';
$output .= "
<script type=\"text/javascript\">
//<![CDATA[
var assetManager = new AssetManager();
assetManager.AddColumn('".WebGUI::Form::checkbox($self->session,{name=>"checkAllAssetIds", extras=>'onclick="toggleAssetListSelectAll(this.form);"'})."','','center','form');
assetManager.AddColumn('".$i18n->get("rank")."','style=\"cursor:move\"','center','numeric');
assetManager.AddColumn('&nbsp;','','center','');
assetManager.AddColumn('".$i18n->get("99")."','','left','');
assetManager.AddColumn('".$i18n->get("type")."','','left','');
assetManager.AddColumn('".$i18n->get("last updated")."','','center','');
assetManager.AddColumn('".$i18n->get("size")."','','right','');\n
assetManager.AddColumn('".$i18n->get("locked")."','','center','');\n";
$self->session->output->print($output);
$output = '';
foreach my $child (@{$self->getLineage(["children"],{returnObjects=>1})}) {
$output .= 'var contextMenu = new contextMenu_createWithLink("'.$child->getId.'","More");';
$output .= 'contextMenu.addLink("'.$child->getUrl("func=changeUrl;proceed=manageAssets").'","'.$i18n->get("change url").'");'
if $userUILevel >= $uiLevels->{"changeUrl"};
$output .= 'contextMenu.addLink("'.$child->getUrl("func=editBranch").'","'.$i18n->get("edit branch").'");'
if $userUILevel >= $uiLevels->{"editBranch"};
$output .= 'contextMenu.addLink("'.$child->getUrl("func=createShortcut;proceed=manageAssets").'","'.$i18n->get("create shortcut").'");'
if $userUILevel >= $uiLevels->{"shortcut"};
$output .= 'contextMenu.addLink("'.$child->getUrl("func=manageRevisions").'","'.$i18n->get("revisions").'");'
if $userUILevel >= $uiLevels->{"revisions"};
$output .= 'contextMenu.addLink("'.$child->getUrl.'","'.$i18n->get("view").'"); '."\n"
if $userUILevel >= $uiLevels->{"view"};
$output .= 'contextMenu.addLink("'.$child->getUrl("func=lock;proceed=manageAssets").'","'.$i18n->get("lock").'");'
if $userUILevel >= $uiLevels->{"changeUrl"} && !$child->isLocked;
$output .= 'contextMenu.addLink("'.$child->getUrl("func=export").'","'.$i18n->get("Export","Icon").'");'
if $userUILevel >= $uiLevels->{"export"} && defined $self->session->config->get("exportPath");
my $title = $child->getTitle;
$title =~ s/\'/\\\'/g;
my $locked;
my $edit;
#if ($child->isLocked) {
if ($child->lockedBy) { # This is a stopgap to fix a bug when isLocked is overridden but does not function as in the API
my $username_html = WebGUI::HTML::format($child->lockedBy->username, "text");
$locked = '<img src="'.$self->session->url->extras('assetManager/locked.gif').'" alt="locked by '.$username_html.'" title="locked by '.$username_html.'" style="border: 0px;" />';
$edit = "'<a href=\"".$child->getUrl("func=edit;proceed=manageAssets")."\">Edit</a> | '+" if ($child->canEditIfLocked);
} else {
$edit = "'<a href=\"".$child->getUrl("func=edit;proceed=manageAssets")."\">Edit</a> | '+";
$locked = '<img src="'.$self->session->url->extras('assetManager/unlocked.gif').'" alt="unlocked" style="border: 0px;" />';
}
my $lockLink = ", '<a href=\"".$child->getUrl("func=manageRevisions")."\">".$locked."</a>'";
my $plus = "'&nbsp;&nbsp;&nbsp;&nbsp;'+";
$plus = "'+ '+" if ($child->hasChildren);
$output .= "assetManager.AddLine('"
.WebGUI::Form::checkbox($self->session,{
name=>'assetId',
value=>$child->getId
})
."',".$child->getRank
.",".$edit."contextMenu.draw()"
.",".$plus."'<a href=\"".$child->getUrl("func=manageAssets")."\">".$title
."</a>','<img src=\"".$child->getIcon(1)."\" style=\"border: 0px;\" alt=\"".$child->getName."\" /> ".$child->getName
."','".$self->session->datetime->epochToHuman($child->get("revisionDate"))
."','".formatBytes($child->get("assetSize"))."'".$lockLink.");\n";
$output .= "assetManager.AddLineSortData('','','','".$title."','".$child->getName
."','".$child->get("revisionDate")."','".$child->get("assetSize")."');
assetManager.addAssetMetaData('".$child->getUrl."', '".$child->getRank."', '".$title."');\n";
$self->session->output->print($output,1);
$output = '';
}
$output .= '
assetManager.AddButton("'.$i18n->get("delete").'","deleteList","manageAssets");
assetManager.AddButton("'.$i18n->get("cut").'","cutList","manageAssets");
assetManager.AddButton("'.$i18n->get("copy").'","copyList","manageAssets");
assetManager.AddButton("'.$i18n->get("duplicate").'","duplicateList","manageAssets");
assetManager.initializeDragEventHandlers();
assetManager.Write();
var assetListSelectAllToggle = false;
function toggleAssetListSelectAll(form){
assetListSelectAllToggle = assetListSelectAllToggle ? false : true;
for(var i = 0; i < form.assetId.length; i++)
form.assetId[i].checked = assetListSelectAllToggle;
}
//]]>
</script> <div class="adminConsoleSpacer">
&nbsp;
</div>
<div style="float: left; padding-right: 30px; font-size: 14px;width: 28%;"><fieldset><legend>'.$i18n->get(1083).'</legend>';
$self->session->output->print($output,1);
$output = '';
foreach my $link (@{$self->getAssetAdderLinks("proceed=manageAssets","assetContainers")}) {
$output .= '<p style="display:inline;vertical-align:middle;"><img src="'.$link->{'icon.small'}.'" alt="'.$link->{label}.'" style="border: 0px;vertical-align:middle;" /></p>
<a href="'.$link->{url}.'">'.$link->{label}.'</a> ';
$output .= $self->session->icon->edit("func=edit;proceed=manageAssets",$link->{asset}->get("url")) if ($link->{isPrototype});
$output .= '<br />';
}
$output .= '<hr />';
foreach my $link (@{$self->getAssetAdderLinks("proceed=manageAssets")}) {
$output .= '<p style="display:inline;vertical-align:middle;"><img src="'.$link->{'icon.small'}.'" alt="'.$link->{label}.'" style="border: 0px;vertical-align:middle;" /></p>
<a href="'.$link->{url}.'">'.$link->{label}.'</a> ';
$output .= $self->session->icon->edit("func=edit;proceed=manageAssets",$link->{asset}->get("url")) if ($link->{isPrototype});
$output .= '<br />';
}
$output .= '<hr />';
foreach my $link (@{$self->getAssetAdderLinks("proceed=manageAssets","utilityAssets")}) {
$output .= '<p style="display:inline;vertical-align:middle;"><img src="'.$link->{'icon.small'}.'" alt="'.$link->{label}.'" style="border: 0px;vertical-align:middle;" /></p>
<a href="'.$link->{url}.'">'.$link->{label}.'</a> ';
$output .= $self->session->icon->edit("func=edit;proceed=manageAssets",$link->{asset}->get("url")) if ($link->{isPrototype});
$output .= '<br />';
}
$output .= '</fieldset></div>';
$self->session->output->print($output);
$output = '';
my %options;
tie %options, 'Tie::IxHash';
my $hasClips = 0;
foreach my $asset (@{$self->getAssetsInClipboard(1)}) {
$options{$asset->getId} = '<img src="'.$asset->getIcon(1).'" alt="'.$asset->getName.'" style="border: 0px;" /> '.$asset->getTitle;
$hasClips = 1;
}
if ($hasClips) {
$output .= '<div style="width: 28%; float: left; padding-right: 30px; font-size: 14px;"><fieldset><legend>'.$i18n->get(1082).'</legend>'
.WebGUI::Form::formHeader($self->session, {action=>$self->getUrl})
.WebGUI::Form::hidden($self->session,{name=>"func",value=>"pasteList"})
.WebGUI::Form::checkbox($self->session,{extras=>'onclick="toggleClipboardSelectAll(this.form);"'})
.' '.$i18n->get("select all").'<br />'
.WebGUI::Form::checkList($self->session,{name=>"assetId",vertical=>1,options=>\%options})
.'<br />'
.WebGUI::Form::submit($self->session,{value=>"Paste"})
.WebGUI::Form::formFooter($self->session)
.' </fieldset></div> '
.'<script type="text/javascript">
//<![CDATA[
var clipboardItemSelectAllToggle = false;
function toggleClipboardSelectAll(form){
clipboardItemSelectAllToggle = clipboardItemSelectAllToggle ? false : true;
for(var i = 0; i < form.assetId.length; i++)
form.assetId[i].checked = clipboardItemSelectAllToggle;
}
//]]>
</script>';
}
$self->session->output->print($output);
$output = '<div style="width: 28%;float: left; padding-right: 30px; font-size: 14px;"><fieldset> <legend>'.$i18n->get("packages").'</legend>';
foreach my $asset (@{$self->getPackageList}) {
$output .= '<p style="display:inline;vertical-align:middle;"><img src="'.$asset->getIcon(1).'" alt="'.$asset->getName.'" style="vertical-align:middle;border: 0px;" /></p>
<a href="'.$self->getUrl("func=deployPackage;assetId=".$asset->getId).'">'.$asset->getTitle.'</a> '
.$self->session->icon->edit("func=edit;proceed=manageAssets",$asset->get("url"))
.$self->session->icon->export("func=exportPackage",$asset->get("url"))
.'<br />';
}
$output .= '<br />'.WebGUI::Form::formHeader($self->session, {action=>$self->getUrl})
.WebGUI::Form::hidden($self->session, {name=>"func", value=>"importPackage"})
.'<input type="file" name="packageFile" size="10" style="font-size: 10px;" />'
.WebGUI::Form::submit($self->session, {value=>$i18n->get("import"), extras=>'style="font-size: 10px;"'})
.WebGUI::Form::formFooter($self->session);
$output .= ' </fieldset></div>
<div class="adminConsoleSpacer">
&nbsp;
</div>
';
$self->session->output->print($output);
return undef;
}
#-------------------------------------------------------------------
=head2 manageAssetsSearch ( )
Returns the interface for searching within the asset manager.
=cut
sub manageAssetsSearch {
my $self = shift;
my $i18n = WebGUI::International->new($self->session, "Asset");
my $output = WebGUI::Form::formHeader($self->session);
$output .= WebGUI::Form::text($self->session, { name=>"keywords", value=>$self->session->form->get("keywords")});
my %classes = ();
tie %classes, "Tie::IxHash";
%classes = ("any"=>"Any Class", $self->session->db->buildHash("select distinct(className) from asset"));
delete $classes{"WebGUI::Asset"}; # don't want to search for the root asset
$output .= WebGUI::Form::selectBox($self->session, {name=>"class", value=>$self->session->form->process("class","className"), defaultValue=>"any", options=>\%classes});
$output .= WebGUI::Form::hidden($self->session, {name=>"func", value=>"manageAssets"});
$output .= WebGUI::Form::hidden($self->session, {name=>"doit", value=>"1"});
$output .= WebGUI::Form::submit($self->session, {value=>"Search"});
$output .= WebGUI::Form::formFooter($self->session);
$self->session->output->print($output);
$output = '';
return undef unless ($self->session->form->get("doit") && ($self->session->form->get("keywords") ne "" || $self->session->form->get("class") ne "any"));
my $class = $self->session->form->process("class","className") eq "any" ? undef : $self->session->form->process("class","className");
my $assets = WebGUI::Search->new($self->session,0)->search({
keywords=>$self->session->form->get("keywords"),
classes=>[$class]
})->getAssets;
$output .= "<script type=\"text/javascript\">
//<![CDATA[
var assetManager = new AssetManager();
assetManager.AddColumn('".WebGUI::Form::checkbox($self->session,{name=>"checkAllAssetIds", extras=>'onclick="toggleAssetListSelectAll(this.form);"'})."','','center','form');
assetManager.AddColumn('&nbsp;','','center','');
assetManager.AddColumn('".$i18n->get("99")."','','left','');
assetManager.AddColumn('".$i18n->get("type")."','','left','');
assetManager.AddColumn('".$i18n->get("last updated")."','','center','');
assetManager.AddColumn('".$i18n->get("size")."','','right','');
\n";
$self->session->output->print($output);
$output = '';
foreach my $child (@{$assets}) {
$output .= 'var contextMenu = new contextMenu_createWithLink("'.$child->getId.'","More");
contextMenu.addLink("'.$child->getUrl("func=editBranch").'","'.$i18n->get("edit branch").'");
contextMenu.addLink("'.$child->getUrl("func=createShortcut;proceed=manageAssets").'","'.$i18n->get("create shortcut").'");
contextMenu.addLink("'.$child->getUrl("func=manageRevisions").'","'.$i18n->get("revisions").'");
contextMenu.addLink("'.$child->getUrl.'","'.$i18n->get("view").'"); '."\n";
my $title = $child->getTitle;
$title =~ s/\'/\\\'/g;
my $locked;
my $edit;
if ($child->isLocked) {
$locked = '<img src="'.$self->session->url->extras('assetManager/locked.gif').'" alt="locked" style="border: 0px;" />';
$edit = "'<a href=\"".$child->getUrl("func=edit;proceed=manageAssets")."\">Edit</a> | '+" if ($child->canEditIfLocked);
} else {
$edit = "'<a href=\"".$child->getUrl("func=edit;proceed=manageAssets")."\">Edit</a> | '+";
$locked = '<img src="'.$self->session->url->extras('assetManager/unlocked.gif').'" alt="unlocked" style="border: 0px;" />';
}
my $lockLink = ", '<a href=\"".$child->getUrl("func=manageRevisions")."\">".$locked."</a>'";
$output .= "assetManager.AddLine('"
.WebGUI::Form::checkbox($self->session,{
name=>'assetId',
value=>$child->getId
})
."',".$edit."contextMenu.draw(),"
."'<a href=\"".$child->getUrl("func=manageAssets&manage=1")."\">".$title
."</a>','<img src=\"".$child->getIcon(1)."\" style=\"border: 0px;\" alt=\"".$child->getName."\" /> ".$child->getName
."','".$self->session->datetime->epochToHuman($child->get("revisionDate"))
."','".formatBytes($child->get("assetSize"))."'".$lockLink.");\n";
$output .= "assetManager.AddLineSortData('','','','".$title."','".$child->getName
."','".$child->get("revisionDate")."','".$child->get("assetSize")."');
assetManager.addAssetMetaData('".$child->getUrl."', '".$child->getRank."', '".$title."');\n";
$self->session->output->print($output,1);
$output = '';
}
$output .= 'assetManager.AddButton("'.$i18n->get("delete").'","deleteList","manageAssets");
assetManager.AddButton("'.$i18n->get("cut").'","cutList","manageAssets");
assetManager.AddButton("'.$i18n->get("copy").'","copyList","manageAssets");
assetManager.Write();
var assetListSelectAllToggle = false;
function toggleAssetListSelectAll(form){
assetListSelectAllToggle = assetListSelectAllToggle ? false : true;
for(var i = 0; i < form.assetId.length; i++)
form.assetId[i].checked = assetListSelectAllToggle;
}
//]]>
</script> <div class="adminConsoleSpacer"> &nbsp;</div>';
$self->session->output->print($output);
return undef;
}
#-------------------------------------------------------------------
=head2 new ( session, assetId [, className, revisionDate ] )
@ -2453,7 +2157,7 @@ sub www_changeUrlConfirm {
}
if ($self->session->form->param("proceed") eq "manageAssets") {
$self->session->http->setRedirect($self->getUrl('func=manageAssets'));
$self->session->http->setRedirect($self->getUrl('op=manageAssets'));
} else {
$self->session->http->setRedirect($self->getUrl());
}
@ -2581,35 +2285,15 @@ sub www_editSave {
=head2 www_manageAssets ( )
Main page to manage/search assets. Renders an AdminConsole with a list of assets. If canEdit returns False, renders an insufficient privilege page. Is called by www_manageAssets
Redirect to the asset manager content handler (for backwards
compatibility)
=cut
sub www_manageAssets {
my $self = shift;
return $self->session->privilege->insufficient() unless $self->canEdit;
$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"});
$self->session->style->setLink($self->session->url->extras('assetManager/assetManager.css'), {rel=>"stylesheet",type=>"text/css"});
$self->session->style->setScript($self->session->url->extras('assetManager/assetManager.js'), {type=>"text/javascript"});
if ($self->session->form->get("search")) {
$self->session->scratch->set("manageAssetsSearchToggle",1);
} elsif ($self->session->form->get("manage")) {
$self->session->scratch->delete("manageAssetsSearchToggle");
}
my $out = $self->getAdminConsole->render("~~~");
my ($head, $foot) = split("~~~",$out);
$self->session->style->sent(1);
$self->session->http->sendHeader;
$self->session->output->print($head);
$self->session->output->print('<div style="text-align: right;"><a href="'.$self->getUrl("func=manageAssets;manage=1").'">Manage</a> | <a href="'.$self->getUrl("func=manageAssets;search=1").'">Search</a></div>',1);
if ($self->session->scratch->get("manageAssetsSearchToggle")) {
$self->manageAssetsSearch;
} else {
$self->manageAssets;
}
$self->session->output->print($foot);
return "chunked";
my $self = shift;
$self->session->http->setRedirect( $self->getUrl( 'op=assetManager' ) );
return "redirect";
}
#-------------------------------------------------------------------

View file

@ -950,13 +950,13 @@ sub www_edit {
# Raw HTML here to provide proper value for the image
$file->{ form_promote }
= qq{<button type="submit" name="promote" value="$file->{assetId}">}
= qq{<button type="submit" name="promote" class="promote" value="$file->{assetId}">}
. $session->icon->moveUp( undef, undef, "disabled" )
. qq{</button>}
;
$file->{ form_demote }
= qq{<button type="submit" name="demote" value="$file->{assetId}">}
= qq{<button type="submit" name="demote" class="demote" value="$file->{assetId}">}
. $session->icon->moveDown( undef, undef, "disabled" )
. qq{</button>}
;

View file

@ -312,7 +312,7 @@ sub getToolbar {
return '<script type="text/javascript">
var contextMenu = new contextMenu_createWithImage("'.$self->getIcon(1).'","'.$self->getId.'","'.$self->getName.'");
contextMenu.addLink("'.$self->getUrl("func=copy").'","'.$i18n->get("copy").'");
contextMenu.addLink("'.$self->getUrl("func=manageAssets").'","'.$i18n->get("manage").'");
contextMenu.addLink("'.$self->getUrl("op=manageAssets").'","'.$i18n->get("manage").'");
contextMenu.addLink("'.$self->getUrl.'","'.$i18n->get("view").'");
contextMenu.print();
</script>'.$toolbar;

View file

@ -414,7 +414,7 @@ $self->session->style->setLink($self->session->url->extras('assetManager/assetMa
name=>'assetId',
value=>$child->getId
})
."','" . $plus . "<a href=\"".$child->getUrl("func=manageAssets")."\">" . $title
."','" . $plus . "<a href=\"".$child->getUrl("op=manageAssets")."\">" . $title
."</a>','<p style=\"display:inline;vertical-align:middle;\"><img src=\"".$child->getIcon(1)."\" style=\"border-style:none;vertical-align:middle;\" alt=\"".$child->getName."\" /></p> ".$child->getName
."','".$self->session->datetime->epochToHuman($child->get("revisionDate"))
."','".formatBytes($child->get("assetSize"))."');\n";

View file

@ -339,7 +339,7 @@ sub www_manageTrash {
name=>'assetId',
value=>$child->getId
})
."','" . $plus . "<a href=\"".$child->getUrl("func=manageAssets")."\">" . $title
."','" . $plus . "<a href=\"".$child->getUrl("op=manageAssets")."\">" . $title
."</a>','<p style=\"display:inline;vertical-align:middle;\"><img src=\"".$child->getIcon(1)."\" style=\"vertical-align:middle;border-style:none;\" alt=\"".$child->getName."\" /></p> ".$child->getName
."','".$self->session->datetime->epochToHuman($child->get("revisionDate"))
."','".formatBytes($child->get("assetSize"))."');\n";

View file

@ -0,0 +1,812 @@
package WebGUI::Content::AssetManager;
use strict;
use URI;
use WebGUI::Form;
use WebGUI::Paginator;
use WebGUI::Utility;
#----------------------------------------------------------------------------
=head2 getClassSelectBox ( session )
Gets a select box to choose a class name.
=cut
sub getClassSelectBox {
my $session = shift;
tie my %classes, "Tie::IxHash", (
"" => "Any Class",
$session->db->buildHash("select distinct(className) from asset"),
);
delete $classes{"WebGUI::Asset"}; # don't want to search for the root asset
return WebGUI::Form::selectBox( $session, {
name => "class",
value => $session->form->process("class","className"),
defaultValue => "",
options => \%classes,
});
}
#----------------------------------------------------------------------------
=head2 getCurrentAsset ( session )
Returns the asset we would be looking at if we weren't looking at the Asset
Manager.
=cut
sub getCurrentAsset {
my $session = shift;
return WebGUI::Asset->newByUrl( $session );
}
#----------------------------------------------------------------------------
=head2 getHeader ( session )
Get a header to pick "Manage" or "Search". Add other things later maybe?
=cut
sub getHeader {
my $session = shift;
my $output = '';
my $i18n = WebGUI::International->new( $session, "Asset" );
if ( $session->form->get( 'method' ) eq "search" ) {
$output .= '<div style="float: right">'
. join( " | ",
q{<a href="?op=assetManager;method=manage">} . $i18n->get( 'manage' ) . q{</a>},
q{<strong>} . $i18n->get( "search" ) . q{</strong>},
)
. q{</div>}
;
}
else {
$output .= '<div style="float: right">'
. join( " | ",
q{<strong>} . $i18n->get( "manage" ) . q{</strong>},
q{<a href="?op=assetManager;method=search">} . $i18n->get( "search" ) . q{</a>},
)
. q{</div>}
;
}
return $output;
}
#----------------------------------------------------------------------------
=head2 getManagerPaginator ( session )
Get a page for the Asset Manager view. Returns a WebGUI::Paginator object
filled with asset IDs.
=cut
sub getManagerPaginator {
my $session = shift;
my $asset = getCurrentAsset( $session );
my $orderByColumn = $session->form->get( 'orderByColumn' )
|| "lineage"
;
my $orderByDirection = $session->form->get( 'orderByDirection' ) eq "DESC"
? "DESC"
: "ASC"
;
my $p
= WebGUI::Paginator->new( $session,
'?op=assetManager;method=manage;orderByColumn=' . $orderByColumn
. ';orderByDirection=' . $orderByDirection
);
my $orderBy = $session->db->dbh->quote_identifier( $orderByColumn ) . ' ' . $orderByDirection;
$p->setDataByArrayRef( $asset->getLineage( ['children'] ), { orderByClause => $orderBy } );
return $p;
}
#----------------------------------------------------------------------------
=head2 getSearchPaginator ( session, query )
Get a page for the Asset Search view. Returns a WebGUI::Paginator object
filled with asset IDs.
=cut
sub getSearchPaginator {
my $session = shift;
my $query = shift;
my %parms;
my $s = WebGUI::Search->new( $session, 0 );
$s->search( {
keywords => $query->{ keywords },
classes => $query->{ classes },
} );
my $queryString = 'op=assetManager;method=search;keywords=' . $query->{ keywords };
for my $class ( @{ $query->{ classes } } ) {
$queryString .= ';class=' . $class;
}
my $p = $s->getPaginatorResultSet( $session->url->page( $queryString ) );
return $p;
}
#----------------------------------------------------------------------------
=head2 getMoreMenu ( asset, label )
Gets the "More" menu with the specified label.
=cut
sub getMoreMenu {
my $asset = shift;
my $label = shift || "More";
my $userUiLevel = $asset->session->user->profileField("uiLevel");
my $toolbarUiLevel = $asset->session->config->get("assetToolbarUiLevel");
my $i18n = WebGUI::International->new( $asset->session, "Asset" );
### The More menu
my @more_fields = (); # The fields to fill in the more menu
my $more_markup = q{<span class="moreMenu"><a href="#">} . $label . q{</a>}
. q{<ul>}
;
# These links are shown based on UI level
if ( $userUiLevel >= $toolbarUiLevel->{ "changeUrl" } ) {
$more_markup .= q{<li><a href="%s">%s</a></li>};
push @more_fields, $asset->getUrl( 'func=changeUrl;proceed=manageAssets' ), $i18n->get( 'change url' );
}
if ( $userUiLevel >= $toolbarUiLevel->{ "editBranch" } ) {
$more_markup .= q{<li><a href="%s">%s</a></li>};
push @more_fields, $asset->getUrl( 'func=editBranch' ), $i18n->get( 'edit branch' );
}
if ( $userUiLevel >= $toolbarUiLevel->{ "shortcut" } ) {
$more_markup .= q{<li><a href="%s">%s</a></li>};
push @more_fields, $asset->getUrl( 'func=createShortcut;proceed=manageAssets' ), $i18n->get( 'create shortcut' );
}
if ( $userUiLevel >= $toolbarUiLevel->{ "revisions" } ) {
$more_markup .= q{<li><a href="%s">%s</a></li>};
push @more_fields, $asset->getUrl( 'func=manageRevisions' ), $i18n->get( 'revisions' );
}
if ( $userUiLevel >= $toolbarUiLevel->{ "view" } ) {
$more_markup .= q{<li><a href="%s">%s</a></li>};
push @more_fields, $asset->getUrl, $i18n->get( 'view' );
}
if ( $userUiLevel >= $toolbarUiLevel->{ "edit" } ) {
$more_markup .= q{<li><a href="%s">%s</a></li>};
push @more_fields, $asset->getUrl( 'func=edit;proceed=manageAssets' ), $i18n->get( 'edit' );
}
if ( $userUiLevel >= $toolbarUiLevel->{ "lock" } ) {
$more_markup .= q{<li><a href="%s">%s</a></li>};
push @more_fields, $asset->getUrl( 'func=lock;proceed=manageAssets' ), $i18n->get( 'lock' );
}
if ( $asset->session->config->get("exportPath") && $userUiLevel >= $toolbarUiLevel->{"export"} ) {
$more_markup .= q{<li><a href="%s">%s</a></li>};
push @more_fields, $asset->getUrl( 'func=export' ), $i18n->get( 'Export Page' );
}
$more_markup .= q{</ul>}
. q{</span>}
;
return sprintf $more_markup, @more_fields;
}
#----------------------------------------------------------------------------
=head2 getOrderLink ( session, column, label )
Gets a link to order the results based on a column. Uses some magick
to ensure proper working no matter where we are.
=cut
sub getOrderLink {
my $session = shift;
my $column = shift;
my $label = shift;
my $columnParam = "orderByColumn";
my $directionParam = "orderByDirection";
my $url = URI->new( $session->env->get( "REQUEST_URI" ) );
my $query = $url->query;
# Split query string into param => value hash
my %query = map { /(.+)=(.+)/; $1 => $2 } split /[;&]/, $query;
# Delete unnecessary keys
delete $query{ 'assetId' };
# Add necessary keys
$query{ $columnParam } = $column;
if ( $session->form->get( $columnParam ) eq $column && $session->form->get( $directionParam ) eq "ASC" ) {
$query{ $directionParam } = "DESC";
}
else {
$query{ $directionParam } = "ASC";
}
$url->query_form( %query );
return q{<a href="} . $url->as_string . q{">}
. $label
. q{</a>}
;
}
#----------------------------------------------------------------------------
=head2 handler ( session )
Handle the session, if we can. Otherwise pass it on.
Check permissions
=cut
# BAD things about procedural that would be fixed with class methods
# 1) I must use stringy eval to call my method, instead of $class->$method( args )
# 2) I must validate that method using a list of known methods instead of $class->can( $method )
sub handler {
my ( $session ) = @_;
if ( $session->form->get( 'op' ) eq 'assetManager' && getCurrentAsset( $session ) ) {
return $session->privilege->noAccess unless getCurrentAsset( $session )->canEdit;
my $method = $session->form->get( 'method' )
? 'www_' . $session->form->get( 'method' )
: 'www_manage'
;
# Validate the method name
if ( !grep { $_ eq $method } qw( www_manage www_search ) ) {
return "Invalid method";
}
else {
# I hate hate hate stringy eval
return eval "$method" . '($session)';
}
}
else {
return;
}
}
#----------------------------------------------------------------------------
=head2 www_manage ( session )
Show the main screen of the asset manager, paginated. Also load the
JavaScript that will take over if the browser has the cojones.
# BAD things about procedural that would be fixed with class methods
# 3) The "appendSideLinks" method would be better as simply "getAdminStyle" and would do more
=cut
sub www_manage {
my ( $session ) = @_;
my $ac = WebGUI::AdminConsole->new( $session, "assets" );
my $currentAsset = getCurrentAsset( $session );
my $i18n = WebGUI::International->new( $session, "Asset" );
### Do Action
if ( my $action = $session->form->get( 'action' ) ) {
my @assetIds = $session->form->get( 'assetId' );
if ( $action eq "update" ) {
for my $assetId ( @assetIds ) {
my $asset = WebGUI::Asset->newByDynamicClass( $session, $assetId );
next unless $asset;
my $rank = $session->form->get( $assetId . '_rank' );
next unless $rank; # There's no such thing as zero
$asset->setRank( $rank );
}
}
elsif ( $action eq "trash" ) {
for my $assetId ( @assetIds ) {
my $asset = WebGUI::Asset->newByDynamicClass( $session, $assetId );
next unless $asset;
$asset->trash;
}
}
elsif ( $action eq "cut" ) {
for my $assetId ( @assetIds ) {
my $asset = WebGUI::Asset->newByDynamicClass( $session, $assetId );
next unless $asset;
$asset->cut;
}
}
elsif ( $action eq "copy" ) {
for my $assetId ( @assetIds ) {
# Copy == Duplicate + Cut
my $asset = WebGUI::Asset->newByDynamicClass( $session, $assetId);
my $newAsset = $asset->duplicate( { skipAutoCommitWorkflows => 1 } );
$newAsset->update( { title => $newAsset->getTitle . ' (copy)' } );
$newAsset->cut;
}
}
elsif ( $action eq "duplicate" ) {
for my $assetId ( @assetIds ) {
my $asset = WebGUI::Asset->newByDynamicClass( $session, $assetId );
next unless $asset;
$asset->duplicate( { skipAutoCommitWorkflows => 1 } );
}
}
}
# Show the page
$session->style->setLink( $session->url->extras( 'yui-webgui/build/assetManager/assetManager.css' ), { rel => "stylesheet", type => 'text/css' } );
$session->style->setScript( $session->url->extras( 'yui/build/yahoo-dom-event/yahoo-dom-event.js' ) );
$session->style->setScript( $session->url->extras( 'yui-webgui/build/assetManager/assetManager.js' ) );
$session->style->setScript( $session->url->extras( 'yui-webgui/build/form/form.js' ) );
$session->style->setRawHeadTags( <<'ENDHTML' );
<script type="text/javascript">
YAHOO.util.Event.onDOMReady( WebGUI.AssetManager.initManager );
</script>
ENDHTML
my $output = '<div id="assetManager">' . getHeader( $session );
### Crumbtrail
my $crumb_markup = '<li> &gt; <a href="%s">%s</a></li>';
my $ancestors = $currentAsset->getLineage( ['ancestors'], { returnObjects => 1 } );
$output .= '<ol id="crumbtrail">';
for my $asset ( @{ $ancestors } ) {
$output .= sprintf $crumb_markup,
$asset->getUrl( 'op=assetManager;method=manage' ),
$asset->get( "menuTitle" ),
;
}
# And ourself
$output .= sprintf '<li> &gt; %s</li>',
getMoreMenu( $currentAsset, $currentAsset->get( "menuTitle" ) ),
;
$output .= '</ol>';
### The page of assets
$output .= q{<form>}
. q{<input type="hidden" name="op" value="assetManager" />}
. q{<input type="hidden" name="method" value="manage" />}
. q{<table class="assetManager" border="0" id="assetManager">}
. q{<thead>}
. q{<tr>}
. q{<th class="center"><input type="checkbox" onclick="WebGUI.Form.toggleAllCheckboxesInForm( this.form, 'assetId' )" /></th>} # Checkbox column
. q{<th class="center">} . getOrderLink( $session, "lineage", $i18n->get( "rank" ) ) . q{</th>} # Rank column
. q{<th class="center">&nbsp;</th>} # Edit / More
. q{<th>} . getOrderLink( $session, "title", $i18n->get( "99" ) ) . q{</th>} # Title
. q{<th>} . getOrderLink( $session, "className", $i18n->get( "type" ) ) . q{</th>} # Type
. q{<th class="center">} . getOrderLink( $session, "revisionDate", $i18n->get( "last updated" ) ) . q{</th>} # Revision Date
. q{<th class="center">} . getOrderLink( $session, "assetSize", $i18n->get( "size" ) ) . q{</th>} # Size
. q{<th class="center">} . getOrderLink( $session, "lockedBy", $i18n->get( "locked" ) ) . q{</th>} # Lock
. q{</tr>}
. q{</thead}
. q{<tbody>}
;
# The markup for a single asset
my $row_markup = q{<tr %s ondblclick="WebGUI.AssetManager.toggleRow( this )">}
. q{<td class="center"><input type="checkbox" name="assetId" value="%s" onchange="WebGUI.AssetManager.toggleHighlightForRow( this )" /></td>}
. q{<td class="center"><input type="text" class="rank" name="%s_rank" size="3" value="%s" onchange="WebGUI.AssetManager.selectRow( this )" /></td>}
. q{<td class="center">%s %s</td>}
. q{<td><span class="hasChildren">%s</span><a href="%s?op=assetManager;method=manage">%s</a></td>}
. q{<td><img src="%s" /> %s</td>}
. q{<td class="center">%s</td>}
. q{<td class="right">%s</td>}
. q{<td class="center"><a href="%s?func=manageRevisions">%s</a></td>}
. q{</tr>}
;
# The field keys to fill in the placeholders
my @row_fields = qw(
alt
assetId
assetId rank
editLink moreMenu
hasChildren url title
iconUrl type
revisionDate
size
url lockIcon
);
my $p = getManagerPaginator( $session, {
orderByColumn => $session->form->get( 'orderByColumn' ),
orderByDirection => $session->form->get( 'orderByDirection' ),
} );
my $count = 0;
for my $assetId ( @{ $p->getPageData } ) {
$count++;
my $asset = WebGUI::Asset->newByDynamicClass( $session, $assetId );
# Populate the required fields to fill in
my %fields = (
alt => ( $count % 3 == 0 ? 'class="alt"' : '' ),
assetId => $asset->getId,
url => $asset->getUrl,
title => $asset->get( "title" ),
revisionDate => $session->datetime->epochToHuman( $asset->get( "revisionDate" ) ),
hasChildren => ( $asset->hasChildren ? "+&nbsp;" : "&nbsp;&nbsp;" ),
rank => $asset->getRank,
size => formatBytes( $asset->get( 'assetSize' ) ),
);
# The asset icon
my $icon = [ grep { $_->{ icon } } @{ $asset->definition( $session ) } ]->[ 0 ]->{ icon };
$fields{ iconUrl } = $session->url->extras( '/assets/small/' . $icon );
# The asset type (i18n name)
my $type = [ grep { $_->{ assetName } } @{ $asset->definition( $session ) } ]->[ 0 ]->{ assetName };
$fields{ type } = $type;
# The lock
if ( $asset->lockedBy ) { # lockedBy in case someone overrides isLocked (like the Collab System Thread )
$fields{ lockIcon }
= sprintf '<img src="%s" alt="locked by %s" title="locked by %s" style="border: 0px;" />',
$session->url->extras( 'assetManager/locked.gif' ),
WebGUI::HTML::format( $asset->lockedBy->username, "text" ),
WebGUI::HTML::format( $asset->lockedBy->username, "text" ),
;
}
else {
$fields{ lockIcon }
= sprintf '<img src="%s" alt="unlocked" title="unlocked" style="border: 0px;" />',
$session->url->extras( 'assetManager/unlocked.gif' ),
;
}
# The edit link
if ( !$asset->lockedBy || $asset->canEditIfLocked ) {
$fields{ editLink }
= sprintf '<a href="%s">' . $i18n->get( "edit" ) . '</a> |',
$asset->getUrl( 'func=edit;proceed=manageAssets' )
;
}
# The More menu
$fields{ moreMenu } = getMoreMenu( $asset, $i18n->get( 'menu label' ) );
$output .= sprintf $row_markup, @fields{ @row_fields };
}
$output .= q{</tbody>}
. q{</table>}
. q{<p class="actions">} . $i18n->get( 'with selected' )
. q{<button name="action" value="update">} . $i18n->get( "update" ) . q{</button>}
. q{<button name="action" value="trash">} . $i18n->get( "delete" ) . q{</button>}
. q{<button name="action" value="cut">} . $i18n->get( 'cut' ) . q{</button>}
. q{<button name="action" value="copy">} . $i18n->get( "copy" ) . q{</button>}
. q{<button name="action" value="duplicate">} . $i18n->get( "duplicate" ) . q{</button>}
. q{</p>}
. q{</form>}
;
### Page links
$output .= q{<div id="pageLinks">} . $p->getBarAdvanced . q{</div>};
### Page description
$output .= sprintf q{<div id="pageStats">} . $i18n->get( 'page indicator' ) . q{</div>},
$p->getPageNumber,
$p->getNumberOfPages,
;
### Clearing div
$output .= q{<div style="clear: both;">&nbsp;</div>};
### New Content
$output .= q{<div class="functionPane"><fieldset><legend>} . $i18n->get( '1083' ) . '</legend>';
foreach my $link (@{$currentAsset->getAssetAdderLinks("proceed=manageAssets","assetContainers")}) {
$output .= '<p style="display:inline;vertical-align:middle;"><img src="'.$link->{'icon.small'}.'" alt="'.$link->{label}.'" style="border: 0px;vertical-align:middle;" /></p>
<a href="'.$link->{url}.'">'.$link->{label}.'</a> ';
$output .= $session->icon->edit("func=edit;proceed=manageAssets",$link->{asset}->get("url")) if ($link->{isPrototype});
$output .= '<br />';
}
$output .= '<hr />';
foreach my $link (@{$currentAsset->getAssetAdderLinks("proceed=manageAssets")}) {
$output .= '<p style="display:inline;vertical-align:middle;"><img src="'.$link->{'icon.small'}.'" alt="'.$link->{label}.'" style="border: 0px;vertical-align:middle;" /></p>
<a href="'.$link->{url}.'">'.$link->{label}.'</a> ';
$output .= $session->icon->edit("func=edit;proceed=manageAssets",$link->{asset}->get("url")) if ($link->{isPrototype});
$output .= '<br />';
}
$output .= '<hr />';
foreach my $link (@{$currentAsset->getAssetAdderLinks("proceed=manageAssets","utilityAssets")}) {
$output .= '<p style="display:inline;vertical-align:middle;"><img src="'.$link->{'icon.small'}.'" alt="'.$link->{label}.'" style="border: 0px;vertical-align:middle;" /></p>
<a href="'.$link->{url}.'">'.$link->{label}.'</a> ';
$output .= $session->icon->edit("func=edit;proceed=manageAssets",$link->{asset}->get("url")) if ($link->{isPrototype});
$output .= '<br />';
}
$output .= '</fieldset></div>';
tie my %options, 'Tie::IxHash';
my $hasClips = 0;
foreach my $asset (@{$currentAsset->getAssetsInClipboard(1)}) {
$options{$asset->getId} = '<img src="'.$asset->getIcon(1).'" alt="'.$asset->getName.'" style="border: 0px;" /> '.$asset->getTitle;
$hasClips = 1;
}
if ($hasClips) {
$output .= '<div class="functionPane"><fieldset><legend>'.$i18n->get(1082).'</legend>'
.WebGUI::Form::formHeader($session, {action=>$currentAsset->getUrl})
.WebGUI::Form::hidden($session,{name=>"func",value=>"pasteList"})
.WebGUI::Form::checkbox($session,{extras=>'onclick="toggleClipboardSelectAll(this.form);"'})
.' '.$i18n->get("select all").'<br />'
.WebGUI::Form::checkList($session,{name=>"assetId",vertical=>1,options=>\%options})
.'<br />'
.WebGUI::Form::submit($session,{value=>"Paste"})
.WebGUI::Form::formFooter($session)
.' </fieldset></div> '
.'<script type="text/javascript">
//<![CDATA[
var clipboardItemSelectAllToggle = false;
function toggleClipboardSelectAll(form){
clipboardItemSelectAllToggle = clipboardItemSelectAllToggle ? false : true;
for(var i = 0; i < form.assetId.length; i++)
form.assetId[i].checked = clipboardItemSelectAllToggle;
}
//]]>
</script>';
}
## Packages
$output .= '<div class="functionPane"><fieldset> <legend>'.$i18n->get("packages").'</legend>';
foreach my $asset (@{$currentAsset->getPackageList}) {
$output .= '<p style="display:inline;vertical-align:middle;"><img src="'.$asset->getIcon(1).'" alt="'.$asset->getName.'" style="vertical-align:middle;border: 0px;" /></p>
<a href="'.$currentAsset->getUrl("func=deployPackage;assetId=".$asset->getId).'">'.$asset->getTitle.'</a> '
.$session->icon->edit("func=edit;proceed=manageAssets",$asset->get("url"))
.$session->icon->export("func=exportPackage",$asset->get("url"))
.'<br />';
}
$output .= '<br />'.WebGUI::Form::formHeader($session, {action=>$currentAsset->getUrl})
.WebGUI::Form::hidden($session, {name=>"func", value=>"importPackage"})
.'<input type="file" name="packageFile" size="10" style="font-size: 10px;" />'
.WebGUI::Form::submit($session, {value=>$i18n->get("import"), extras=>'style="font-size: 10px;"'})
.WebGUI::Form::formFooter($session);
$output .= ' </fieldset></div>';
### Clearing div
$output .= q{<div style="clear: both;">&nbsp;</div>};
$output .= q{</div>};
return $ac->render( $output );
}
#----------------------------------------------------------------------------
=head2 www_search ( session )
Search assets underneath this asset.
=cut
sub www_search {
my $session = shift;
my $ac = WebGUI::AdminConsole->new( $session, "assets" );
my $i18n = WebGUI::International->new( $session, "Asset" );
my $output = '<div id="assetManager">' . getHeader( $session );
$session->style->setLink( $session->url->extras( 'yui-webgui/build/assetManager/assetManager.css' ), { rel => "stylesheet", type => 'text/css' } );
$session->style->setScript( $session->url->extras( 'yui/build/yahoo-dom-event/yahoo-dom-event.js' ) );
$session->style->setScript( $session->url->extras( 'yui-webgui/build/assetManager/assetManager.js' ) );
$session->style->setScript( $session->url->extras( 'yui-webgui/build/form/form.js' ) );
$session->style->setRawHeadTags( <<'ENDHTML' );
<script type="text/javascript">
YAHOO.util.Event.onDOMReady( WebGUI.AssetManager.initSearch );
</script>
ENDHTML
### Show the form
$output .= q{<form><p>}
. q{<input type="hidden" name="op" value="assetManager" />}
. q{<input type="hidden" name="method" value="search" />}
. q{<input type="text" size="45" name="keywords" value="} . $session->form->get('keywords') . q{" />}
. getClassSelectBox( $session )
. q{<button name="action" value="search">} . $i18n->get( "search" ) . q{</button>}
. q{</p></form>}
;
### Actions
if ( my $action = $session->form->get( 'action' ) ) {
my @assetIds = $session->form->get( 'assetId' );
if ( $action eq "trash" ) {
for my $assetId ( @assetIds ) {
my $asset = WebGUI::Asset->newByDynamicClass( $session, $assetId );
next unless $asset;
$asset->trash;
}
}
elsif ( $action eq "cut" ) {
for my $assetId ( @assetIds ) {
my $asset = WebGUI::Asset->newByDynamicClass( $session, $assetId );
next unless $asset;
$asset->cut;
}
}
elsif ( $action eq "copy" ) {
for my $assetId ( @assetIds ) {
# Copy == Duplicate + Cut
my $asset = WebGUI::Asset->newByDynamicClass( $session, $assetId);
my $newAsset = $asset->duplicate( { skipAutoCommitWorkflows => 1 } );
$newAsset->update( { title => $newAsset->getTitle . ' (copy)' } );
$newAsset->cut;
}
}
}
### Run the search
if ( $session->form->get( 'keywords' ) || $session->form->get( 'class' ) ) {
my $keywords = $session->form->get( 'keywords' );
my @classes = $session->form->get( 'class' );
my $p = getSearchPaginator( $session, {
keywords => $keywords,
classes => \@classes,
orderByColumn => $session->form->get( 'orderByColumn' ),
orderByDirection => $session->form->get( 'orderByDirection' ),
} );
if ( $p->getRowCount == 0 ) {
$output .= q{<p class="error">} . $i18n->get( 'no results' ) . q{</p>};
}
else {
### Display the search results
$output .= q{<form>}
. q{<input type="hidden" name="op" value="assetManager" />}
. q{<input type="hidden" name="method" value="search" />}
. q{<input type="hidden" name="pn" value="} . $session->form->get('pn') . q{" />}
. q{<input type="hidden" name="keywords" value="} . $keywords . q{" />}
;
# Add classes to the form
for my $class ( @classes ) {
$output .= q{<input type="hidden" name="class" value="} . $class . q{" />};
}
$output .= q{<table class="assetManager" border="0">}
. q{<thead>}
. q{<tr>}
. q{<th class="center"><input type="checkbox" onclick="WebGUI.Form.toggleAllCheckboxesInForm( this.form, 'assetId' )" /></th>} # Checkbox column
. q{<th class="center">&nbsp;</th>} # Edit / More
. q{<th>} . $i18n->get( '99' ) . q{</th>} # Title
. q{<th>} . $i18n->get( "type" ) . q{</th>} # Type
. q{<th class="center">} . $i18n->get( "last updated" ) . q{</th>} # Revision Date
. q{<th class="center">} . $i18n->get( "size" ) . q{</th>} # Size
. q{<th class="center">} . $i18n->get( "locked" ) . q{</th>} # Lock
. q{</tr>}
. q{</thead}
. q{<tbody>}
;
# The markup for a single asset
my $row_markup = q{<tr %s ondblclick="WebGUI.AssetManager.toggleRow( this )">}
. q{<td class="center"><input type="checkbox" name="assetId" value="%s" onchange="WebGUI.AssetManager.toggleHighlightForRow( this )" /></td>}
. q{<td class="center">%s %s</td>}
. q{<td>%s</td>}
. q{<td><img src="%s" /> %s</td>}
. q{<td class="center">%s</td>}
. q{<td class="right">%s</td>}
. q{<td class="center"><a href="%s?func=manageRevisions">%s</a></td>}
. q{</tr>}
;
# The field keys to fill in the placeholders
my @row_fields = qw(
alt
assetId
editLink moreMenu
title
iconUrl type
revisionDate
size
url lockIcon
);
my $count = 0;
for my $assetInfo ( @{ $p->getPageData } ) {
$count++;
my $asset = WebGUI::Asset->newByDynamicClass( $session, $assetInfo->{ assetId } );
# Populate the required fields to fill in
my %fields = (
alt => ( $count % 3 == 0 ? 'class="alt"' : '' ),
assetId => $asset->getId,
url => $asset->getUrl,
title => $asset->get( "title" ),
revisionDate => $session->datetime->epochToHuman( $asset->get( "revisionDate" ) ),
hasChildren => ( $asset->hasChildren ? "+&nbsp;" : "&nbsp;&nbsp;" ),
rank => $asset->getRank,
size => formatBytes( $asset->get( 'assetSize' ) ),
);
# The asset icon
my $icon = [ grep { $_->{ icon } } @{ $asset->definition( $session ) } ]->[ 0 ]->{ icon };
$fields{ iconUrl } = $session->url->extras( '/assets/small/' . $icon );
# The asset type (i18n name)
my $type = [ grep { $_->{ assetName } } @{ $asset->definition( $session ) } ]->[ 0 ]->{ assetName };
$fields{ type } = $type;
# The lock
if ( $asset->lockedBy ) { # lockedBy in case someone overrides isLocked (like the Collab System Thread )
$fields{ lockIcon }
= sprintf '<img src="%s" alt="locked by %s" title="locked by %s" style="border: 0px;" />',
$session->url->extras( 'assetManager/locked.gif' ),
WebGUI::HTML::format( $asset->lockedBy->username, "text" ),
WebGUI::HTML::format( $asset->lockedBy->username, "text" ),
;
}
else {
$fields{ lockIcon }
= sprintf '<img src="%s" alt="unlocked" title="unlocked" style="border: 0px;" />',
$session->url->extras( 'assetManager/unlocked.gif' ),
;
}
# The edit link
if ( !$asset->lockedBy || $asset->canEditIfLocked ) {
$fields{ editLink }
= sprintf '<a href="%s">' . $i18n->get( "edit" ) . '</a> |',
$asset->getUrl( 'func=edit' )
;
}
# The More menu
$fields{ moreMenu } = getMoreMenu( $asset, $i18n->get( "menu label" ) );
$output .= sprintf $row_markup, @fields{ @row_fields };
}
$output .= q{</tbody>}
. q{</table>}
. q{<p class="actions">} . $i18n->get( 'with selected' )
. q{<button name="action" value="trash">} . $i18n->get( 'delete' ) . q{</button>}
. q{<button name="action" value="cut">} . $i18n->get( "cut" ) . q{</button>}
. q{<button name="action" value="copy">} . $i18n->get( "copy" ) . q{</button>}
. q{</p>}
. q{</form>}
;
### Page links
$output .= q{<div id="pageLinks">} . $p->getBarAdvanced . q{</div>};
### Page description
$output .= sprintf q{<div id="pageStats">} . $i18n->get( 'page indicator' ) . q{</div>},
$p->getPageNumber,
$p->getNumberOfPages,
;
### Clearing div
$output .= q{<div style="clear: both;">&nbsp;</div>};
}
}
$output .= '</div>';
return $ac->render( $output );
}
1;

View file

@ -176,7 +176,7 @@ sub toHtmlWithWrapper {
$returnUrl = ";proceed=goBackToPage;returnUrl=".$self->session->url->escape($self->session->asset->getUrl);
}
my $buttons = $self->session->icon->edit("func=edit".$returnUrl,$template->get("url"));
$buttons .= $self->session->icon->manage("func=manageAssets",$template->getParent->get("url"));
$buttons .= $self->session->icon->manage("op=manageAssets",$template->getParent->get("url"));
$self->set("subtext",$buttons . $self->get("subtext"));
}
return $self->SUPER::toHtmlWithWrapper;

View file

@ -398,7 +398,7 @@ sub search {
if ($rules->{classes}) {
my @phrases = ();
foreach my $class (@{$rules->{classes}}) {
next unless defined $class;
next unless $class;
push(@params, $class);
push(@phrases, "className=?");
}

View file

@ -53,11 +53,14 @@ sub handler {
$request->push_handlers(PerlResponseHandler => sub {
my $session = WebGUI::Session->open($server->dir_config('WebguiRoot'), $config->getFilename, $request, $server);
foreach my $handler (@{$config->get("contentHandlers")}) {
my $output = eval { WebGUI::Pluggable::run($handler, "handler", [ $session ] ) };
my $output = WebGUI::Pluggable::run($handler, "handler", [ $session ] );
if ( my $e = WebGUI::Error->caught ) {
$session->errorHandler->error($e->package.":".$e->line." - ".$e->error);
$session->errorHandler->debug($e->package.":".$e->line." - ".$e->trace);
}
elsif ( $@ ) {
$session->errorHandler->error( $@ );
}
else {
if ($output eq "chunked") {
if ($session->errorHandler->canShowDebug()) {

View file

@ -1048,6 +1048,42 @@ Couldn't open %-s because %-s <br />
lastUpdated => 0,
},
'search' => {
message => q{Search},
lastUpdated => 0,
context => "Label for the Search function of the asset manager",
},
'with selected' => {
message => q{With Selected: },
lastUpdated => 0,
context => q{Introduction to the action buttons.},
},
'update' => {
message => q{Update},
lastUpdated => 0,
context => q{Label for the update action. Currently only affects rank.},
},
'page indicator' => {
message => q{Showing page %s of %s},
lastUpdated => 0,
context => q{Which page we're on. First field is the current page. Second field is the total number of pages},
},
'no results' => {
message => q{No Results Found!},
lastUpdated => 0,
context => q{Message when no assets match search criteria},
},
'menu label' => {
message => q{More},
lastUpdated => 0,
context => q{Label for the menu to show actions to perform on an asset},
},
};
1;