Skip to content

Commit

Permalink
Item13823: bail out early
Browse files Browse the repository at this point in the history
... when not in view, edit or print mode
  • Loading branch information
MichaelDaum committed Oct 18, 2015
1 parent e68c204 commit 509fbda
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
1 change: 1 addition & 0 deletions data/System/AutoTemplatePlugin.txt
Expand Up @@ -151,6 +151,7 @@ The following settings can be defined in configure
---++ Change History

%TABLE{columnwidths="7em" tablewidth="100%"}%
| 13 Oct 2015: | bail out early when not in view, edit or print mode |
| 25 Sep 2015: | added support for PRINT_TEMPLATE |
| 31 Aug 2015: | ignore invalid template warning when section not found |
| 17 Jul 2015: | fixed auto-templating of topics being created; fixed auto-templating when the !DataForm is changed during edit |
Expand Down
23 changes: 14 additions & 9 deletions lib/Foswiki/Plugins/AutoTemplatePlugin.pm
Expand Up @@ -15,8 +15,8 @@ package Foswiki::Plugins::AutoTemplatePlugin;
use strict;
use warnings;

our $VERSION = '5.00';
our $RELEASE = '25 Sep 2015';
our $VERSION = '5.10';
our $RELEASE = '13 Oct 2015';
our $SHORTDESCRIPTION = 'Automatically sets VIEW_TEMPLATE, EDIT_TEMPLATE and PRINT_TEMPLATE';
our $NO_PREFS_IN_TOPIC = 1;
our $debug;
Expand All @@ -31,8 +31,11 @@ sub initPlugin {
my $override = $Foswiki::cfg{Plugins}{AutoTemplatePlugin}{Override} || 0;
$debug = $Foswiki::cfg{Plugins}{AutoTemplatePlugin}{Debug} || 0;


# is this an edit action?
my $templateVar = _isEditAction()?'EDIT_TEMPLATE':_isPrintAction()?'PRINT_TEMPLATE':'VIEW_TEMPLATE';
my $templateVar = _isEditAction()?'EDIT_TEMPLATE':_isViewAction()?'VIEW_TEMPLATE':_isPrintAction()?'PRINT_TEMPLATE':undef;

return 1 unless $templateVar;

# back off if there is a view template already and we are not in override mode
my $currentTemplate = Foswiki::Func::getPreferencesValue($templateVar);
Expand Down Expand Up @@ -138,9 +141,8 @@ sub _getTemplateFromSectionInclude {
my $templateName = "%INCLUDE{ \"$formweb.$formtopic\" section=\"$sectionName\" warn=\"off\"}%";
$templateName = Foswiki::Func::expandCommonVariables( $templateName, $topic, $web );

return $templateName if _templateExists($templateName);

return undef;
return undef unless _templateExists($templateName);
return $templateName;
}

sub _isPrintAction {
Expand All @@ -150,6 +152,10 @@ sub _isPrintAction {
return $contentType eq 'application/pdf' || $cover =~ /print/ ? 1:0;
}

sub _isViewAction {
return Foswiki::Func::getContext()->{view}?1:0;
}

sub _isEditAction {
return Foswiki::Func::getContext()->{edit}?1:0;
}
Expand Down Expand Up @@ -182,9 +188,8 @@ sub _getTemplateFromTemplateExistence {
$templateName =~ s/Form$//;
$templateName .= ucfirst($action);


return $templateName if _templateExists($templateName);
return undef;
return undef unless _templateExists($templateName);
return $templateName;
}

sub _getTemplateFromRules {
Expand Down

0 comments on commit 509fbda

Please sign in to comment.