change admin console to get asset info via ajax call after frame is loaded

this is step one in making the asset control toolbars work
correctly without having an "Admin Mode"
This commit is contained in:
Doug Bell 2011-04-14 15:08:35 -05:00
parent eec3986cf7
commit f5ebb6e916
3 changed files with 116 additions and 99 deletions

View file

@ -122,6 +122,38 @@ sub getAdminPluginTemplateVars {
#----------------------------------------------------------------------
=head2 getAssetData ( asset )
Get the required data for an asset, including the properties and helpers.
Returns a hashref.
=cut
sub getAssetData {
my ( $self, $asset ) = @_;
# Populate the required fields to fill in
my %fields = (
assetId => $asset->getId,
url => $asset->getUrl,
lineage => $asset->lineage,
title => $asset->menuTitle,
revisionDate => $asset->revisionDate,
childCount => $asset->getChildCount,
assetSize => $asset->assetSize,
lockedBy => ($asset->isLockedBy ? $asset->lockedBy->username : ''),
canEdit => $asset->canEdit && $asset->canEditIfLocked,
helpers => $asset->getHelpers,
icon => $asset->getIcon("small"),
className => $asset->getName,
revisions => [ $asset->getRevisionDates ],
);
return \%fields;
}
#----------------------------------------------------------------------
=head2 getAssetTypes ( )
Get a hash of className => info pairs containing information about the
@ -480,6 +512,22 @@ sub www_findUser {
#----------------------------------------------------------------------
=head2 www_getAssetData ( )
Get data for an asset, including properties and asset helpers.
=cut
sub www_getAssetData {
my ( $self ) = @_;
my $session = $self->session;
my $assetId = $session->form->get('assetId');
my $asset = WebGUI::Asset->newById( $session, $assetId );
return JSON->new->encode( $self->getAssetData( $asset ) );
}
#----------------------------------------------------------------------
=head2 www_getClipboard ( )
Get the assets currently on the user's clipboard
@ -496,13 +544,7 @@ sub www_getClipboard {
my $assets = WebGUI::Asset->getRoot( $session )->getAssetsInClipboard( $userOnly );
my @assetInfo = ();
for my $asset ( @{$assets} ) {
push @assetInfo, {
assetId => $asset->getId,
url => $asset->getUrl,
title => $asset->menuTitle,
revisionDate => $asset->revisionDate,
icon => $asset->getIcon("small"),
};
push @assetInfo, $self->getAssetData( $asset );
}
return JSON->new->encode( \@assetInfo );
@ -557,43 +599,16 @@ sub www_getTreeData {
for my $assetId ( @{ $p->getPageData } ) {
my $asset = WebGUI::Asset->newById( $session, $assetId );
# Populate the required fields to fill in
my %fields = (
assetId => $asset->getId,
url => $asset->getUrl,
lineage => $asset->lineage,
title => $asset->menuTitle,
revisionDate => $asset->revisionDate,
childCount => $asset->getChildCount,
assetSize => $asset->assetSize,
lockedBy => ($asset->isLockedBy ? $asset->lockedBy->username : ''),
canEdit => $asset->canEdit && $asset->canEditIfLocked,
helpers => $asset->getHelpers,
icon => $asset->getIcon("small"),
className => $asset->getName,
);
push @{ $assetInfo->{ assets } }, \%fields;
push @{ $assetInfo->{ assets } }, $self->getAssetData( $asset );
}
$assetInfo->{ totalAssets } = $p->getRowCount;
$assetInfo->{ sort } = $session->form->get( 'orderByColumn' );
$assetInfo->{ dir } = lc $session->form->get( 'orderByDirection' );
$assetInfo->{ currentAsset } = {
assetId => $asset->getId,
url => $asset->getUrl,
title => $asset->getTitle,
icon => $asset->getIcon("small"),
helpers => $asset->getHelpers,
};
$assetInfo->{ currentAsset } = $self->getAssetData( $asset );
$assetInfo->{ crumbtrail } = [];
for my $asset ( @{ $asset->getLineage( ['ancestors'], { returnObjects => 1 } ) } ) {
push @{ $assetInfo->{crumbtrail} }, {
title => $asset->getTitle,
url => $asset->getUrl
};
push @{ $assetInfo->{crumbtrail} }, $self->getAssetData( $asset );
}
$session->response->content_type( 'application/json' );
@ -708,24 +723,7 @@ sub www_searchAssets {
for my $result ( @{ $p->getPageData } ) {
my $assetId = $result->{assetId};
my $asset = WebGUI::Asset->newById( $session, $assetId );
# Populate the required fields to fill in
my %fields = (
assetId => $asset->getId,
url => $asset->getUrl,
lineage => $asset->lineage,
title => $asset->menuTitle,
revisionDate => $asset->revisionDate,
childCount => $asset->getChildCount,
assetSize => $asset->assetSize,
lockedBy => ($asset->isLockedBy ? $asset->lockedBy->username : ''),
canEdit => $asset->canEdit && $asset->canEditIfLocked,
helpers => $asset->getHelpers,
icon => $asset->getIcon('small'),
className => $asset->getName,
);
push @{ $assetInfo->{ assets } }, \%fields;
push @{ $assetInfo->{ assets } }, $self->getAssetData( $asset );
}
$assetInfo->{ totalAssets } = $p->getRowCount;

View file

@ -248,34 +248,15 @@ if ($self->session->user->isRegistered || $self->session->setting->get("preventP
}
# TODO: Figure out if user is still in the admin console
$var{'head.tags'} .= '<script type="text/javascript">';
my $asset = $session->asset;
# If user is in an operation, find the right asset
if ( !$asset && $session->form->get('op') ) {
$asset = WebGUI::Asset->newByUrl( $session );
}
if ( $asset ) {
my $i18n = WebGUI::International->new( $session );
my $assetName = $i18n->get( @{ $asset->assetName } );
my $assetDef = {
assetId => $asset->getId,
title => $asset->getTitle,
url => $asset->getUrl,
icon => $asset->getIcon(1),
type => $assetName,
helpers => $asset->getHelpers,
revisions => $asset->getRevisionDates,
};
$var{'head.tags'} .= sprintf <<'ADMINJS', JSON->new->encode( $assetDef );
if ( window.parent && window.parent.admin ) {
window.parent.admin.navigate( %s );
}
# Give the API jocks something to use
if ( $session->asset ) {
$var{'head.tags'} .= sprintf <<'ADMINJS', $session->asset->getId
<script type="text/javascript">
if ( typeof window.WG == "undefined" ) { window.WG = {} }
WG.currentAssetId = '%s';
</script>
ADMINJS
}
$var{'head.tags'} .= '</script>';
# Removing the newlines will probably annoy people.
# Perhaps turn it off under debug mode?