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:
parent
eec3986cf7
commit
f5ebb6e916
3 changed files with 116 additions and 99 deletions
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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?
|
||||
|
|
|
|||
|
|
@ -11,9 +11,11 @@ if ( typeof WebGUI == "undefined" ) {
|
|||
WebGUI = {};
|
||||
}
|
||||
WebGUI.Admin = function(cfg){
|
||||
var self = this;
|
||||
// Public properties
|
||||
this.cfg = cfg;
|
||||
this.currentAssetDef = null;
|
||||
this.currentAssetId = "";
|
||||
this.currentTab = "view"; // "view" or "tree" or other ID
|
||||
this.treeDirty = true;
|
||||
|
||||
|
|
@ -37,8 +39,20 @@ WebGUI.Admin = function(cfg){
|
|||
// Custom events
|
||||
this.afterNavigate = new YAHOO.util.CustomEvent( "afterNavigate", this );
|
||||
|
||||
// Keep track of the view iframe
|
||||
var viewframe = document.getElementById('adminViewFrame');
|
||||
// If it already loaded, run the right function
|
||||
if ( viewframe.hasLoaded && window.frames[viewframe.name].WG ) {
|
||||
this.navigate( window.frames[viewframe.name].WG.currentAssetId );
|
||||
}
|
||||
// Next and every subsequent time it loads, run the right function again
|
||||
YAHOO.util.Event.on( viewframe, 'load', function(){
|
||||
if ( window.frames[viewframe.name].WG ) {
|
||||
self.navigate( window.frames[viewframe.name].WG.currentAssetId );
|
||||
}
|
||||
} );
|
||||
|
||||
// Private methods
|
||||
var self = this;
|
||||
// Initialize these things AFTER the i18n is fetched
|
||||
var _init = function () {
|
||||
self.afterNavigate.subscribe( self.requestUpdateCurrentVersionTag, self );
|
||||
|
|
@ -60,10 +74,6 @@ WebGUI.Admin = function(cfg){
|
|||
homeUrl : self.cfg.homeUrl
|
||||
} );
|
||||
self.afterNavigate.subscribe( self.locationBar.afterNavigate, self.locationBar );
|
||||
if ( self.currentAssetDef ) {
|
||||
self.locationBar.navigate( self.currentAssetDef );
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
// Get I18N
|
||||
|
|
@ -245,23 +255,51 @@ WebGUI.Admin.prototype.makeGotoAsset
|
|||
* page is reached
|
||||
*/
|
||||
WebGUI.Admin.prototype.navigate
|
||||
= function ( assetDef ) {
|
||||
= function ( assetId ) {
|
||||
// Don't do the same asset twice
|
||||
if ( this.currentAssetDef && this.currentAssetDef.assetId == assetDef.assetId ) {
|
||||
if ( this.currentAssetId && this.currentAssetId == assetId ) {
|
||||
// But still fire the event
|
||||
this.afterNavigate.fire( assetDef );
|
||||
this.afterNavigate.fire( this.currentAssetDef );
|
||||
return;
|
||||
}
|
||||
|
||||
if ( !this.currentAssetDef || this.currentAssetDef.assetId != assetDef.assetId ) {
|
||||
this.currentAssetDef = assetDef;
|
||||
this.treeDirty = 1;
|
||||
this.updateAssetHelpers( assetDef );
|
||||
this.updateAssetHistory( assetDef );
|
||||
}
|
||||
if ( !this.currentAssetId || this.currentAssetId != assetId ) {
|
||||
// request asset update
|
||||
this.currentAssetId = assetId;
|
||||
var self = this;
|
||||
this.requestAssetDef( assetId, function( assetDef ) {
|
||||
self.currentAssetDef = assetDef;
|
||||
self.treeDirty = 1;
|
||||
self.updateAssetHelpers( assetDef );
|
||||
self.updateAssetHistory( assetDef );
|
||||
|
||||
// Fire event
|
||||
this.afterNavigate.fire( assetDef );
|
||||
// Fire event
|
||||
this.afterNavigate.fire( assetDef );
|
||||
} );
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* requestAssetDef( assetId, callback )
|
||||
* Request more information about an asset. The callback takes a single
|
||||
* argument which is an object containing the asset information and is
|
||||
* called in the scope of the admin function
|
||||
*/
|
||||
WebGUI.Admin.prototype.requestAssetDef
|
||||
= function ( assetId, callback ) {
|
||||
var connectCallback = {
|
||||
success : function (o) {
|
||||
var assetDef = YAHOO.lang.JSON.parse( o.responseText );
|
||||
callback.call( this, assetDef );
|
||||
},
|
||||
failure : function (o) {
|
||||
|
||||
},
|
||||
scope: this
|
||||
};
|
||||
|
||||
var url = '?op=admin;method=getAssetData;assetId=' + assetId;
|
||||
var ajax = YAHOO.util.Connect.asyncRequest( 'GET', url, connectCallback );
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
@ -447,7 +485,7 @@ WebGUI.Admin.prototype.updateAssetHelpers
|
|||
= function ( assetDef ) {
|
||||
var typeEl = document.getElementById( 'helper_asset_name' );
|
||||
typeEl.style.backgroundImage = 'url(' + assetDef.icon + ')';
|
||||
typeEl.innerHTML = assetDef.type;
|
||||
typeEl.innerHTML = assetDef.className;
|
||||
|
||||
// Clear old helpers
|
||||
var helperEl = document.getElementById( 'helper_list' );
|
||||
|
|
@ -477,7 +515,7 @@ WebGUI.Admin.prototype.addHelperHandler
|
|||
YAHOO.util.Event.on( elem, "click", function(){ self.gotoAsset( helper.url ) }, self, true );
|
||||
}
|
||||
else {
|
||||
YAHOO.util.Event.on( elem, "click", function(){ self.requestHelper( helperId, self.currentAssetDef.assetId ) }, self, true );
|
||||
YAHOO.util.Event.on( elem, "click", function(){ self.requestHelper( helperId, self.currentAssetId ) }, self, true );
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue