package WebGUI::Content::AssetManager;
use strict;
use JSON qw( from_json to_json );
use URI;
use WebGUI::Form;
use WebGUI::Paginator;
use WebGUI::Utility;
use WebGUI::Macro::AdminBar;
#----------------------------------------------------------------------------
=head2 getClassSelectBox ( session )
Gets a select box to choose a class name.
=cut
sub getClassSelectBox {
my $session = shift;
my $i18n = WebGUI::International->new($session, 'Asset');
tie my %classes, "Tie::IxHash", (
"" => $i18n->get("Any Class"),
$session->db->buildHash("select distinct(className) from asset"),
);
delete $classes{"WebGUI::Asset"}; # don't want to search for the root asset
#my $className = $session->form->process("class","className") || $session->scratch->get('assetManagerSearchClassName');
my $className = $session->form->get('action') ? $session->form->process('class', "className")
: $session->scratch->get('assetManagerSearchPageNumber')
;
$session->scratch->set('assetManagerSearchClassName', $className);
return WebGUI::Form::selectBox( $session, {
name => "class",
value => $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 .= '
};
tie my %options, 'Tie::IxHash';
my $hasClips = 0;
my $clipNum = 0;
foreach my $asset (@{$currentAsset->getAssetsInClipboard(1)}) {
$options{$asset->getId} = ' '.$asset->getTitle;
$hasClips = 1;
$clipNum++;
}
if ($hasClips) {
$output .= ' '
.'';
}
## Packages
$output .= '';
### Clearing div
$output .= q{
};
$output .= q{
};
### Write the JavaScript that will take over
$output .= '
ENDJS
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 $currentAsset = getCurrentAsset($session);
my $output = '
' . 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' ) );
my $keywords = $session->form->get('keywords') || $session->scratch->get('assetManagerSearchKeywords');
### Show the form
$output .= q{}
;
### Run the search
if ( $keywords || $session->form->get( 'class' ) ) {
my @classes = $session->form->get( 'class' );
my $keywordsScrubbed = $keywords;
# Detect a helper word key
my @assetIds = ($keywords =~ /assetid:\s*([^\s]+)/gi);
# purge helper word keys
if (@assetIds) {
$keywordsScrubbed =~ s/\bassetid:\s*[^\s]+//gi;
}
$keywordsScrubbed =~ s/^\s+//g;
$keywordsScrubbed =~ s/\s+$//g;
my $p = getSearchPaginator( $session, {
assetIds => \@assetIds,
keywords => $keywordsScrubbed,
classes => \@classes,
orderByColumn => $session->form->get( 'orderByColumn' ),
orderByDirection => $session->form->get( 'orderByDirection' ),
} );
if ( $p->getRowCount == 0 ) {
$output .= q{