Change how the view template variables work. It no longer appends, viewTemplateVars
makes them all.
This commit is contained in:
parent
338433e78d
commit
17b124c39f
2 changed files with 15 additions and 24 deletions
|
|
@ -258,31 +258,21 @@ sub view {
|
|||
my $session = $self->session;
|
||||
|
||||
#This automatically creates template variables for all of your wobject's properties.
|
||||
my $var = $self->get;
|
||||
$self->viewTemplateVariables($var);
|
||||
|
||||
#This is an example of debugging code to help you diagnose problems.
|
||||
#WebGUI::ErrorHandler::warn($self->get("templateId"));
|
||||
|
||||
#use Data::Dumper;
|
||||
#$session->log->warn(Dumper $var);
|
||||
my $var = $self->viewTemplateVariables();
|
||||
|
||||
return $self->processTemplate($var, undef, $self->{_viewTemplate});
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 viewTemplateVars ( $var )
|
||||
=head2 viewTemplateVars ( )
|
||||
|
||||
Add template variables to the existing template variables.
|
||||
|
||||
=head3 $var
|
||||
|
||||
Template variables will be added onto this hash ref.
|
||||
Make template variables for the view template.
|
||||
|
||||
=cut
|
||||
|
||||
sub viewTemplateVariables {
|
||||
my ($self, $var) = @_;
|
||||
my ($self) = @_;
|
||||
my $session = $self->session;
|
||||
##Only return assetIds, we'll build data for the things that are actually displayed.
|
||||
my $storySql = $self->getLineageSql(['descendants'],{
|
||||
|
|
@ -292,8 +282,9 @@ sub viewTemplateVariables {
|
|||
my $p = WebGUI::Paginator->new($session, $self->getUrl, $self->get('storiesPerPage'));
|
||||
$p->setDataByQuery($storySql);
|
||||
my $storyIds = $p->getPageData();
|
||||
$var->{date_loop} = [];
|
||||
my $var = $self->get;
|
||||
$p->appendTemplateVars($var);
|
||||
$var->{date_loop} = [];
|
||||
my $lastStoryDate = '';
|
||||
my $datePointer = undef;
|
||||
##Only build objects for the assets that we need
|
||||
|
|
@ -319,7 +310,7 @@ sub viewTemplateVariables {
|
|||
|
||||
$var->{addStoryUrl} = $self->getUrl('func=add;class=WebGUI::Asset::Story');
|
||||
$var->{canPostStories} = $self->canPostStories;
|
||||
return 1;
|
||||
return $var;
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
|
|
|||
|
|
@ -24,6 +24,7 @@ use WebGUI::Test; # Must use this before any other WebGUI modules
|
|||
use WebGUI::Test::Maker::Permission;
|
||||
use WebGUI::Session;
|
||||
use WebGUI::Text;
|
||||
use WebGUI::Utility;
|
||||
use WebGUI::DateTime;
|
||||
use DateTime;
|
||||
|
||||
|
|
@ -173,10 +174,9 @@ $story = $newFolder->addChild({ className => 'WebGUI::Asset::Story', title => "T
|
|||
$session->db->write("update asset set creationDate=$tomorrow where assetId=?",[$story->getId]);
|
||||
|
||||
my $templateVars;
|
||||
$templateVars = {};
|
||||
$archive->viewTemplateVariables($templateVars);
|
||||
$templateVars = $archive->viewTemplateVariables();
|
||||
KEY: foreach my $key (keys %{ $templateVars }) {
|
||||
next KEY unless $key =~ /pagination\./;
|
||||
next KEY if isIn($key, qw/canPostStories addStoryUrl date_loop/);
|
||||
delete $templateVars->{$key};
|
||||
}
|
||||
|
||||
|
|
@ -220,16 +220,16 @@ $folder->addChild({ className => 'WebGUI::Asset::Story', title => 'Story 3'});
|
|||
$folder->addChild({ className => 'WebGUI::Asset::Story', title => 'Story 4'});
|
||||
$archive->update({storiesPerPage => 3});
|
||||
|
||||
##Don't assume that Admin and Visitor have the same timezone.
|
||||
$session->user({userId => 3});
|
||||
($wgBdayMorn,undef) = $session->datetime->dayStartEnd($wgBday);
|
||||
|
||||
$templateVars = {};
|
||||
$archive->viewTemplateVariables($templateVars);
|
||||
$templateVars = $archive->viewTemplateVariables();
|
||||
KEY: foreach my $key (keys %{ $templateVars }) {
|
||||
next KEY unless $key =~ /pagination\./;
|
||||
next KEY if isIn($key, qw/canPostStories addStoryUrl date_loop/);
|
||||
delete $templateVars->{$key};
|
||||
}
|
||||
|
||||
|
||||
cmp_deeply(
|
||||
$templateVars,
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue