diff --git a/data/System/MultiTopicSavePlugin.txt b/data/System/MultiTopicSavePlugin.txt index ab67eb6..0b23939 100644 --- a/data/System/MultiTopicSavePlugin.txt +++ b/data/System/MultiTopicSavePlugin.txt @@ -77,8 +77,12 @@ To ease this task you can use the MULTITOPICSAVESUBMIT which creates a submit bu * topic = name of the target topic. In formatted searches you can put $topic here * value = the value that is put in the field by default * options = the values to choose between for types radio, select etc. This value is ignored for text, textarea, and hidden. Options are separated by commas, example: options="dog, cat, horse" + *Note that the input fields generated by MULTITOPICSAVEINPUT have only single quotes (') allowing the use in the format parameter of SEARCH. -Note that the input fields generated by MULTITOPICSAVEINPUT have only single quotes (') allowing the use in the format parameter of SEARCH. + * %MULTITOPICSAVEMESSAGE% + * This macro shows messages about topic that were not saved due to lack access rights and it shows the total number of saved topics. This macro is only expanded when you return to the page after submitting the content. + * The messages are sent via a url parameter called MULTITOPICSAVEMESSAGE. This macro simply expands to %URLPARAM{"MULTITOPICSAVEMESSAGE"}% + * The idea of this macro is to place it somewhere on the topic so the user can see how the saving went. Typically at the top or at the bottom of the page near the submit button. ---++ Examples of input field types with MULTITOPICSAVEINPUT @@ -185,6 +189,7 @@ One line description, required for extensions repository catalog. | Release: | %$RELEASE% | | Version: | %$VERSION% | | Change History: |   | +| 17 Feb 2010 (1.2) | Added MULTITOPICSAVEMESSAGE macro so the user can get feedback on how the saving went | | 17 Feb 2010 (1.1) | Added type hidden. Added examples of use of all the different field types | | 16 Feb 2010 (1.0) | First version of plugin | | Home: | http://foswiki.org/Extensions/%TOPIC% | diff --git a/lib/Foswiki/Plugins/MultiTopicSavePlugin.pm b/lib/Foswiki/Plugins/MultiTopicSavePlugin.pm index 59406ee..98fa54f 100644 --- a/lib/Foswiki/Plugins/MultiTopicSavePlugin.pm +++ b/lib/Foswiki/Plugins/MultiTopicSavePlugin.pm @@ -29,7 +29,7 @@ use Foswiki::Plugins (); # For the API version our $VERSION = '$Rev: 5771 $'; # $RELEASE is used in the "Find More Extensions" automation in configure. -our $RELEASE = '1.1'; +our $RELEASE = '1.2'; # Short description of this plugin # One line description, is shown in the %SYSTEMWEB%.TextFormattingRules topic: @@ -97,6 +97,9 @@ sub initPlugin { Foswiki::Func::registerTagHandler( 'MULTITOPICSAVEINPUT', \&_MULTITOPICSAVEINPUT ); + Foswiki::Func::registerTagHandler( 'MULTITOPICSAVEMESSAGE', + \&_MULTITOPICSAVEMESSAGE + ); # Allow a sub to be called from the REST interface # using the provided alias @@ -265,6 +268,30 @@ sub _MULTITOPICSAVEINPUT { return $result; } + +# The function used to handle the %MULTITOPICSAVEMESSAGE% macro +sub _MULTITOPICSAVEMESSAGE { + my($session, $params, $theTopic, $theWeb) = @_; + # $session - a reference to the Foswiki session object (if you don't know + # what this is, just ignore it) + # $params= - a reference to a Foswiki::Attrs object containing + # parameters. + # This can be used as a simple hash that maps parameter names + # to values, with _DEFAULT being the name for the default + # (unnamed) parameter. + # $theTopic - name of the topic in the query + # $theWeb - name of the web in the query + # Return: the result of processing the macro. This will replace the + # macro call in the final text. + + # For example, %EXAMPLETAG{'hamburger' sideorder="onions"}% + # $params->{_DEFAULT} will be 'hamburger' + # $params->{sideorder} will be 'onions' + + return "%URLPARAM{\"MULTITOPICSAVEMESSAGE\"}%"; +} + + =begin TML ---++ restMultiTopicSave($session) -> $text @@ -322,10 +349,13 @@ sub restMultiTopicSave { # Now we traverse each topic and save all the parameters for # each topic if they have changed. + + my $message = ''; + my $topicsavecounter = 0; + foreach my $topickey ( keys %parameters ) { foreach my $fieldName ( keys %{$parameters{$topickey}} ) { my $value = $parameters{$topickey}{$fieldName}; - my ( $web, $topic ) = Foswiki::Func::normalizeWebTopicName( '', $topickey ); @@ -340,17 +370,22 @@ sub restMultiTopicSave { ) ) { + $message .= "Topic $web.$topic was not saved due to lack of access rights\n\n"; next; } $meta->putKeyed( 'FIELD', { name => $fieldName, value => $value } ); Foswiki::Func::saveTopic($web, $topic, $meta, $text); + $topicsavecounter++; } } } + + $message .= "Number of topics changed: $topicsavecounter"; + $query->param(-name => 'MULTITOPICSAVEMESSAGE', -value => "$message"); my $url = Foswiki::Func::getScriptUrl( $redirectweb, $redirecttopic, 'view' ); - Foswiki::Func::redirectCgiQuery( undef, $url ); + Foswiki::Func::redirectCgiQuery( undef, $url, 1 ); return undef; }