Skip to content

Commit

Permalink
Item8550: MultiTopicSavePlugin - Add MULTITOPICSAVEMESSAGE
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.foswiki.org/trunk/MultiTopicSavePlugin@6412 0b4bb1d4-4e5a-0410-9cc4-b2b747904278
  • Loading branch information
KennethLavrsen authored and KennethLavrsen committed Feb 17, 2010
1 parent c99252a commit 7e3c188
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 4 deletions.
7 changes: 6 additions & 1 deletion data/System/MultiTopicSavePlugin.txt
Expand Up @@ -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.
* %<nop>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 %<nop>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

Expand Down Expand Up @@ -185,6 +189,7 @@ One line description, required for extensions repository catalog.
| Release: | %$RELEASE% |
| Version: | %$VERSION% |
| Change&nbsp;History: | <!-- versions below in reverse order -->&nbsp; |
| 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% |
Expand Down
41 changes: 38 additions & 3 deletions lib/Foswiki/Plugins/MultiTopicSavePlugin.pm
Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 );

Expand All @@ -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;
}

Expand Down

0 comments on commit 7e3c188

Please sign in to comment.