Skip to content

Commit

Permalink
Item11847:
Browse files Browse the repository at this point in the history
   * fixed error when meta data definition is read-protected
   * implemented a way to store meta data in a distant / hidden topic 



git-svn-id: http://svn.foswiki.org/trunk/MetaDataPlugin@14787 0b4bb1d4-4e5a-0410-9cc4-b2b747904278
  • Loading branch information
MichaelDaum authored and MichaelDaum committed May 10, 2012
1 parent 6fc07b4 commit 6990e56
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 18 deletions.
3 changes: 3 additions & 0 deletions data/System/MetaDataPlugin.txt
Expand Up @@ -112,6 +112,7 @@ render a modal edit dialog according to the associated !DataForm definition.

| *Parameter* | *Description* | *Default* |
| "..." | !MetaData key | |
| topic | the location where to store the newly created records |
| format | format string to render the button | defined in the =metadataplugin.tmpl= template |
| template | name of the TMPL:DEF to render the button | metadata::new |
| title | display title for the button | |
Expand Down Expand Up @@ -181,6 +182,8 @@ have a database of efforts recorded on that tracker.
| Release: | %$RELEASE% |
| Version: | %$VERSION% |
| Change History: | <!-- versions below in reverse order -->&nbsp; |
| 10 May 2012: | fixed error when meta data definition is read-protected; \
implemented a way to store meta data in a distant / hidden topic |
| 08 May 2012: | added =sort= and =reverse= parameters to RENDERMETADATA |
| 27 Apr 2012: | fixed access to the original value of +values formfields |
| 26 Apr 2012: | fixing table editor for firefox; \
Expand Down
21 changes: 17 additions & 4 deletions lib/Foswiki/Plugins/MetaDataPlugin.pm
@@ -1,6 +1,6 @@
# Plugin for Foswiki - The Free and Open Source Wiki, http://foswiki.org/
#
# MetaDataPlugin is Copyright (C) 2011 Michael Daum http://michaeldaumconsulting.com
# MetaDataPlugin is Copyright (C) 2011-2012 Michael Daum http://michaeldaumconsulting.com
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
Expand All @@ -22,9 +22,10 @@ use Foswiki::Func ();
use Foswiki::Plugins ();
use Foswiki::Contrib::JsonRpcContrib ();
use Foswiki::Plugins::MetaDataPlugin::Core();
use Error qw( :try );

