Fixed bug where Template form plugin would not show anything for getValueAsHtml.

This commit is contained in:
martin 2010-06-04 11:54:36 +00:00
parent 053292a75b
commit 73c762d6f1
3 changed files with 143 additions and 29 deletions

View file

@ -2,6 +2,7 @@
- fixed #11596: Calendar: all day events leaking
- fixed #11604: scheduled workflows getting deleted
- added API method commitAsUser allowing developers to commit version tags as other users
- fixed: The template form plugin would return an empty string when getValueAsHtml was called. ( Martin Kamerbeek / Oqapi )
7.9.6
- new checkbox in the asset manager for clearing the package flag on import

View file

@ -78,23 +78,23 @@ If true, this will limit the list of template to only include templates that are
=cut
sub definition {
my $class = shift;
my $session = shift;
my $definition = shift || [];
my $i18n = WebGUI::International->new($session, 'Asset_Template');
push(@{$definition}, {
label=>{
defaultValue=>$i18n->get("assetName")
},
name=>{
defaultValue=>"templateId"
},
namespace=>{
defaultValue=>undef
},
onlyCommitted=>{
defaultValue=>''
},
my $class = shift;
my $session = shift;
my $definition = shift || [];
my $i18n = WebGUI::International->new($session, 'Asset_Template');
push(@{$definition}, {
label=>{
defaultValue=>$i18n->get("assetName")
},
name=>{
defaultValue=>"templateId"
},
namespace=>{
defaultValue=>undef
},
onlyCommitted=>{
defaultValue=>''
},
});
return $class->SUPER::definition($session, $definition);
}
@ -138,6 +138,54 @@ sub isDynamicCompatible {
#-------------------------------------------------------------------
=head2 getValueAsHtml ( )
Returns the tempalte name of the selected template.
=cut
sub getValueAsHtml {
my $self = shift;
$self->setOptions;
return $self->SUPER::getValueAsHtml;
}
#-------------------------------------------------------------------
=head2 setOptions
Fills the options of the select list with the appropriate templates.
=cut
sub setOptions {
my $self = shift;
my $session = $self->session;
my $userId = $session->user->userId;
my $onlyCommitted = $self->get( 'onlyCommitted' )
? q{assetData.status='approved'}
: $self->get( 'onlyCommitted' )
;
my $templateList = WebGUI::Asset::Template->getList( $session, $self->get( 'namespace' ), $onlyCommitted );
#Remove entries from template list that the user does not have permission to view.
for my $assetId ( keys %{ $templateList } ) {
my $asset = WebGUI::Asset::Template->new( $session, $assetId );
if ( $asset && !$asset->canView( $userId ) ) {
delete $templateList->{ $assetId };
}
}
$self->set( 'options', $templateList );
return;
}
#-------------------------------------------------------------------
=head2 toHtml ( )
Renders a template picker control.
@ -145,18 +193,11 @@ Renders a template picker control.
=cut
sub toHtml {
my $self = shift;
my $onlyCommitted = $self->get('onlyCommitted') ? "assetData.status='approved'" : $self->get('onlyCommitted');
my $templateList = WebGUI::Asset::Template->getList($self->session, $self->get("namespace"), $onlyCommitted);
#Remove entries from template list that the user does not have permission to view.
for my $assetId ( keys %{$templateList} ) {
my $asset = WebGUI::Asset::Template->new($self->session, $assetId);
if (!$asset->canView($self->session->user->userId)) {
delete $templateList->{$assetId};
}
}
$self->set("options", $templateList);
return $self->SUPER::toHtml();
my $self = shift;
$self->setOptions;
return $self->SUPER::toHtml();
}
#-------------------------------------------------------------------

72
t/Form/Template.t Normal file
View file

@ -0,0 +1,72 @@
#-------------------------------------------------------------------
# WebGUI is Copyright 2001-2009 Plain Black Corporation.
#-------------------------------------------------------------------
# Please read the legal notices (docs/legal.txt) and the license
# (docs/license.txt) that came with this distribution before using
# this software.
#-------------------------------------------------------------------
# http://www.plainblack.com info@plainblack.com
#-------------------------------------------------------------------
use FindBin;
use strict;
use lib "$FindBin::Bin/../lib";
use WebGUI::Test;
use WebGUI::Form::Template;
use WebGUI::Session;
use Test::Deep;
use Test::More; # increment this value for each test you create
my $session = WebGUI::Test->session;
plan tests => 4;
my $versionTag = WebGUI::VersionTag->create( $session );
$versionTag->setWorking;
{
my $templateList = WebGUI::Asset::Template->getList( $session, 'style' );
my $elem = WebGUI::Form::Template->new( $session, {
namespace => 'style',
onlyCommitted => 0,
} );
$elem->setOptions;
cmp_deeply(
$templateList,
$elem->get('options'),
'setOption sets correct templates'
);
my $newTemplate = WebGUI::Asset->getRoot( $session )->addChild( {
title => 'Klazam',
menuTitle => 'Klazam',
template => '',
namespace => 'style',
className => 'WebGUI::Asset::Template',
} );
$elem->setOptions;
cmp_deeply(
{ %{$templateList}, $newTemplate->getId => 'Klazam' },
$elem->get('options'),
'setOption includes uncommitted templates when onlyCommitted is false'
);
$elem->set( onlyCommitted => 1 );
$elem->setOptions;
cmp_deeply(
$templateList,
$elem->get('options'),
'setOption excludes uncommitted templates when onlyCommitted is true'
);
my ( $id, $name ) = %{ $templateList };
$elem->set( 'value', $id );
is( $elem->getValueAsHtml, $name, 'getValueAsHtml return template name' );
}
$versionTag->rollback;