Skip to content

Commit

Permalink
Item11150: fixed templating of topics being created
Browse files Browse the repository at this point in the history
- fixed auto-templating when the !DataForm is changed during edit
  • Loading branch information
MichaelDaum committed Jul 17, 2015
1 parent f5f94a5 commit ccddfb3
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 12 deletions.
3 changes: 2 additions & 1 deletion data/System/AutoTemplatePlugin.txt
Expand Up @@ -151,11 +151,12 @@ The following settings can be defined in configure
* Set SHORTDESCRIPTION = Automatically sets VIEW_TEMPLATE and EDIT_TEMPLATE
-->
| Plugin Author: | Foswiki:Main.MichaelDaum |
| Copyright: | © 2008-2014, Oliver Krüger, Michael Daum |
| Copyright: | © 2008-2015, Oliver Krüger, Michael Daum |
| License: | GPL ([[http://www.gnu.org/copyleft/gpl.html][GNU General Public License]]) |
| Release: | %$RELEASE% |
| Version: | %$VERSION% |
| Change History: | <!-- versions below in reverse order -->&nbsp; |
| 17 Jul 2015: | fixed auto-templating of topics being created; fixed auto-templating when the !DataForm is changed during edit |
| 03 Nov 2014: | implemented public API to get the auto-assigned template |
| 25 Aug 2011: | added more default views for tools in the System web |
| 05 Apr 2011: | added VIEW_TEMPLATE_RULES, EDIT_TEMPLATE_RULES preference variables |
Expand Down
18 changes: 12 additions & 6 deletions lib/Foswiki/Plugins/AutoTemplatePlugin.pm
@@ -1,6 +1,7 @@
# Plugin for Foswiki
#
# Copyright (C) 2008-2014 Oliver Krueger <oliver@wiki-one.net>
# Copyright (C) 2008 Oliver Krueger <oliver@wiki-one.net>
# Copyright (C) 2008-2015 Foswiki Contributors
# All Rights Reserved.
#
# This program is distributed in the hope that it will be useful,
Expand All @@ -14,12 +15,11 @@ package Foswiki::Plugins::AutoTemplatePlugin;
use strict;
use warnings;

our $VERSION = '3.00';
our $RELEASE = '3.00';
our $VERSION = '4.00';
our $RELEASE = '4.00';
our $SHORTDESCRIPTION = 'Automatically sets VIEW_TEMPLATE and EDIT_TEMPLATE';
our $NO_PREFS_IN_TOPIC = 1;
our $debug;
our $isEditAction;

sub initPlugin {
my( $topic, $web, $user, $installWeb ) = @_;
Expand All @@ -35,7 +35,7 @@ sub initPlugin {
$debug = $Foswiki::cfg{Plugins}{AutoTemplatePlugin}{Debug} || 0;

# is this an edit action?
$isEditAction = Foswiki::Func::getContext()->{edit};
my $isEditAction = Foswiki::Func::getContext()->{edit};
my $templateVar = $isEditAction?'EDIT_TEMPLATE':'VIEW_TEMPLATE';

# back off if there is a view template already and we are not in override mode
Expand Down Expand Up @@ -109,9 +109,12 @@ sub getTemplateName {
sub _getFormName {
my ($web, $topic) = @_;

my $request = Foswiki::Func::getCgiQuery();
my $form = $request->param("formtemplate");
return $form if defined $form && $form ne '';

my ( $meta, $text ) = Foswiki::Func::readTopic( $web, $topic );

my $form;
$form = $meta->get("FORM") if $meta;
$form = $form->{"name"} if $form;

Expand All @@ -129,6 +132,7 @@ sub _getTemplateFromSectionInclude {
my ($formweb, $formtopic) = Foswiki::Func::normalizeWebTopicName($web, $formName);

# SMELL: This can be done much faster, if the formdefinition topic is read directly
my $isEditAction = Foswiki::Func::getContext()->{edit};
my $sectionName = $isEditAction?'edittemplate':'viewtemplate';
my $templateName = "%INCLUDE{ \"$formweb.$formtopic\" section=\"$sectionName\"}%";
$templateName = Foswiki::Func::expandCommonVariables( $templateName, $topic, $web );
Expand All @@ -141,6 +145,7 @@ sub _getTemplateFromTemplateExistence {
my ($web, $topic) = @_;

my $formName = _getFormName($web, $topic);
my $isEditAction = Foswiki::Func::getContext()->{edit}?1:0;
return unless $formName;

writeDebug("called _getTemplateFromTemplateExistence($formName, $topic, $web)");
Expand All @@ -160,6 +165,7 @@ sub _getTemplateFromRules {
writeDebug("called _getTemplateFromRules($web, $topic)");

# read template rules from preferences
my $isEditAction = Foswiki::Func::getContext()->{edit};
my $rules = Foswiki::Func::getPreferencesValue(
$isEditAction?'EDIT_TEMPLATE_RULES':'VIEW_TEMPLATE_RULES');

Expand Down
12 changes: 7 additions & 5 deletions lib/Foswiki/Plugins/AutoTemplatePlugin/Config.spec
Expand Up @@ -2,15 +2,15 @@
# ---++ AutoTemplatePlugin
# This is the configuration used by the <b>AutoTemplatePlugin</b>.

# **BOOLEAN**
# **BOOLEAN LABEL="Debug"**
# Turn on/off debugging in debug.txt
$Foswiki::cfg{Plugins}{AutoTemplatePlugin}{Debug} = 0;

# **BOOLEAN**
# **BOOLEAN LABEL="Override"**
# Template defined by form overrides existing VIEW_TEMPLATE or EDIT_TEMPLATE settings
$Foswiki::cfg{Plugins}{AutoTemplatePlugin}{Override} = 0;

# **STRING**
# **STRING LABEL="Mode"**
# Comma separated list of modes defining how to find the view or edit template.
# The following modes can be combined:
# <ul>
Expand All @@ -21,7 +21,7 @@ $Foswiki::cfg{Plugins}{AutoTemplatePlugin}{Override} = 0;
# </ul>
$Foswiki::cfg{Plugins}{AutoTemplatePlugin}{Mode} = 'rules, exist';

# **PERL**
# **PERL LABEL="ViewTemplate Rules"**
# Rule set used to derive the view template name. This is a list of rules of the form
# <code>'pattern' => 'template'</code>. The current topic is matched against each of the
# patterns in the given order. The first matching pattern determines the concrete view template.
Expand All @@ -43,8 +43,10 @@ $Foswiki::cfg{Plugins}{AutoTemplatePlugin}{ViewTemplateRules} = {
'WikiUsers' => 'WikiUsersView',
};

# **PERL**
# **PERL LABEL="EditTemplate Rules"**
# Rule set used to derive the edit template name. The format is the same as for the <code>{ViewTempalteRules}</code>
# configuration. This rule set is used during edit.
$Foswiki::cfg{Plugins}{AutoTemplatePlugin}{EditTemplateRules} = {
};

1;

0 comments on commit ccddfb3

Please sign in to comment.