Skip to content

Commit

Permalink
Item477: Rebrand RenderFormPlugin
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.foswiki.org/trunk@1376 0b4bb1d4-4e5a-0410-9cc4-b2b747904278
  • Loading branch information
KennethLavrsen authored and KennethLavrsen committed Dec 15, 2008
1 parent 5ba8ce2 commit a1b215d
Show file tree
Hide file tree
Showing 12 changed files with 156 additions and 134 deletions.
Expand Up @@ -21,7 +21,7 @@ Features:

---++ Syntax Rules
* Usage: =%<nop>RENDERFORM{attr1="val1" attr2="val2" ...}%=
* Example: =%<nop>RENDERFORM{"TWikiFormDefinition"}% (=%<nop>RENDERFORM{form="TWikiFormDefinition"}%=)
* Example: =%<nop>RENDERFORM{"DataFormDefinition"}% (=%<nop>RENDERFORM{form="DataFormDefinition"}%=)

---++ Quick Start Guide

Expand Down Expand Up @@ -190,40 +190,37 @@ You can also use template based preferences, just write ==RENDERFORM_TEMPLATE_&l

---++ Plugin Installation Instructions

__Note:__ You do not need to install anything on the browser to use this plugin. The following instructions are for the administrator who installs the plugin on the TWiki server.
__Note:__ You do not need to install anything on the browser to use this plugin. The following instructions are for the administrator who installs the plugin on the Foswiki server.

* Download the ZIP file from the Plugin Home (see below)
* Unzip ==%TOPIC%.zip== in your twiki installation directory. Content:
* Unzip ==%TOPIC%.zip== in your Foswiki installation directory. Content:
| *File:* | *Description:* |
| ==data/System/%TOPIC%.txt== | Plugin topic |
| ==data/TWiki/VarRENDERFORM.txt== | Plugin Variables topic |
| ==data/TWiki/%TOPIC%ExampleForm.txt== | Example form |
| ==pub/TWiki/%TOPIC%/example.gif== | Example image |
| ==data/System/VarRENDERFORM.txt== | Plugin Variables topic |
| ==data/System/%TOPIC%ExampleForm.txt== | Example form |
| ==pub/System/%TOPIC%/example.gif== | Example image |
| ==lib/Foswiki/Plugins/%TOPIC%.pm== | Plugin Perl module |
| ==lib/Foswiki/Plugins/%TOPIC%/Core.pm== | Plugin Perl module |
* Configure the Plugin:
* TWiki 4.0 and up: Run the [[%SCRIPTURL%/configure%SCRIPTSUFFIX%][configure]] script to enable the Plugin
* Run the [[%SCRIPTURL%/configure%SCRIPTSUFFIX%][configure]] script to enable the Plugin
* Change the Plugin settings as needed
* Test if the installation was successful:
* see Examples section


