diff --git a/lib/WebGUI/Admin.pm b/lib/WebGUI/Admin.pm index 3cf077fc4..a0d2df007 100644 --- a/lib/WebGUI/Admin.pm +++ b/lib/WebGUI/Admin.pm @@ -656,10 +656,13 @@ sub www_processAssetHelper { my ( $form ) = $session->quick(qw{ form }); my $assetId = $form->get('assetId'); - my $class = $form->get('className'); - WebGUI::Pluggable::load( $class ); + my $helperId = $form->get('helperId'); my $asset = WebGUI::Asset->newById( $session, $assetId ); - return JSON->new->encode( $class->process( $asset ) ); + + my $class = $asset->getHelpers->{ $helperId }->{ className }; + WebGUI::Pluggable::load( $class ); + my $helper = $class->new( id => $helperId, session => $self->session ); + return JSON->new->encode( $helper->process( $asset ) ); } #---------------------------------------------------------------------- diff --git a/lib/WebGUI/Asset.pm b/lib/WebGUI/Asset.pm index e3e55b7c9..7110b84c6 100644 --- a/lib/WebGUI/Asset.pm +++ b/lib/WebGUI/Asset.pm @@ -1191,61 +1191,56 @@ sub getHelpers { my $session = $self->session; my ( $conf ) = $session->quick(qw{ config }); - my $default = [ - { - class => 'WebGUI::AssetHelper::ChangeUrl', + my $default = { + change_url => { + className => 'WebGUI::AssetHelper::ChangeUrl', label => 'Change URL', }, - { - class => 'WebGUI::AssetHelper::Copy', + copy => { + className => 'WebGUI::AssetHelper::Copy', label => 'Copy', }, - { - class => 'WebGUI::AssetHelper::CopyBranch', + copy_branch => { + className => 'WebGUI::AssetHelper::CopyBranch', label => 'Copy Branch', }, - { - class => 'WebGUI::AssetHelper::CreateShortcut', + shortcut => { + className => 'WebGUI::AssetHelper::CreateShortcut', label => 'Create Shortcut', }, - { - class => 'WebGUI::AssetHelper::Cut', + cut => { + className => 'WebGUI::AssetHelper::Cut', label => 'Cut', }, - { + edit => { url => $self->getUrl( 'func=edit' ), label => 'Edit', }, - { - class => 'WebGUI::AssetHelper::EditBranch', + edit_branch => { + className => 'WebGUI::AssetHelper::EditBranch', label => 'Edit Branch', }, - { - class => 'WebGUI::AssetHelper::ExportHtml', + export_html => { + className => 'WebGUI::AssetHelper::ExportHtml', label => 'Export As HTML', }, - { + view => { url => $self->getUrl( 'func=view' ), label => 'View', }, - { - class => 'WebGUI::AssetHelper::Lock', + lock => { + className => 'WebGUI::AssetHelper::Lock', label => 'Lock', }, - ]; + }; + # Merge additional helpers for this class from config + my $confHelpers = $conf->get('assets/' . $self->className . '/helpers') || {}; + $default = { %$default, %$confHelpers }; - # Get additional helpers for this class from config - my $confHelpers = $conf->get('assets/' . $self->className . '/helpers'); - # Merge on label - for my $helper ( @$confHelpers ) { + # Process macros in labels + for my $helper ( values %$default ) { WebGUI::Macro::process( \$helper->{label} ); - if ( my $replace = first { $_->{label} eq $helper->{label} } @$default ) { - $replace = $helper; # replace in the default arrayref - } - else { - push @$default, $helper; - } } return $default; diff --git a/lib/WebGUI/AssetHelper.pm b/lib/WebGUI/AssetHelper.pm index fc9c627c3..15a8fe5fd 100644 --- a/lib/WebGUI/AssetHelper.pm +++ b/lib/WebGUI/AssetHelper.pm @@ -23,7 +23,38 @@ the Admin Console. =head1 SYNOPSIS -Despite using OO style methods, there are no AssetHelper objects. This is simply to provide inheritance. + package MyHelper; + use base 'WebGUI::AssetHelper'; + + sub process { + my ( $self, $asset ) = @_; + # Do stuff + return { message => 'Done stuff!' }; + } + + sub www_doOtherStuff { + my ( $self, $asset ) = @_; + # Do other stuff + } + +=head1 ATTRIBUTES + +=cut + +use WebGUI::BestPractices; +use Moose; + +has 'session' => ( + is => 'ro', + required => 1, + isa => 'WebGUI::Session', +); + +has 'id' => ( + is => 'ro', + required => 1, + isa => 'Str', +); =head1 METHODS @@ -33,16 +64,12 @@ These methods are available from this class: #------------------------------------------------------------------- -=head2 process ( $class, $asset ) +=head2 process ( $asset ) -This is a class method. Process is the default method called by the Asset Helper content handler. +Process is the default method called by the Admin Console. It returns a hashref, that is converted by the content handler to JSON to be passed back to the Admin Console. -=head3 $class - -The name of the class this method was called as. - =head3 $asset A WebGUI::Asset object. @@ -82,14 +109,14 @@ An array reference of arguments that, when used with C, will be pa =cut sub process { - my ($class, $asset) = @_; + my ($self, $asset) = @_; ##This method can do work, or it can delegate out to other methods. return { error => q{User, we have a problem.}, message => q{A friendly informational method}, - open_tab => '?op=assetHelper;className=WebGUI::AssetHelper;method=editBranch', + open_tab => '?op=assetHelper;helperId=' . $self->id . ';method=editBranch', redirect => '/home', scriptFile => q{URL}, scriptMethod => q{methodName}, diff --git a/lib/WebGUI/AssetHelper/ChangeUrl.pm b/lib/WebGUI/AssetHelper/ChangeUrl.pm index 141b33c75..bbc0be014 100644 --- a/lib/WebGUI/AssetHelper/ChangeUrl.pm +++ b/lib/WebGUI/AssetHelper/ChangeUrl.pm @@ -34,14 +34,14 @@ These methods are available from this class: #------------------------------------------------------------------- -=head2 process ( $class, $asset ) +=head2 process ( $asset ) Opens a new tab for displaying the form to change the Asset's URL. =cut sub process { - my ($class, $asset) = @_; + my ($self, $asset) = @_; my $session = $asset->session; my $i18n = WebGUI::International->new($session, "Asset"); if (! $asset->canEdit) { @@ -51,20 +51,20 @@ sub process { } return { - openDialog => $asset->getUrl('op=assetHelper;className=WebGUI::AssetHelper::ChangeUrl;method=changeUrl;assetId=' . $asset->getId ), + openDialog => $asset->getUrl('op=assetHelper;helperId=' . $self->id . ';method=changeUrl;assetId=' . $asset->getId ), }; } #------------------------------------------------------------------- -=head2 www_changeUrl ( $class, $asset ) +=head2 www_changeUrl ( $asset ) Displays a form to change the URL for this asset. =cut sub www_changeUrl { - my ($class, $asset) = @_; + my ($self, $asset) = @_; my $session = $asset->session; my $i18n = WebGUI::International->new($session, "Asset"); if (! $asset->canEdit) { @@ -74,7 +74,7 @@ sub www_changeUrl { } my $f = WebGUI::FormBuilder->new($session, method => 'POST', action => $asset->getUrl ); $f->addField( "hidden", name => 'op', value => 'assetHelper' ); - $f->addField( "hidden", name => 'className', value => $class ); + $f->addField( "hidden", name => 'helperId', value => $self->id ); $f->addField( "hidden", name => "method", value=>"changeUrlSave" ); $f->addField( "hidden", name => 'assetId', value => $asset->getId ); $f->addField( "text", @@ -103,7 +103,7 @@ This actually does the change url of the www_changeUrl() function. =cut sub www_changeUrlSave { - my ($class, $asset) = @_; + my ($self, $asset) = @_; my $session = $asset->session; my $i18n = WebGUI::International->new($session, "Asset"); if (! $asset->canEdit) { diff --git a/lib/WebGUI/AssetHelper/Copy.pm b/lib/WebGUI/AssetHelper/Copy.pm index ea67630ac..f5f894737 100644 --- a/lib/WebGUI/AssetHelper/Copy.pm +++ b/lib/WebGUI/AssetHelper/Copy.pm @@ -32,30 +32,30 @@ These methods are available from this class: #------------------------------------------------------------------- -=head2 process ( $class, $asset ) +=head2 process ( $asset ) Open a progress dialog for the copy operation =cut sub process { - my ($class, $asset) = @_; + my ($self, $asset) = @_; return { - openDialog => '?op=assetHelper;className=' . $class . ';method=copy;assetId=' . $asset->getId, + openDialog => '?op=assetHelper;helperId=' . $self->id . ';method=copy;assetId=' . $asset->getId, }; } #---------------------------------------------------------------------------- -=head2 www_copy ( $class, $asset ) +=head2 www_copy ( $asset ) Perform the copy operation, showing the progress. =cut sub www_copy { - my ( $class, $asset ) = @_; + my ( $self, $asset ) = @_; my $session = $asset->session; my $i18n = WebGUI::International->new($session, 'Asset'); diff --git a/lib/WebGUI/AssetHelper/CopyBranch.pm b/lib/WebGUI/AssetHelper/CopyBranch.pm index 1d48189c5..e9dd7e896 100644 --- a/lib/WebGUI/AssetHelper/CopyBranch.pm +++ b/lib/WebGUI/AssetHelper/CopyBranch.pm @@ -32,36 +32,36 @@ These methods are available from this class: #------------------------------------------------------------------- -=head2 process ( $class, $asset ) +=head2 process ( $asset ) Open a progress dialog for the copy operation =cut sub process { - my ($class, $asset) = @_; + my ($self, $asset) = @_; return { - openDialog => '?op=assetHelper;className=' . $class . ';method=getWith;assetId=' . $asset->getId + openDialog => '?op=assetHelper;helperId=' . $self->id . ';method=getWith;assetId=' . $asset->getId }; } #---------------------------------------------------------------------------- -=head2 www_getWith ( $class, $asset ) +=head2 www_getWith ( $asset ) Get the "with" configuration. "Descendants" or "Children". =cut sub www_getWith { - my ( $class, $asset ) = @_; + my ( $self, $asset ) = @_; my $session = $asset->session; my $i18n = WebGUI::International->new($session, 'Asset'); return '
' . '' - . '' + . '' . '' . '' . '' @@ -73,14 +73,14 @@ sub www_getWith { #---------------------------------------------------------------------------- -=head2 www_copy ( $class, $asset ) +=head2 www_copy ( $asset ) Perform the copy operation, showing the progress. =cut sub www_copy { - my ($class, $asset) = @_; + my ($self, $asset) = @_; my $session = $asset->session; $asset->forkWithStatusPage({ diff --git a/lib/WebGUI/AssetHelper/CreateShortcut.pm b/lib/WebGUI/AssetHelper/CreateShortcut.pm index 2de7a4923..756e7d8d1 100644 --- a/lib/WebGUI/AssetHelper/CreateShortcut.pm +++ b/lib/WebGUI/AssetHelper/CreateShortcut.pm @@ -32,14 +32,14 @@ These methods are available from this class: #------------------------------------------------------------------- -=head2 process ( $class, $asset ) +=head2 process ( $asset ) Create a shortcut to the asset on the clipboard. =cut sub process { - my ($class, $asset) = @_; + my ($self, $asset) = @_; my $session = $asset->session; my $i18n = WebGUI::International->new( $session, 'WebGUI' ); diff --git a/lib/WebGUI/AssetHelper/Cut.pm b/lib/WebGUI/AssetHelper/Cut.pm index 4bf161370..10c8e7533 100644 --- a/lib/WebGUI/AssetHelper/Cut.pm +++ b/lib/WebGUI/AssetHelper/Cut.pm @@ -32,7 +32,7 @@ These methods are available from this class: #------------------------------------------------------------------- -=head2 process ( $class, $asset ) +=head2 process ( $asset ) Cuts the asset to the clipboard. If the user cannot edit the asset, or the asset is a system asset, it returns an error message. @@ -40,7 +40,7 @@ system asset, it returns an error message. =cut sub process { - my ($class, $asset) = @_; + my ($self, $asset) = @_; my $session = $asset->session; my $i18n = WebGUI::International->new($session, 'WebGUI'); @@ -52,20 +52,20 @@ sub process { } return { - openDialog => '?op=assetHelper;className=' . $class . ';method=cut;assetId=' . $asset->getId, + openDialog => '?op=assetHelper;helperId=' . $self->id . ';method=cut;assetId=' . $asset->getId, }; } #---------------------------------------------------------------------------- -=head2 www_cut ( $class, $asset ) +=head2 www_cut ( $asset ) Show the progress bar while cutting the asset. =cut sub www_cut { - my ( $class, $asset ) = @_; + my ( $self, $asset ) = @_; my $session = $asset->session; my $i18n = WebGUI::International->new($session, 'Asset'); diff --git a/lib/WebGUI/AssetHelper/EditBranch.pm b/lib/WebGUI/AssetHelper/EditBranch.pm index 30d6935f2..b9310bece 100644 --- a/lib/WebGUI/AssetHelper/EditBranch.pm +++ b/lib/WebGUI/AssetHelper/EditBranch.pm @@ -64,7 +64,7 @@ Creates a tabform to edit the Asset Tree. If canEdit returns False, returns insu =cut sub www_editBranch { - my ($class, $asset) = @_; + my ($self, $asset) = @_; my $session = $asset->session; my ( $style, $url ) = $session->quick( qw( style url ) ); $style->setCss( $url->extras('hoverhelp.css')); @@ -84,7 +84,7 @@ ENDHTML my $change = '
'.$i18n->get("change") . ' '; my $tabform = WebGUI::TabForm->new($session); $tabform->hidden({name=>"op",value=>"assetHelper"}); - $tabform->hidden({name=>"className",value=>$class}); + $tabform->hidden({name=>"helperId",value=>$self->id}); $tabform->hidden({name=>"method",value=>"editBranchSave"}); $tabform->hidden({name=>"assetId",value=>$asset->getId}); $tabform->addTab("properties",$i18n->get("properties"),9); @@ -312,7 +312,7 @@ Verifies proper inputs in the Asset Tree and saves them. Returns ManageAssets me =cut sub www_editBranchSave { - my ($class, $asset) = @_; + my ($self, $asset) = @_; my $session = $asset->session; return $session->privilege->insufficient() unless ($asset->canEdit && $session->user->isInGroup('4')); my $form = $session->form; diff --git a/lib/WebGUI/AssetHelper/ExportHtml.pm b/lib/WebGUI/AssetHelper/ExportHtml.pm index f55b16531..819861e72 100644 --- a/lib/WebGUI/AssetHelper/ExportHtml.pm +++ b/lib/WebGUI/AssetHelper/ExportHtml.pm @@ -34,14 +34,14 @@ These methods are available from this class: #------------------------------------------------------------------- -=head2 process ( $class, $asset ) +=head2 process ( $asset ) Opens a new tab for displaying the form and the output for exporting a branch. =cut sub process { - my ($class, $asset) = @_; + my ($self, $asset) = @_; my $session = $asset->session; my $i18n = WebGUI::International->new($session, "Asset"); if (! $asset->canEdit) { @@ -51,7 +51,7 @@ sub process { } return { - openDialog => '?op=assetHelper;className=' . $class . ';method=export;assetId=' . $asset->getId, + openDialog => '?op=assetHelper;helperId=' . $self->id . ';method=export;assetId=' . $asset->getId, }; } @@ -64,7 +64,7 @@ Displays the export page administrative interface =cut sub www_export { - my ($class, $asset) = @_; + my ($self, $asset) = @_; my $session = $asset->session; return $session->privilege->insufficient() unless ($session->user->isInGroup(13)); my ( $style, $url ) = $session->quick(qw{ style url }); @@ -81,7 +81,7 @@ ENDHTML my $i18n = WebGUI::International->new($session, "Asset"); my $f = WebGUI::FormBuilder->new($session, action => $asset->getUrl); $f->addField( "hidden", name => 'op', value => 'assetHelper' ); - $f->addField( "hidden", name => 'className', value => $class ); + $f->addField( "hidden", name => 'helperId', value => $self->id ); $f->addField( "hidden", name => 'assetId', value => $asset->getId ); $f->addField( "hidden", name => "method", @@ -155,7 +155,7 @@ Displays the export status page =cut sub www_exportStatus { - my ($class, $asset) = @_; + my ($self, $asset) = @_; my $session = $asset->session; return $session->privilege->insufficient unless $session->user->isInGroup(13); diff --git a/lib/WebGUI/AssetHelper/Lock.pm b/lib/WebGUI/AssetHelper/Lock.pm index fe65e7bf9..898bf3c14 100644 --- a/lib/WebGUI/AssetHelper/Lock.pm +++ b/lib/WebGUI/AssetHelper/Lock.pm @@ -33,7 +33,7 @@ These methods are available from this class: #------------------------------------------------------------------- -=head2 process ( $class, $asset ) +=head2 process ( $asset ) Locks the asset with a version tag. If the user cannot edit the asset, or the asset is already locked, it returns an error message. @@ -41,7 +41,7 @@ already locked, it returns an error message. =cut sub process { - my ($class, $asset) = @_; + my ($self, $asset) = @_; my $session = $asset->session; my $i18n = WebGUI::International->new($session, 'Asset'); diff --git a/lib/WebGUI/Content/Admin.pm b/lib/WebGUI/Content/Admin.pm index 4aef62c12..4101d8c62 100644 --- a/lib/WebGUI/Content/Admin.pm +++ b/lib/WebGUI/Content/Admin.pm @@ -83,14 +83,20 @@ sub handler { if ( $session->form->get("op") eq "assetHelper" ) { # Load and run the requested asset helper www_ method - my $class = $session->form->get('className'); - WebGUI::Pluggable::load( $class ); - my $method = $session->form->get('method') || "view"; my $assetId = $session->form->get('assetId'); my $asset = WebGUI::Asset->newById( $session, $assetId ); - if ( $class->can( "www_" . $method ) ) { - return $class->can( "www_" . $method )->( $class, $asset ); + my $helperId = $session->form->get('helperId'); + my $class = $asset->getHelpers->{ $helperId }->{ className }; + WebGUI::Pluggable::load( $class ); + my $helper = $class->new( id => $helperId, session => $session ); + + my $method = $session->form->get('method') || "view"; + if ( $helper->can( "www_" . $method ) ) { + return $helper->can( "www_" . $method )->( $helper, $asset ); + } + else { + $session->log->error( sprintf 'Invalid asset helper "%s" calling method "%s"', $helperId, $method ); } } diff --git a/t/Admin.t b/t/Admin.t index aa4b7b0a2..e00eab75d 100644 --- a/t/Admin.t +++ b/t/Admin.t @@ -81,10 +81,10 @@ $mech->get('/'); # Start a session $mech->session->user({ userId => '3' }); # www_processAssetHelper -$mech->get_ok( '/?op=admin;method=processAssetHelper;className=WebGUI::AssetHelper::Cut;assetId=' . $snip->getId ); +$mech->get_ok( '/?op=admin;method=processAssetHelper;helperId=cut;assetId=' . $snip->getId ); cmp_deeply( JSON->new->decode( $mech->content ), - WebGUI::AssetHelper::Cut->process( $snip ), + WebGUI::AssetHelper::Cut->new( id => 'cut', session => $session )->process( $snip ), 'www_processAssetHelper', ); diff --git a/t/AssetHelper/ChangeUrl.t b/t/AssetHelper/ChangeUrl.t index 324f3e479..26e23d22c 100644 --- a/t/AssetHelper/ChangeUrl.t +++ b/t/AssetHelper/ChangeUrl.t @@ -35,9 +35,10 @@ my $asset = WebGUI::Test->asset->addChild( { #---------------------------------------------------------------------------- # Check permissions +my $helper = WebGUI::AssetHelper::ChangeUrl->new( id => 'change_url', session => $session ); $session->user({ userId => 1 }); -my $output = WebGUI::AssetHelper::ChangeUrl->process( $asset ); +my $output = $helper->process( $asset ); ok( $output->{error}, "Errors on bad permissions" ); @@ -45,7 +46,7 @@ ok( $output->{error}, "Errors on bad permissions" ); # Change URL! $session->user({ userId => 3 }); # By the power of grayskull! -my $output = WebGUI::AssetHelper::ChangeUrl->process( $asset ); +my $output = $helper->process( $asset ); cmp_deeply( $output, { openDialog => all( re( 'method=changeUrl' ), diff --git a/t/AssetHelper/Copy.t b/t/AssetHelper/Copy.t index b2c66e8cc..f6267125a 100644 --- a/t/AssetHelper/Copy.t +++ b/t/AssetHelper/Copy.t @@ -36,16 +36,18 @@ plan tests => 3; # Increment this number for each test you create # put your tests here my $output; +my $helper = WebGUI::AssetHelper::Copy->new( id => 'copy', session => $session ); my $home = WebGUI::Asset->getDefault($session); my $root = WebGUI::Asset->getRoot($session); { - $output = WebGUI::AssetHelper::Copy->process($home); + $output = $helper->process($home); cmp_deeply( $output, { openDialog => all( + re('helperId=copy'), re('method=copy'), re('assetId=' . $home->getId ), ), @@ -55,7 +57,7 @@ my $root = WebGUI::Asset->getRoot($session); } my $mech = WebGUI::Test::Mechanize->new( config => WebGUI::Test->file ); -$mech->get_ok( '/?op=assetHelper;className=WebGUI::AssetHelper::Copy;method=copy;assetId=' . $home->getId ); +$mech->get_ok( '/?op=assetHelper;helperId=copy;method=copy;assetId=' . $home->getId ); my $clippies = $root->getLineage(["descendants"], {statesToInclude => [qw{clipboard clipboard-limbo}], returnObjects => 1,}); is @{ $clippies }, 1, '... only copied 1 asset to the clipboard, no children'; diff --git a/t/AssetHelper/CopyBranch.t b/t/AssetHelper/CopyBranch.t index b37ce6d9f..8e69179f6 100644 --- a/t/AssetHelper/CopyBranch.t +++ b/t/AssetHelper/CopyBranch.t @@ -36,6 +36,7 @@ plan tests => 5; # Increment this number for each test you create # put your tests here my $output; +my $helper = WebGUI::AssetHelper::CopyBranch->new( id => 'copy_branch', session => $session ); my $node = WebGUI::Asset->getImportNode($session); my $root = WebGUI::Asset->getRoot( $session ); my $tag = WebGUI::VersionTag->getWorking( $session ); @@ -60,11 +61,12 @@ addToCleanup( $tag ); { - $output = WebGUI::AssetHelper::CopyBranch->process($top); + $output = $helper->process($top); cmp_deeply( $output, { openDialog => all( + re('helperId=copy_branch'), re('method=getWith'), re('assetId=' . $top->getId ), ), @@ -74,7 +76,7 @@ addToCleanup( $tag ); } my $mech = WebGUI::Test::Mechanize->new( config => WebGUI::Test->file ); -$mech->get_ok( '/?op=assetHelper;className=WebGUI::AssetHelper::CopyBranch;method=copy;with=children;assetId=' . $top->getId ); +$mech->get_ok( '/?op=assetHelper;helperId=copy_branch;method=copy;with=children;assetId=' . $top->getId ); WebGUI::Test->waitForAllForks; my $clippies = $root->getLineage(["descendants"], {statesToInclude => [qw{clipboard clipboard-limbo}], returnObjects => 1,}); @@ -83,7 +85,7 @@ for my $asset ( @$clippies ) { $asset->purge; } -$mech->get_ok( '/?op=assetHelper;className=WebGUI::AssetHelper::CopyBranch;method=copy;with=descendants;assetId=' . $top->getId ); +$mech->get_ok( '/?op=assetHelper;helperId=copy_branch;method=copy;with=descendants;assetId=' . $top->getId ); WebGUI::Test->waitForAllForks; my $clippies = $root->getLineage(["descendants"], {statesToInclude => [qw{clipboard clipboard-limbo}], returnObjects => 1,}); is @{ $clippies }, 3, '... copied 3 asset to the clipboard'; diff --git a/t/AssetHelper/CreateShortcut.t b/t/AssetHelper/CreateShortcut.t index 904de43c4..c628418b5 100644 --- a/t/AssetHelper/CreateShortcut.t +++ b/t/AssetHelper/CreateShortcut.t @@ -31,11 +31,12 @@ my $session = WebGUI::Test->session; # Tests my $output; +my $helper = WebGUI::AssetHelper::CreateShortcut->new( id => 'shortcut', session => $session ); my $import = WebGUI::Asset->getImportNode($session); my $priv_page = WebGUI::Test->asset( groupIdView => '3' ); $session->user({userId => 1}); -$output = WebGUI::AssetHelper::CreateShortcut->process($priv_page); +$output = $helper->process($priv_page); cmp_deeply( $output, { @@ -48,7 +49,7 @@ $session->setting->set( versionTagMode => 'autoCommit' ); $session->setting->set( skipCommitComments => '1' ); $session->user({userId => 3}); my $safe_page = WebGUI::Test->asset; -$output = WebGUI::AssetHelper::CreateShortcut->process($safe_page); +$output = $helper->process($safe_page); cmp_deeply( $output, { diff --git a/t/AssetHelper/Cut.t b/t/AssetHelper/Cut.t index d13c9f720..27cc3c1c0 100644 --- a/t/AssetHelper/Cut.t +++ b/t/AssetHelper/Cut.t @@ -31,10 +31,11 @@ my $session = WebGUI::Test->session; # Tests my $output; +my $helper = WebGUI::AssetHelper::Cut->new( id => 'cut', session => $session ); my $import = WebGUI::Asset->getImportNode($session); $session->user({userId => 1}); -$output = WebGUI::AssetHelper::Cut->process($import); +$output = $helper->process($import); cmp_deeply( $output, { @@ -44,7 +45,7 @@ cmp_deeply( ); $session->user({userId => 3}); -$output = WebGUI::AssetHelper::Cut->process($import); +$output = $helper->process($import); cmp_deeply( $output, { @@ -54,7 +55,7 @@ cmp_deeply( ); my $safe_page = $import->getFirstChild; -$output = WebGUI::AssetHelper::Cut->process($safe_page); +$output = $helper->process($safe_page); cmp_deeply( $output, { diff --git a/t/AssetHelper/EditBranch.t b/t/AssetHelper/EditBranch.t index 1a56f198d..0dc3f0476 100644 --- a/t/AssetHelper/EditBranch.t +++ b/t/AssetHelper/EditBranch.t @@ -31,6 +31,7 @@ my $session = WebGUI::Test->session; # Tests my $output; +my $helper = WebGUI::AssetHelper::EditBranch->new( id => 'edit_branch', session => $session ); my $node = WebGUI::Asset->getImportNode($session); my $root = WebGUI::Asset->getRoot( $session ); my $top = $node->addChild({ @@ -54,7 +55,7 @@ WebGUI::Test->addToCleanup( $top, $child, $grand ); { - $output = WebGUI::AssetHelper::EditBranch->process($top); + $output = $helper->process($top); cmp_deeply( $output, { @@ -70,7 +71,7 @@ WebGUI::Test->addToCleanup( $top, $child, $grand ); my $mech = WebGUI::Test::Mechanize->new( config => WebGUI::Test->file ); $mech->get('/'); $mech->session->user({ userId => 3 }); -$mech->get_ok( '/?op=assetHelper;className=WebGUI::AssetHelper::EditBranch;method=editBranch;assetId=' . $top->getId ); +$mech->get_ok( '/?op=assetHelper;helperId=edit_branch;method=editBranch;assetId=' . $top->getId ); $mech->submit_form_ok({ fields => { ownerUserId => '3', diff --git a/t/AssetHelper/ExportHtml.t b/t/AssetHelper/ExportHtml.t index f7163959e..d8a73afb3 100644 --- a/t/AssetHelper/ExportHtml.t +++ b/t/AssetHelper/ExportHtml.t @@ -30,6 +30,7 @@ my $session = WebGUI::Test->session; $session->user({ userId => 3 }); my $output; +my $helper = WebGUI::AssetHelper::ExportHtml->new( id => 'export_html', session => $session ); my $node = WebGUI::Asset->getImportNode($session); my $root = WebGUI::Asset->getRoot( $session ); my $top = $node->addChild({ @@ -62,7 +63,7 @@ WebGUI::Test->config->set( "exportPath" => $dir->dirname ); { - $output = WebGUI::AssetHelper::ExportHtml->process($top); + $output = $helper->process($top); cmp_deeply( $output, { @@ -78,7 +79,7 @@ WebGUI::Test->config->set( "exportPath" => $dir->dirname ); my $mech = WebGUI::Test::Mechanize->new( config => WebGUI::Test->file ); $mech->get('/'); $mech->session->user({ userId => 3 }); -$mech->get_ok( '/?op=assetHelper;className=WebGUI::AssetHelper::ExportHtml;method=export;assetId=' . $top->getId ); +$mech->get_ok( '/?op=assetHelper;helperId=export_html;method=export;assetId=' . $top->getId ); $mech->submit_form_ok({ fields => { }, diff --git a/t/AssetHelper/Lock.t b/t/AssetHelper/Lock.t index d05d525e9..94be523ed 100644 --- a/t/AssetHelper/Lock.t +++ b/t/AssetHelper/Lock.t @@ -45,8 +45,9 @@ my $newPage = $home->addChild({ $newPage = WebGUI::Asset->newById($session, $newPage->assetId); +my $helper = WebGUI::AssetHelper::Lock->new( id => 'lock', session => $session ); $session->user({userId => 1}); -$output = WebGUI::AssetHelper::Lock->process($newPage); +$output = $helper->process($newPage); cmp_deeply( $output, { @@ -56,7 +57,7 @@ cmp_deeply( ); $session->user({userId => 3}); -$output = WebGUI::AssetHelper::Lock->process($newPage); +$output = $helper->process($newPage); cmp_deeply( $output, { @@ -70,7 +71,7 @@ ok $newPage->isLocked, 'Asset is locked, and ready for next test'; is $newPage->getRevisionCount, 2, 'new revision added'; $session->user({userId => $editor->getId}); -$output = WebGUI::AssetHelper::Lock->process($newPage); +$output = $helper->process($newPage); cmp_deeply( $output, { diff --git a/www/extras/admin/admin.js b/www/extras/admin/admin.js index 25aa47a7e..174c8207b 100644 --- a/www/extras/admin/admin.js +++ b/www/extras/admin/admin.js @@ -454,28 +454,28 @@ WebGUI.Admin.prototype.updateAssetHelpers } // Add new ones - for ( var i = 0; i < assetDef.helpers.length; i++ ) { - var helper = assetDef.helpers[i]; + for ( var helperId in assetDef.helpers ) { + var helper = assetDef.helpers[helperId]; var li = document.createElement('li'); li.className = "clickable with_icon"; li.appendChild( document.createTextNode( helper.label ) ); - this.addHelperHandler( li, helper ); + this.addHelperHandler( li, helperId, helper ); helperEl.appendChild( li ); } }; /** - * addHelperHandler( elem, helper ) + * addHelperHandler( elem, helperId, helper ) * Add the click handler to activate the given helper */ WebGUI.Admin.prototype.addHelperHandler -= function ( elem, helper ) { += function ( elem, helperId, helper ) { var self = this; if ( helper.url ) { YAHOO.util.Event.on( elem, "click", function(){ self.gotoAsset( helper.url ) }, self, true ); } - else if ( helper['class'] ) { - YAHOO.util.Event.on( elem, "click", function(){ self.requestHelper( helper['class'], self.currentAssetDef.assetId ) }, self, true ); + else { + YAHOO.util.Event.on( elem, "click", function(){ self.requestHelper( helperId, self.currentAssetDef.assetId ) }, self, true ); } }; @@ -535,7 +535,7 @@ WebGUI.Admin.prototype.requestUpdateCurrentVersionTag * Request the Asset Helper for the given assetId */ WebGUI.Admin.prototype.requestHelper -= function ( helperClass, assetId ) { += function ( helperId, assetId ) { var callback = { success : function (o) { var resp = YAHOO.lang.JSON.parse( o.responseText ); @@ -547,7 +547,7 @@ WebGUI.Admin.prototype.requestHelper scope: this }; - var url = '?op=admin;method=processAssetHelper;className=' + helperClass + ';assetId=' + assetId; + var url = '?op=admin;method=processAssetHelper;helperId=' + helperId + ';assetId=' + assetId; var ajax = YAHOO.util.Connect.asyncRequest( 'GET', url, callback ); };