Skip to content

Commit

Permalink
Item8555: Item8554: Adding new feature editmode (default on) so you c…
Browse files Browse the repository at this point in the history
…an turn the edit mode on and off by url param.

Fixed a bug that makes the checkbox and select field turn add option values if they are a substring of an existing value


git-svn-id: http://svn.foswiki.org/trunk/MultiTopicSavePlugin@6420 0b4bb1d4-4e5a-0410-9cc4-b2b747904278
  • Loading branch information
KennethLavrsen authored and KennethLavrsen committed Feb 17, 2010
1 parent 72cc96b commit b47dcf1
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 4 deletions.
42 changes: 41 additions & 1 deletion data/System/MultiTopicSavePlugin.txt
Expand Up @@ -6,6 +6,8 @@
%ATTACHURL%/example.png <br />
_Example screenshot_

%TOC%

This plugin allows the user to submit updates to the dataform in multiple topics in one single edit/submit cycle.

The users can create a topic which displays the fields from many topics as editable fields. The users can edit the field values and when they click a submit button all the topics with fields that were changed will be updated.
Expand Down Expand Up @@ -79,7 +81,8 @@ 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.
* editmode = enable the field in edit mode. If this is set to "off" the value given in the value field is shown. If editmode is "on" the field is shown in edit mode. By default the editmode it "on". This enables selectively to enable editing by adding something like editmode="%<nop>URLPARAM{"multiedit" default="off"}% to MULTITOPICSAVEINPUT and control selectively if fields are editable or not. This can simply be used by appending ?multiedit=on to the URL.
* 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.
Expand Down Expand Up @@ -174,6 +177,42 @@ For example. You have many topics with a field with combinations of values A, B
%SEARCH{"NOT(Platforms ~ '*D*') AND name ~ 'FuncReq*'" type="query" nonoise="on" format="| [[$topic][$formfield(Title)]] |$percntMULTITOPICSAVEINPUT{$quotPlatforms$quot type=$quothidden$quot web=$quot$web$quot topic=$quot$topic$quot value=$quot$formfield(Platforms)$quot }$percnt $percntMULTITOPICSAVEINPUT{$quotPlatforms$quot type=$quotcheckbox$quot size=$quot0$quot multiple=$quoton$quot web=$quot$web$quot topic=$quot$topic$quot value=$quot$quot options=$quotD$quot }$percnt |"}%
</verbatim>

---++ Tips and Tricks

---+++ Auto generating the options list

Instead of manually defining the list of options in MULTITOPICSAVEINPUT you can load the list of options from the Plugin form. Assuming the values are defined in the form itself this is an example of setting a macro which you can then use later. In this example the form topic is called !RequirementsForm and the field name is Platforms.

<verbatim>
* Set PLATFORMOPTIONS = %SEARCH{"\| *Platforms *\|" topic="RequirementsForm" regex="on" nonoise="on" multiple="on" format="$pattern(.*?\| *Platforms *\|[^\|]*\|[^\|]*\| *([^\|]*?) *\|.*)"}%
</verbatim>

You can then use options="%<nop>PLATFORMOPTIONS%" in MULTITOPICSAVEINPUT

If the values are defined in their own topic use instead this example

The topic called =FieldName= defines the values in a table like

| *Name* | *Type* | *Tooltip message* |
| Open | option | Not yet resolved |
| Closed | option | Fixed and closed |
| Rejected | option | Not accepted and closed |

The example below sets FIELDOPTIONS = Open, Closed, Rejected

<verbatim>
* Set FIELDOPTIONS = %SEARCH{ "^\|[^\|]*\| *option *\|" topic="FieldName" type="regex" multiple="on" nonoise="on" separator=", " format="$pattern(^\| *(.*?) *\|.*)" }%
</verbatim>

---+++ Using the editmode parameter

To take advantage of the =editmode= parameter for MULTITOPICSAVEINPUT add editmode="%<nop>URLPARAM{"multiedit" default="off"}% to MULTITOPICSAVEINPUT.

This will disable editing and just show the plain content given in the value option.

At the top of the page put a link like this =[<nop>[%<nop>TOPICURL%?multiedit=on][Edit the requirements]]=. When the user clicks the link the page is reloaded and all fields will be in edit mode. A bit like we know from EditTablePlugin.

[[%TOPICURL%?multiedit=on][Edit the requirements]]

<!--
One line description, required for extensions repository catalog.
Expand All @@ -191,6 +230,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.3) | Added the parameter editmode to MULTITOPICSAVEINPUT which can be used to show the value instead of an edit field. <br />Fixed bug where options were wrongly selected if they matched a substring of the one of the values. |
| 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 |
Expand Down
12 changes: 9 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.2';
our $RELEASE = '1.3';

# Short description of this plugin
# One line description, is shown in the %SYSTEMWEB%.TextFormattingRules topic:
Expand Down Expand Up @@ -177,6 +177,12 @@ sub _MULTITOPICSAVEINPUT {
my $value = defined $params->{value} ? $params->{value} : '';
my @values = map { s/^\s*(.*?)\s*$/$1/; $_; } split( /\s*,\s*/, $value );

# If edit mode is defined and set to off - just return the value
my $editmode = defined $params->{editmode} ? $params->{editmode} : 'on';
unless ( Foswiki::Func::isTrue( $editmode ) ) {
return $value;
}

# We assume all leading and trailing spaces are unwanted.
my @options = ();
if ( defined $params->{options} ) {
Expand Down Expand Up @@ -212,7 +218,7 @@ sub _MULTITOPICSAVEINPUT {
if ( $type eq 'radio' && $option eq $value ) {
$result .= "checked='checked' ";
}
if ( $type eq 'checkbox' && grep (/$option/, @values ) ) {
if ( $type eq 'checkbox' && grep (/^$option$/, @values ) ) {
$result .= "checked='checked' ";
}
$result .= "/> $option </td>";
Expand Down Expand Up @@ -245,7 +251,7 @@ sub _MULTITOPICSAVEINPUT {
foreach my $option ( @options ) {
$result .= "<option class='foswikiOption' ";

if ( grep (/$option/, @values ) ) {
if ( grep (/^$option$/, @values ) ) {
$result .= "selected='selected' ";
}

Expand Down

0 comments on commit b47dcf1

Please sign in to comment.