---++ Plugin Info
| Plugin Author: | TWiki:Main.DanielRohde |
| Copyright: | &copy; 2008, TWiki:Main.DanielRohde |
| Plugin Author: | Foswiki:Main.DanielRohde |
| Copyright: | &copy; 2008, Foswiki:Main.DanielRohde |
| License: | GPL ([[http://www.gnu.org/copyleft/gpl.html][GNU General Public License]]) |
| Plugin Version: | V1.002 (14 Oct 2008) |
| Plugin Version: | V1.003 (16 Dec 2008) |
| Change History: | <!-- versions below in reverse order --> |
| V1.002 (14 Oct 2008): | TWiki:Main:DanielRohde: added layout feature; fixed date field bug; added missing docs; |
| V1.001 (05 Oct 2008): | TWiki:Main:DanielRohde: changed topicparent default; added and fixed docs; fixed date field bug; fixed non-word character in field names bug; |
| V1.000 (04 Oct 2008): | TWiki:Main:DanielRohde: Initial version |
| TWiki Dependency: | $TWiki::Plugins::VERSION 1.1 |
| V1.003 (16 Dec 2008): | Foswiki:Main.KennethLavrsen: Changed to Foswiki name space |
| V1.002 (14 Oct 2008): | Foswiki:Main:DanielRohde: added layout feature; fixed date field bug; added missing docs; |
| V1.001 (05 Oct 2008): | Foswiki:Main:DanielRohde: changed topicparent default; added and fixed docs; fixed date field bug; fixed non-word character in field names bug; |
| V1.000 (04 Oct 2008): | Foswiki:Main:DanielRohde: Initial version |
| Foswiki Dependency: | $Foswiki::Plugins::VERSION 1.1 |
| CPAN Dependencies: | none |
| Other Dependencies: | none |
| Perl Version: | 5.005 |
| [[Foswiki:Extensions/Benchmark][Benchmarks]]: | %SYSTEMWEB%.GoodStyle 61%, %SYSTEMWEB%.FormattedSearch 87%, %TOPIC% 70% |
| Perl Version: | 5.008 |
| Plugin Home: | http://foswiki.org/Extensions/%TOPIC% |
| Feedback: | http://foswiki.org/Extensions/%TOPIC%Dev |
| Appraisal: | http://foswiki.org/Extensions/%TOPIC%Appraisal |

-- TWiki:Main.DanielRohde - 04 Oct 2008
Expand Up @@ -3,7 +3,7 @@
#VarRENDERFORM
---+++ RENDERFORM -- render DataForms data within a topic
* The =%<nop>RENDERLIST%= variable is handled by the RenderFormPlugin
* Syntax: =%<nop>RENDERFORM{ "ATWikiFormDefinition"}%=
* Syntax: =%<nop>RENDERFORM{ "ADataFormDefinition"}%=
* Example:%BR%
=%<nop>RENDERLIST{ "%SYSTEMWEB%.HelpDeskForm" }%= %BR%
* Related: DataForms
67 changes: 67 additions & 0 deletions RenderFormPlugin/lib/Foswiki/Plugins/RenderFormPlugin.pm
@@ -0,0 +1,67 @@
# RenderFormPlugin for Foswiki - The Free and Open Source Wiki, http://foswiki.org/
#
# Copyright (C) 2008 Daniel Rohde
#
# For licensing info read LICENSE file in the Foswiki root.
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details, published at
# http://www.gnu.org/copyleft/gpl.html
#
# As per the GPL, removal of this notice is prohibited.

package Foswiki::Plugins::RenderFormPlugin;

use strict;

use vars qw( $VERSION $RELEASE $REVISION $debug $pluginName );

$VERSION = '$Rev$';

$RELEASE = 'Dakar';

$REVISION = '1.003'; #Kenneth Lavrsen# Changed to Foswiki name space
#$REVISION = '1.002'; #dro# added layout feature; fixed date field bug; added missing docs;
#$REVISION = '1.001'; #dro# changed topicparent default; added and fixed docs; fixed date field bug; fixed non-word character in field names bug;
#$REVISION = '1.000'; #dro# initial version

$pluginName = 'RenderFormPlugin';

sub initPlugin {
my( $topic, $web, $user, $installWeb ) = @_;

# check for Plugins.pm versions
if( $Foswiki::Plugins::VERSION < 1.026 ) {
Foswiki::Func::writeWarning( "Version mismatch between $pluginName and Plugins.pm" );
return 0;
}

# Plugin correctly initialized
return 1;
}

sub commonTagsHandler {
# do not uncomment, use $_[0], $_[1]... instead
### my ( $text, $topic, $web ) = @_;

Foswiki::Func::writeDebug( "- ${pluginName}::commonTagsHandler( $_[2].$_[1] )" ) if $debug;

## !! does not work: deep recursion bug:
## use Foswiki::Contrib::JSCalendarContrib;
## Foswiki::Contrib::JSCalendarContrib::addHEAD( 'foswiki' );

## eval {
use Foswiki::Plugins::RenderFormPlugin::Core;
$_[0] =~ s/\%RENDERFORM{(.*?)}\%/Foswiki::Plugins::RenderFormPlugin::Core::render($1,$_[1],$_[2])/ge;
$_[0] =~ s/\%STARTRENDERFORMLAYOUT(.*?)STOPRENDERFORMLAYOUT\%//sg;
### workaround for date fields:
$_[0] =~ s/<\/body>/%INCLUDE{"%SYSTEMWEB%\/JSCalendarContribInline"}%<\/body>/i if ($Foswiki::Plugins::VERSION > 1.1) && ($_[0] !~ /JSCalendarContrib\foswiki.js/);
##};
##Foswiki::Func::writeWarning($@) if $@;
}
@@ -1,4 +1,22 @@
package TWiki::Plugins::RenderFormPlugin::Core;
# RenderFormPlugin for Foswiki - The Free and Open Source Wiki, http://foswiki.org/
#
# Copyright (C) 2008 Daniel Rohde
#
# For licensing info read LICENSE file in the Foswiki root.
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details, published at
# http://www.gnu.org/copyleft/gpl.html
#
# As per the GPL, removal of this notice is prohibited.

package Foswiki::Plugins::RenderFormPlugin::Core;

### todo:
# + additional form field definitions that can be used with URLPARAM in the templatetopic
Expand Down Expand Up @@ -60,7 +78,7 @@ sub _initDefaults {
sub _initOptions {
my ($attributes, $topic, $web) = @_;

my %params = &TWiki::Func::extractParameters($attributes);
my %params = &Foswiki::Func::extractParameters($attributes);

## handle default parameter:
$params{form}=$params{_DEFAULT} if (defined $params{_DEFAULT}) && (!defined $params{form});
Expand All @@ -75,9 +93,9 @@ sub _initOptions {
return 0 if $#unknownParams != -1;

my $tmplName = $params{template};
$tmplName = ( TWiki::Func::getPreferencesValue("\U${pluginName}_TEMPLATE\E") || undef) unless defined $tmplName;
$tmplName = ( Foswiki::Func::getPreferencesValue("\U${pluginName}_TEMPLATE\E") || undef) unless defined $tmplName;

my $cgi = TWiki::Func::getCgiQuery();
my $cgi = Foswiki::Func::getCgiQuery();


$formCounter++;
Expand All @@ -91,8 +109,8 @@ sub _initOptions {
$v = $params{$option} unless defined $v;

if ((defined $tmplName)&&(!defined $v)) {
$v = (TWiki::Func::getPreferencesFlag("\U${pluginName}_TEMPLATE_${tmplName}_${option}\E") || undef) if grep /^\Q$option\E$/, @flagOptions;
$v = (TWiki::Func::getPreferencesValue("\U${pluginName}_TEMPLATE_${tmplName}_${option}\E") || undef) unless defined $v;
$v = (Foswiki::Func::getPreferencesFlag("\U${pluginName}_TEMPLATE_${tmplName}_${option}\E") || undef) if grep /^\Q$option\E$/, @flagOptions;
$v = (Foswiki::Func::getPreferencesValue("\U${pluginName}_TEMPLATE_${tmplName}_${option}\E") || undef) unless defined $v;
$v = undef if (defined $v) && ($v eq "");
}

Expand All @@ -104,9 +122,9 @@ sub _initOptions {
}
} else {
if (grep /^\Q$option\E$/, @flagOptions) {
$v = TWiki::Func::getPreferencesFlag("\U${pluginName}_$option\E") || undef;
$v = Foswiki::Func::getPreferencesFlag("\U${pluginName}_$option\E") || undef;
} else {
$v = TWiki::Func::getPreferencesValue("\U${pluginName}_$option\E") || undef;
$v = Foswiki::Func::getPreferencesValue("\U${pluginName}_$option\E") || undef;
}
$v = undef if (defined $v) && ($v eq "");
$options{$option}=(defined $v)? $v : $defaults{$option};
Expand All @@ -121,7 +139,7 @@ sub _initOptions {

# automatic mode change:
my ($w,$t) = _getWebAndTopic($options{topic},$web);
my $topicExists = TWiki::Func::topicExists($w,$t);
my $topicExists = Foswiki::Func::topicExists($w,$t);
$options{mode}='view' if (($options{mode} eq $defaults{mode}) && ($options{topic} ne $topic.'XXXXXXXXXX') && $topicExists);

# automatic form detection:
Expand Down Expand Up @@ -151,9 +169,9 @@ sub _detectForm {
my $formTopic = undef;

if ($text =~ /\%META:FORM{(.*?)}\%/s) {
my %params = TWiki::Func::extractParameters($1);
my %params = Foswiki::Func::extractParameters($1);
my ($w,$t) = _getWebAndTopic($params{name}, $web);
$formTopic = "$w.$t" if TWiki::Func::topicExists($w,$t);
$formTopic = "$w.$t" if Foswiki::Func::topicExists($w,$t);
}
return $formTopic;
}
Expand Down Expand Up @@ -183,7 +201,7 @@ sub render {
my %titl = %{$titlRef};

my $text = "";
my $cgi = TWiki::Func::getCgiQuery();
my $cgi = Foswiki::Func::getCgiQuery();

#_dump(\@defs);

Expand All @@ -193,7 +211,7 @@ sub render {
$text .= $cgi->start_form(-method=>"post",
-onSubmit=>"return ${formName}CheckFormData();",
-name=>$formName,
-action=>TWiki::Func::getScriptUrl($theWeb, $topic, $options{script}));
-action=>Foswiki::Func::getScriptUrl($theWeb, $topic, $options{script}));
$text .= $cgi->a({-name=>"$formName"},"");

$options{topicparent} = "$theWeb.$theTopic" unless defined $options{topicparent};
Expand Down Expand Up @@ -242,13 +260,13 @@ sub _layoutTopicExists {
my ($topic,$web);
($topic) = split(/\#/,$options{layout});
($web,$topic) = _getWebAndTopic($topic,$theWeb);
return TWiki::Func::topicExists($web,$topic);
return Foswiki::Func::topicExists($web,$topic);
}
# =========================
sub _renderUserLayout {
my ($topic,$web,$a) = @_;

my $cgi = TWiki::Func::getCgiQuery();
my $cgi = Foswiki::Func::getCgiQuery();
my $formName = $options{formName};

my $text = _readUserLayout($web);
Expand All @@ -272,7 +290,7 @@ sub _renderUserLayout {
my $title = $$def{title};

if ($text=~s/(\Q$options{fieldmarker}$title$options{fieldmarker}\E)/join(" ",_renderFormField($cgi,$def,$formName))/eg) {
TWiki::Func::writeDebug("$1 substituted") if $TWiki::Plugins::RenderFormPlugin::debug;
Foswiki::Func::writeDebug("$1 substituted") if $Foswiki::Plugins::RenderFormPlugin::debug;
} else {
$hidden .= $cgi->hidden(-name=>$name, -default=>$$def{values}[0]{name});
}
Expand All @@ -296,7 +314,7 @@ sub _readUserLayout {

while ((!defined $layout)&&($text=~s/\%STARTRENDERFORMLAYOUT\{(.*?)\}\%(.*?)\%STOPRENDERFORMLAYOUT\%//s)) {
my ($p,$l) = ($1,$2);
my %params = TWiki::Func::extractParameters($p);
my %params = Foswiki::Func::extractParameters($p);
my $pname = $params{name};
$pname = $params{_DEFAULT} unless defined $pname;
if ((defined $name) && (defined $pname) && ($pname eq $name) && ((!defined $params{mode}) || ($params{mode} eq $options{mode}))) {
Expand Down Expand Up @@ -329,7 +347,7 @@ sub _readUserLayout {
sub _getSwitchButton {
my ($theTopic,$theWeb) = @_;
my $formName = $options{formName};
my $cgi = TWiki::Func::getCgiQuery();
my $cgi = Foswiki::Func::getCgiQuery();
my $buttonmode = $options{mode} eq 'view' ? 'edit' : $options{mode} eq 'edit' ? 'view' : '';

## preserve all query parameters and overwrite some
Expand Down Expand Up @@ -428,11 +446,11 @@ sub _renderFormField {
$td = $$def{value};
$td = '&nbsp;' if $$def{value} eq "";
} else {
my $dateformat = defined $options{dateformat} ? $options{dateformat} : TWiki::Func::getPreferencesValue('JSCALENDARDATEFORMAT');
my $dateformat = defined $options{dateformat} ? $options{dateformat} : Foswiki::Func::getPreferencesValue('JSCALENDARDATEFORMAT');
$dateformat="%d %b %Y" unless defined $dateformat;
my $id=$formName.$$def{name};
$td = $cgi->textfield({-id=>$id,-name=>$$def{name},-default=>$$def{value},-size=>$$def{size},-readonly=>'readonly'})
.$cgi->image_button(-name=>'calendar', -src=>'%PUBURLPATH%/TWiki/JSCalendarContrib/img.gif',
.$cgi->image_button(-name=>'calendar', -src=>'%PUBURLPATH%/%SYSTEMWEB%/JSCalendarContrib/img.gif',
-alt=>'Calendar', -title=>'Calendar', -onClick=>qq@javascript: return showCalendar('$id','$dateformat')@);
}
}
Expand Down Expand Up @@ -501,13 +519,13 @@ sub _readTopicFormData {
my $foundForm=0;
foreach my $line (split(/[\r\n]/,$data)) {
if ($line=~/\%META:FORM{(.*?)}\%/) {
my %params = TWiki::Func::extractParameters($1);
my %params = Foswiki::Func::extractParameters($1);
$foundForm = ($params{name} eq $options{form}) || ($params{name} eq "$theWeb.$options{form}");
next;
}

if ($foundForm &&($line=~/\%META:FIELD{(.*?)}\%/)) {
my %params = TWiki::Func::extractParameters($1);
my %params = Foswiki::Func::extractParameters($1);

if (defined $$attr{$params{name}} && $$attr{$params{name}}{type} =~ /^(text|textarea|label|date)$/) {
$$attr{$params{name}}{value}=$params{value};
Expand Down Expand Up @@ -655,7 +673,7 @@ sub _getFormFieldValues {
# =========================
sub _createMissingParamsMessage {
my $msg;
$msg = TWiki::Func::getPreferencesValue("MISSINGPARAMSMSG") || undef;
$msg = Foswiki::Func::getPreferencesValue("MISSINGPARAMSMSG") || undef;
$msg = $defaults{missingparamsmsg} unless defined $msg;
$msg =~ s/\%MISSINGPARAMSLIST\%/join(', ', sort @missingParams)/eg;
$msg =~ s/\%REQUIREDPARAMSLIST\%/join(', ', sort @requiredOptions)/eg;
Expand All @@ -664,7 +682,7 @@ sub _createMissingParamsMessage {
# =========================
sub _createUnknownParamsMessage {
my $msg;
$msg = TWiki::Func::getPreferencesValue("UNKNOWNPARAMSMSG") || undef;
$msg = Foswiki::Func::getPreferencesValue("UNKNOWNPARAMSMSG") || undef;
$msg = $defaults{unknownparamsmsg} unless defined $msg;
$msg =~ s/\%UNKNOWNPARAMSLIST\%/join(', ', sort @unknownParams)/eg;
$msg =~ s/\%KNOWNPARAMSLIST\%/join(', ', sort keys %defaults)/eg;
Expand All @@ -673,7 +691,7 @@ sub _createUnknownParamsMessage {
# =========================
sub _createInvalidParamsMessage {
my $msg;
$msg = TWiki::Func::getPreferencesValue("INVALIDPARAMSMSG") || undef;
$msg = Foswiki::Func::getPreferencesValue("INVALIDPARAMSMSG") || undef;
$msg = $defaults{invalidparamsmsg} unless defined $msg;
$msg =~ s/\%INVALIDPARAMSLIST\%/join(', ', sort @invalidParams)/eg;
my $list = "";
Expand All @@ -688,17 +706,17 @@ sub _readTopicText
{
my( $theWeb, $theTopic, $dontExpand ) = @_;
my $text = '';
if( $TWiki::Plugins::VERSION >= 1.010 ) {
$text = &TWiki::Func::readTopicText( $theWeb, $theTopic, '', 1 );
if( $Foswiki::Plugins::VERSION >= 1.010 ) {
$text = &Foswiki::Func::readTopicText( $theWeb, $theTopic, '', 1 );
} else {
$text = &TWiki::Func::readTopic( $theWeb, $theTopic );
$text = &Foswiki::Func::readTopic( $theWeb, $theTopic );
}

#if ((!defined $dontExpand) || (!$dontExpand)) {
$text =~ s/(\%RENDERFORM{.*?}%)/<verbatim>\n$1<\/verbatim>/g;
$text =~ s/(\%STARTRENDERFORMLAYOUT.*?STOPRENDERFORMLAYOUT\%)/<verbatim>\n$1\n<\/verbatim>/sg;

$text = TWiki::Func::expandCommonVariables($text, $theTopic, $theWeb);
$text = Foswiki::Func::expandCommonVariables($text, $theTopic, $theWeb);
#}
# return raw topic text, including meta data
return $text;
Expand All @@ -715,7 +733,7 @@ sub _int {
sub _dump {
eval {
use Data::Dumper;
TWiki::Func::writeWarning(Data::Dumper->Dump( \@_ ));
Foswiki::Func::writeWarning(Data::Dumper->Dump( \@_ ));
};
}
1;
@@ -1,5 +1,5 @@
# Dependencies for RenderFormPlugin
# Example:
# Time::ParseDate,>=2003.0211,cpan,Required.
# TWiki::Plugins,>=1.15,perl,TWiki 4.1 release.
# Foswiki::Plugins,>=1.15,perl,Foswiki 1.0 release.

@@ -0,0 +1,8 @@
# Release manifest for RenderFormPlugin
data/System/RenderFormPlugin.txt 0644 Documentation
data/System/VarRENDERFORM.txt 0644 Documentation
data/System/RenderFormPluginExampleForm.txt 0644 Documentation
pub/System/RenderFormPlugin/example.gif 0644 Example image
lib/Foswiki/Plugins/RenderFormPlugin.pm 0644 Perl module
lib/Foswiki/Plugins/RenderFormPlugin/Core.pm 0644 Perl module

0 comments on commit a1b215d

Please sign in to comment.