our $VERSION = '$Rev$';
our $RELEASE = '1.20';
our $RELEASE = '1.30';
our $SHORTDESCRIPTION = 'Bring custom meta data to wiki apps';
our $NO_PREFS_IN_TOPIC = 1;
our $core;
Expand Down Expand Up @@ -138,10 +139,22 @@ sub topicName2MetaData {
##############################################################################
sub getMetaDataDefinition {
my ($web, $topic) = @_;

return unless Foswiki::Func::topicExists($web, $topic);

my $formDef = new Foswiki::Form($Foswiki::Plugins::SESSION, $web, $topic);
my $formDef;

try {
$formDef = new Foswiki::Form($Foswiki::Plugins::SESSION, $web, $topic);
} catch Error::Simple with {

# just in case, cus when this fails it takes down more of foswiki
Foswiki::Func::writeWarning("MetaDataPlugin::getMetaDataDefinition() failed for $web.$topic:".shift);

} catch Foswiki::AccessControlException with {
# catch but simply bail out
};

return unless defined $formDef;

my @other = ();
Expand Down
27 changes: 19 additions & 8 deletions lib/Foswiki/Plugins/MetaDataPlugin/Core.pm
@@ -1,6 +1,6 @@
# Plugin for Foswiki - The Free and Open Source Wiki, http://foswiki.org/
#
# MetaDataPlugin is Copyright (C) 2011 Michael Daum http://michaeldaumconsulting.com
# MetaDataPlugin is Copyright (C) 2011-2012 Michael Daum http://michaeldaumconsulting.com
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
Expand Down Expand Up @@ -37,7 +37,6 @@ sub writeDebug {
sub new {
my ($class, $session) = @_;


my $this = bless({
baseWeb => $session->{webName},
baseTopic => $session->{topicName},
Expand Down Expand Up @@ -73,11 +72,18 @@ sub NEWMETADATA {
my ($this, $params) = @_;

my $theMetaData = lc($params->{_DEFAULT} || $params->{meta} || '');
my $theTitle = $params->{title} || '';
my $theTitle = $params->{title};
my $theFormat = $params->{format};
my $theTemplate = $params->{template} || 'metadata::new';
my $theTopic = $params->{topic} || $this->{baseWeb}.'.'.$this->{baseTopic};

my ($web, $topic) = Foswiki::Func::normalizeWebTopicName($this->{baseWeb}, $theTopic);
$theTopic = "$web.$topic";

$theTitle = "New ".ucfirst($theMetaData) unless defined $theTitle;

$theFormat = Foswiki::Func::expandTemplate($theTemplate) unless defined $theFormat;
$theFormat =~ s/%topic%/$theTopic/g;
$theFormat =~ s/%meta%/$theMetaData/g;
$theFormat =~ s/%title%/$theTitle/g;

Expand Down Expand Up @@ -162,13 +168,11 @@ sub renderMetaData {
#writeDebug("formWeb=$formWeb, formTopic=$formTopic");

unless (Foswiki::Func::topicExists($formWeb, $formTopic)) {
print STDERR "error: form definition for $formWeb.$formTopic does not exist";
return inlineError("form definition for $formWeb.$formTopic does not exist");
return inlineError("form definition for <nop>$metaDataKey not found");
}

my $formDef = new Foswiki::Form($this->{session}, $formWeb, $formTopic);
unless (defined $formDef) {
print STDERR "error: can't parse form definition at $formWeb.$formTopic";
return inlineError("can't parse form definition at $formWeb.$formTopic");
}

Expand Down Expand Up @@ -359,6 +363,11 @@ sub renderMetaData {

my $fieldValue = $record->{$fieldName};

# try not to break foswiki tables
if ($theAction eq 'view') {
$fieldValue =~ s/\n/<br \/>/g;
}

$fieldSize = $params->{$fieldName.'_size'} if defined $params->{$fieldName.'_size'};
$fieldAttrs = $params->{$fieldName.'_attributes'} if defined $params->{$fieldName.'_attributes'};
$fieldDescription = $params->{$fieldName.'_tooltip'} if defined $params->{$fieldName.'_tooltip'};
Expand Down Expand Up @@ -494,9 +503,11 @@ sub renderMetaData {
$fieldDuplicateAction = ''; # TODO: disabled

my $fieldActions = '<span class="metaDataActions">'.$fieldEditAction.$fieldDuplicateAction.$fieldDeleteAction.'</div>';
my $topic = $topicObj->getPath;
$fieldActions =~ s/\%title\%/$title/g;
$fieldActions =~ s/\%name\%/$name/g;
$fieldActions =~ s/\%meta\%/$metaData/g;
$fieldActions =~ s/\%topic\%/$topic/g;

$row =~ s/\$actions\b/$fieldActions/g;
$row =~ s/\$index\b/$index/g;
Expand Down Expand Up @@ -729,11 +740,11 @@ sub sortRecords {
$item =~ s/\s*$//;
$item =~ s/^\s*//;

unless ($item =~ /^(\s*[+-]?\d+(\.?\d+)?\s*)$/) {
if ($isNumeric && $item !~ /^(\s*[+-]?\d+(\.?\d+)?\s*)$/) {
$isNumeric = 0;
}

unless (defined Foswiki::Time::parseTime($item)) {
if ($isDate && ! defined Foswiki::Time::parseTime($item)) {
$isDate = 0;
}

Expand Down
13 changes: 7 additions & 6 deletions templates/metadataplugin.tmpl
@@ -1,11 +1,12 @@
%TMPL:DEF{"metadata::edit"}%<a href="%SCRIPTURL{"rest"}%/RenderPlugin/template?topic=%WEB%.%TOPIC%&name=metadataplugin&expand=metadata::editor&metadata=%meta%&metadata::name=%name%&metadata::title=%MAKETEXT{"Edit"}% %title%" class="jqUIDialogLink metaDataEditAction {cache:false}">%JQICON{"pencil"}%</a>%TMPL:END%
%TMPL:DEF{"metadata::duplicate"}%<a href="%SCRIPTURL{"rest"}%/RenderPlugin/template?topic=%WEB%.%TOPIC%&name=metadataplugin&expand=metadata::duplicator&metadata=%meta%&metadata::name=%name%&metadata::title=%MAKETEXT{"Duplicate"}% %title%" class="jqUIDialogLink metaDataDuplicateAction {cache:false}">%JQICON{"page_white_copy"}%</a>%TMPL:END%
%TMPL:DEF{"metadata::delete"}%<a href="%SCRIPTURL{"rest"}%/RenderPlugin/template?topic=%WEB%.%TOPIC%&name=metadataplugin&expand=metadata::confirmdelete&metadata=%meta%&metadata::name=%name%&metadata::title=%title%" class="jqUIDialogLink metaDataDeleteAction {cache:false}">%JQICON{"bin"}%</a>%TMPL:END%
%TMPL:DEF{"metadata::new"}%<a href="%SCRIPTURL{"rest"}%/RenderPlugin/template?topic=%WEB%.%TOPIC%&name=metadataplugin&expand=metadata::editor&metadata=%meta%&metadata::title=%MAKETEXT{"Add"}% %meta%" class="jqUIButton jqUIDialogLink metaDataNewAction {icons: {primary:'ui-icon-circle-plus'}}">%title%</a>%TMPL:END%
%TMPL:DEF{"metadata::edit"}%<a href="%SCRIPTURL{"rest"}%/RenderPlugin/template?topic=%topic%&redirectto=%WEB%.%TOPIC%&name=metadataplugin&expand=metadata::editor&metadata=%meta%&metadata::name=%name%&metadata::title=%MAKETEXT{"Edit"}% %title%" class="jqUIDialogLink metaDataEditAction {cache:false}">%JQICON{"pencil"}%</a>%TMPL:END%
%TMPL:DEF{"metadata::duplicate"}%<a href="%SCRIPTURL{"rest"}%/RenderPlugin/template?topic=%topic%&redirectto=%WEB%.%TOPIC%&name=metadataplugin&expand=metadata::duplicator&metadata=%meta%&metadata::name=%name%&metadata::title=%MAKETEXT{"Duplicate"}% %title%" class="jqUIDialogLink metaDataDuplicateAction {cache:false}">%JQICON{"page_white_copy"}%</a>%TMPL:END%
%TMPL:DEF{"metadata::delete"}%<a href="%SCRIPTURL{"rest"}%/RenderPlugin/template?topic=%topic%&redirectto=%WEB%.%TOPIC%&name=metadataplugin&expand=metadata::confirmdelete&metadata=%meta%&metadata::name=%name%&metadata::title=%title%" class="jqUIDialogLink metaDataDeleteAction {cache:false}">%JQICON{"bin"}%</a>%TMPL:END%
%TMPL:DEF{"metadata::new"}%<a href="%SCRIPTURL{"rest"}%/RenderPlugin/template?topic=%topic%&redirectto=%WEB%.%TOPIC%&name=metadataplugin&expand=metadata::editor&metadata=%meta%&metadata::title=%MAKETEXT{"Add"}% %meta%" class="jqUIButton jqUIDialogLink metaDataNewAction {icons: {primary:'ui-icon-circle-plus'}}">%title%</a>%TMPL:END%

%TMPL:DEF{"metadata::editor"}%<!-- -->
<div title="%URLPARAM{"metadata::title" default="%MAKETEXT{"Edit"}% %URLPARAM{"metadata"}%" }%" class="jqUIDialog {modal:true, resizable:true, draggable:true, width:710}">
<form id='metaDataForm' action='%SCRIPTURL{"save"}%/%WEB%/%TOPIC%' method='post'>
<input type="hidden" name="redirectto" value="%URLPARAM{"redirectto" default="%WEB%.%TOPIC%"}%" />
%RENDERMETADATA{
"%URLPARAM{"metadata"}%"
action="edit"
Expand Down Expand Up @@ -40,15 +41,15 @@
%TMPL:DEF{"metadata::duplicator::params"}%%TMPL:P{"metadata::editor::params"}%%TMPL:END%

%TMPL:DEF{"metadata::confirmdelete"}%<!-- -->
<div title="%MAKETEXT{"Confirmation required"}%" class="jqUIDialog {modal:true, draggable:true, width:280, height:210}">
<div title="%MAKETEXT{"Confirmation required"}%" class="jqUIDialog {modal:true, draggable:true, width:280}">
<img src="%PUBURLPATH%/%SYSTEMWEB%/MetaDataPlugin/trash.png" width="48" height="48" align="right" />
%MAKETEXT{"Are you sure that you want to delete this record?"}%
%TMPL:P{"metadata::confirmdelete::details"}%<!-- -->
<form id="metaDataDeleteForm" action="%SCRIPTURL{"jsonrpc"}%/MetaDataPlugin/delete" method="post">
<input type="hidden" name="topic" value="%WEB%.%TOPIC%" />
<input type="hidden" name="metadata" value="%URLPARAM{"metadata"}%" />
<input type="hidden" name="metadata::name" value="%URLPARAM{"metadata::name"}%" />
<input type="hidden" name="redirectto" value="%WEB%.%TOPIC%" />
<input type="hidden" name="redirectto" value="%URLPARAM{"redirectto" default="%WEB%.%TOPIC%"}%" />
<a class="jqUIDialogButton jqUIDialogSubmit {icon:'ui-icon-trash'}">%MAKETEXT{"Yes, delete"}%</a>
<a class="jqUIDialogButton jqUIDialogClose {icon:'ui-icon-cancel'}">%MAKETEXT{"No, thanks"}%</a>
</form>
Expand Down

0 comments on commit 6990e56

Please sign in to comment.