add "asset" property to AssetHelpers.

Simplifies the API and allows us to have getForm and getUrl to make
asset helpers easier to build.
This commit is contained in:
Doug Bell 2011-03-25 14:49:44 -05:00
parent df31c13e13
commit 698f40a6dd
23 changed files with 216 additions and 123 deletions

View file

@ -56,6 +56,12 @@ has 'id' => (
isa => 'Str',
);
has 'asset' => (
is => 'ro',
required => 1,
isa => 'WebGUI::Asset',
);
=head1 METHODS
These methods are available from this class:
@ -64,6 +70,47 @@ These methods are available from this class:
#-------------------------------------------------------------------
=head2 getForm ( $method )
Get a WebGUI::FormBuilder that submits to the given www_ $method.
=cut
sub getForm {
my ( $self, $method ) = @_;
my $f = WebGUI::FormBuilder->new( $self->session, action => $self->session->url->page );
$f->addField( 'hidden', name => 'op', value => 'assetHelper' );
$f->addField( 'hidden', name => 'helperId', value => $self->id );
$f->addField( 'hidden', name => 'method', value => $method );
$f->addField( 'hidden', name => 'assetId', value => $self->asset->assetId );
return $f;
}
#-------------------------------------------------------------------
=head2 getUrl ( $method, $pairs )
Get a URL to call the www_ method of this Asset Helper. $method is the name
of the method, without the www_. $pairs is a string of name=value; pairs to
add to the URL.
=cut
sub getUrl {
my ( $self, $method, $pairs ) = @_;
$method ||= 'view';
$pairs ||= '';
return $self->asset->getUrl(
'op=assetHelper;assetId=' . $self->asset->assetId . ';helperId=' . $self->id
. ';method=' . $method . ';' . $pairs
);
}
#-------------------------------------------------------------------
=head2 process ( $asset )
Process is the default method called by the Admin Console.