From ccddfb36e93624177a2b3751109f27b99d80a2b7 Mon Sep 17 00:00:00 2001 From: MichaelDaum Date: Fri, 17 Jul 2015 10:58:03 +0200 Subject: [PATCH] Item11150: fixed templating of topics being created - fixed auto-templating when the !DataForm is changed during edit --- data/System/AutoTemplatePlugin.txt | 3 ++- lib/Foswiki/Plugins/AutoTemplatePlugin.pm | 18 ++++++++++++------ .../Plugins/AutoTemplatePlugin/Config.spec | 12 +++++++----- 3 files changed, 21 insertions(+), 12 deletions(-) diff --git a/data/System/AutoTemplatePlugin.txt b/data/System/AutoTemplatePlugin.txt index 7221f92..f9b1bdf 100644 --- a/data/System/AutoTemplatePlugin.txt +++ b/data/System/AutoTemplatePlugin.txt @@ -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: |   | +| 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 | diff --git a/lib/Foswiki/Plugins/AutoTemplatePlugin.pm b/lib/Foswiki/Plugins/AutoTemplatePlugin.pm index 2a94852..f60cf5d 100644 --- a/lib/Foswiki/Plugins/AutoTemplatePlugin.pm +++ b/lib/Foswiki/Plugins/AutoTemplatePlugin.pm @@ -1,6 +1,7 @@ # Plugin for Foswiki # -# Copyright (C) 2008-2014 Oliver Krueger +# Copyright (C) 2008 Oliver Krueger +# Copyright (C) 2008-2015 Foswiki Contributors # All Rights Reserved. # # This program is distributed in the hope that it will be useful, @@ -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 ) = @_; @@ -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 @@ -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; @@ -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 ); @@ -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)"); @@ -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'); diff --git a/lib/Foswiki/Plugins/AutoTemplatePlugin/Config.spec b/lib/Foswiki/Plugins/AutoTemplatePlugin/Config.spec index fa2ff01..762adb3 100644 --- a/lib/Foswiki/Plugins/AutoTemplatePlugin/Config.spec +++ b/lib/Foswiki/Plugins/AutoTemplatePlugin/Config.spec @@ -2,15 +2,15 @@ # ---++ AutoTemplatePlugin # This is the configuration used by the AutoTemplatePlugin. -# **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: #
    @@ -21,7 +21,7 @@ $Foswiki::cfg{Plugins}{AutoTemplatePlugin}{Override} = 0; #
$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 # 'pattern' => 'template'. The current topic is matched against each of the # patterns in the given order. The first matching pattern determines the concrete view template. @@ -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 {ViewTempalteRules} # configuration. This rule set is used during edit. $Foswiki::cfg{Plugins}{AutoTemplatePlugin}{EditTemplateRules} = { }; + +1;