Skip to content

Commit

Permalink
Item12540:
Browse files Browse the repository at this point in the history
   * fixed dependencies on jQuery plugins
   * improved params to NEWMETADATA
   * improved table ui



git-svn-id: http://svn.foswiki.org/trunk/MetaDataPlugin@16820 0b4bb1d4-4e5a-0410-9cc4-b2b747904278
  • Loading branch information
MichaelDaum authored and MichaelDaum committed Jul 10, 2013
1 parent 665301a commit 20f168f
Show file tree
Hide file tree
Showing 6 changed files with 112 additions and 39 deletions.
6 changes: 5 additions & 1 deletion data/System/MetaDataPlugin.txt
Expand Up @@ -128,6 +128,7 @@ render a modal edit dialog according to the associated !DataForm definition.
| title | display title for the modal dialog | |
| buttontitle | display title for the button (default is =title=) | |
| hideempty | boolean flag to hide/show empty formfields | off |
| icon | name of a famfamfam icon to be used on the button | add |

---++ Registering !MetaData

Expand Down Expand Up @@ -191,9 +192,12 @@ have a database of efforts recorded on that tracker.
| Author(s): | Michael Daum|
| Copyright: | © 2011-2013 Michael Daum http://michaeldaumconsulting.com |
| License: | [[http://www.gnu.org/licenses/gpl.html][GPL (Gnu General Public License)]] |
| Release: | %$RELEASE% |
| Version: | %$VERSION% |
| Release: | %$RELEASE% |
| Change History: | <!-- versions below in reverse order -->&nbsp; |
| 10 Jul 2013: | fixed dependencies on jQuery plugins; \
improved params to NEWMETADATA; \
improved table ui |
| 14 Mar 2013: | fixed redirecting from edit |
| 01 Nov 2012: | replace TML table default format strings with HTML tables for more robustness; removed automatic \n -> &lt;br /> conversion |
| 06 Sep 2012: | implemented proper locking |
Expand Down
4 changes: 2 additions & 2 deletions lib/Foswiki/Plugins/MetaDataPlugin.pm
Expand Up @@ -24,8 +24,8 @@ use Foswiki::Contrib::JsonRpcContrib ();
use Foswiki::Plugins::MetaDataPlugin::Core();
use Error qw( :try );

our $VERSION = '3.11';
our $RELEASE = '3.11';
use version; our $VERSION = version->declare("v3.2.0");
our $RELEASE = '10 Jul 2013';
our $SHORTDESCRIPTION = 'Bring custom meta data to wiki apps';
our $NO_PREFS_IN_TOPIC = 1;
our $core;
Expand Down
36 changes: 27 additions & 9 deletions lib/Foswiki/Plugins/MetaDataPlugin/Core.pm
Expand Up @@ -64,12 +64,13 @@ sub init {

Foswiki::Plugins::JQueryPlugin::createPlugin("ui::dialog");
Foswiki::Plugins::JQueryPlugin::createPlugin("ui::button");
Foswiki::Plugins::JQueryPlugin::createPlugin("ui::validate");
Foswiki::Plugins::JQueryPlugin::createPlugin("validate");
Foswiki::Plugins::JQueryPlugin::createPlugin("blockui");
Foswiki::Plugins::JQueryPlugin::createPlugin("form");
Foswiki::Plugins::JQueryPlugin::createPlugin("jsonrpc");

#my ( $zone, $tag, $data, $requires ) = @_;
Foswiki::Func::addToZone("script", "METADATAPLUGIN", <<'EOB', "JQUERYPLUGIN, JQUERYPLUGIN::UI::DIALOG, JQUERYPLUGIN::UI::BUTTON");
Foswiki::Func::addToZone("script", "METADATAPLUGIN", <<'EOB', "JQUERYPLUGIN, JQUERYPLUGIN::UI::DIALOG, JQUERYPLUGIN::UI::BUTTON, JQUERYPLUGIN::JSONRPC");
<script src='%PUBURLPATH%/%SYSTEMWEB%/MetaDataPlugin/metadata.js'></script>
EOB

Expand Down Expand Up @@ -129,6 +130,7 @@ sub NEWMETADATA {
my $theTemplate = $params->{template} || 'metadata::new';
my $theTopic = $params->{topic} || $this->{baseWeb}.'.'.$this->{baseTopic};
my $theMap = $params->{map} || '';
my $theIcon = $params->{icon} || 'add';

foreach my $map (split(/\s*,\s*/, $theMap)) {
$map =~ s/\s*$//;
Expand All @@ -138,16 +140,20 @@ sub NEWMETADATA {
}
}

# rebuild the mapping string
my @mapping = ();
my @values = ();
foreach my $key (keys %$params) {
my $val = $params->{$key};
if ($key =~ /_title$/) {
my $val = $params->{$key};
$key =~ s/_title$//;
push @mapping, $key.'='.$val;
} elsif ($key =~ /_value$/) {
$key =~ s/_value$//;
push @values, $key.'='.$val;
}
}
$theMap = join(",", @mapping);
my $theValues = join("&", @values);

$theTitle = '%MAKETEXT{"New [_1]" args="'.ucfirst($theMetaData).'"}%' unless defined $theTitle;
$theButtonTitle = $theTitle unless defined $theButtonTitle;
Expand All @@ -168,6 +174,8 @@ sub NEWMETADATA {
$theFormat =~ s/%title%/$theTitle/g;
$theFormat =~ s/%buttontitle%/$theButtonTitle/g;
$theFormat =~ s/%map%/$theMap/g;
$theFormat =~ s/%values%/$theValues/g;
$theFormat =~ s/%icon%/$theIcon/g;

#writeDebug("done NEWMETADATA()");

Expand Down Expand Up @@ -262,6 +270,9 @@ sub renderMetaData {
my $theFilter = $params->{filter};
my $theWarn = Foswiki::Func::isTrue($params->{warn}, 1);
my $theMap = $params->{map} || '';
my $theFieldHeader = $params->{fieldheader} || '';
my $theFieldFooter = $params->{fieldfooter} || '';
my $theFieldSep = $params->{fieldseparator} || '';

foreach my $map (split(/\s*,\s*/, $theMap)) {
$map =~ s/\s*$//;
Expand Down Expand Up @@ -440,9 +451,8 @@ sub renderMetaData {
$theFieldFormat = '$value';
} else {
$theFieldFormat = ' <tr class="$metadata $name">$n'.
' <th>$title:$mandatory</th>$n'.
' <td>$n$edit$n</td>'.
' <td><div class=\'foswikiFormDescription foswikiHidden\'>$description</div></td>$n'.
' <th valign=\'top\'>$title:$mandatory</th>$n'.
' <td>$n$edit$n<div class=\'foswikiFormDescription\'>$description</div></td>'.
' </tr>';
}
}
Expand Down Expand Up @@ -496,6 +506,7 @@ sub renderMetaData {
next if defined $theExclude && $excludeMap{$name};

# loop over all fields of a record
my @fieldResult = ();
foreach my $field (@selectedFields) {
next unless $field;

Expand Down Expand Up @@ -580,11 +591,12 @@ sub renderMetaData {

if ($theAction eq 'edit') { # or get value from url (highest prio)
my $urlValue;
my $key = 'META_'.uc($metaData).'_'.$fieldName;
if ($field->isMultiValued) {
my @urlValue = $query->param('META:'.$metaData.':'.$fieldName);
my @urlValue = $query->param($key);
$urlValue = join(", ", @urlValue) if @urlValue;
} else {
$urlValue = $query->param('META:'.$metaData.':'.$fieldName);
$urlValue = $query->param($key);
}
$fieldValue = $urlValue if defined $urlValue;
}
Expand Down Expand Up @@ -685,6 +697,8 @@ sub renderMetaData {
$row =~ s/\$$fieldName/$line/g;
$row =~ s/\$orig$fieldName/$fieldValue/g;

push @fieldResult, $line;

# cleanup
$fieldClone->finish() if defined $fieldClone;
$field->{name} = $origFieldName;
Expand Down Expand Up @@ -718,8 +732,12 @@ sub renderMetaData {
$fieldActions =~ s/\%map\%/$theMap/g;
}

my $fieldResult = '';
$fieldResult = $theFieldHeader.join($theFieldSep, @fieldResult).$theFieldFooter if @fieldResult;

$row =~ s/\$actions\b/$fieldActions/g;
$row =~ s/\$index\b/$index/g;
$row =~ s/\$fields\b/$fieldResult/g;

push @result, $row;
$index++;
Expand Down
31 changes: 21 additions & 10 deletions pub/System/MetaDataPlugin/metadata.uncompressed.css
@@ -1,32 +1,43 @@
.metaDataView table {
margin-right:60px;
width:100%;
position:relative;
cursor:pointer;
border-collapse:separate;
}
.metaDataReadOnly table {
margin-right:0px;
}
.metaDataView tr.hover td {
background: #F4F4F4;
.metaDataActions,
.metaDataView table tr.hover td {
border-color:#E7B6B9 !important;
}
/*
.metaDataView tr.selected td {
background:#f2f7ff;
.metaDataActions,
.metaDataView table tr.hover td {
background-color:#FBE3E4;
}

.metaDataView tbody tr td {
border-width:1px 0px 1px 0px;
border-style:solid;
border-color:transparent;
}
*/
.metaDataActions {
display:none;
position:absolute;
right:-63px;
margin-top:-10px;
padding:5px;
right:7px;
border-style:solid;
border-width:1px 1px 0 1px;
border-radius:0.5em 0.5em 0 0;
}
.metaDataActions a {
padding:5px;
display:block;
float:left;
vertical-align:middle;
}
.hover .metaDataActions {
display:block;
}
#metaDataForm tr.name {
display:none;
}
Expand Down
71 changes: 55 additions & 16 deletions pub/System/MetaDataPlugin/metadata.uncompressed.js
Expand Up @@ -5,7 +5,7 @@
pluginName = 'metaDataView',
pluginClass = '.metaDataView',
defaults = {
actionFadeoutTime: 1000
hideActionDelay: 1500
};


Expand All @@ -23,30 +23,69 @@
return self;
};

// show actions
MetaDataView.prototype.showActions = function($row) {
var self = this,
$actions = $row.find(".metaDataActions"),
rowPos = $row.position(),
height = $actions.outerHeight()-1;

self.elem.find(".hover").removeClass("hover");
$row.addClass("hover");
$actions.show().css("top", rowPos.top-height);
};

// hide actions
MetaDataView.prototype.hideActions = function() {
var self = this;

self.elem.find(".hover").removeClass("hover");
};

// adds a hide-action timer
MetaDataView.prototype.startTimer = function() {
var self = this;
self.timeout = setTimeout(function() {
if (!self.active) {
self.hideActions();
}
}, self.opts.hideActionDelay);
};

// init method
MetaDataView.prototype.init = function() {
var self = this;

self.active = false;

self.elem.find(".metaDataActions").hover(
function() {
self.active = true;
},
function() {
self.active = false;
self.startTimer();
}
);

self.elem.find("tr")
.hover(
self.elem.find("tbody tr").hover(
function() {
var $row = $(this);
$row.addClass("hover");
self.elem.find(".metaDataActions").hide();
$row.find(".metaDataActions").show();
if (self.timeout) {
clearTimeout(self.timeout);
var $row = $(this),
$actions = $row.find(".metaDataActions");

if ($actions.length) {
self.active = true;
if (self.timeout) {
clearTimeout(self.timeout);
}
self.showActions($row);
}
},
function() {
var $row = $(this);
$row.removeClass("hover");
self.timeout = setTimeout(function() {
$row.find(".metaDataActions").stop().fadeOut();
}, self.opts.actionFadeoutTime);
self.active = false;
self.startTimer();
}
)
.click(function(e) {
).click(function(e) {
var $this = $(this),
$editAction = $this.find(".metaDataEditAction");

Expand Down
3 changes: 2 additions & 1 deletion templates/metadataplugin.tmpl
@@ -1,7 +1,8 @@
%TMPL:DEF{"metadata::edit"}%<a href="%SCRIPTURL{"rest"}%/RenderPlugin/template?topic=%topic%&name=metadataplugin&expand=metadata::editor&metadata=%meta%&metadata::name=%name%&metadata::title=%title%&map=%ENCODE{"%map%"}%&querystring=%ENCODE{"%QUERYSTRING%"}%&t=%GMTIME{"$epoch"}%" class="jqUIDialogLink metaDataEditAction {cache:false}">%JQICON{"pencil"}%</a>%TMPL:END%
%TMPL:DEF{"metadata::duplicate"}%<a href="%SCRIPTURL{"rest"}%/RenderPlugin/template?topic=%topic%&name=metadataplugin&expand=metadata::duplicator&metadata=%meta%&metadata::name=%name%&metadata::title=%title%&querystring=%ENCODE{"%QUERYSTRING%"}%&t=%GMTIME{"$epoch"}%" class="jqUIDialogLink metaDataDuplicateAction {cache:false}">%JQICON{"page_white_copy"}%</a>%TMPL:END%
%TMPL:DEF{"metadata::delete"}%<a href="%SCRIPTURL{"rest"}%/RenderPlugin/template?topic=%topic%&name=metadataplugin&expand=metadata::confirmdelete&metadata=%meta%&metadata::name=%name%&metadata::title=%title%&querystring=%ENCODE{"%QUERYSTRING%"}%&t=%GMTIME{"$epoch"}%" class="jqUIDialogLink metaDataDeleteAction {cache:false}">%JQICON{"bin"}%</a>%TMPL:END%
%TMPL:DEF{"metadata::new"}%<a href="%SCRIPTURL{"rest"}%/RenderPlugin/template?topic=%topic%&name=metadataplugin&expand=metadata::editor&metadata=%meta%&metadata::title=%title%&map=%ENCODE{"%map%"}%&querystring=%ENCODE{"%QUERYSTRING%"}%&t=%GMTIME{"$epoch"}%" class="jqUIButton jqUIDialogLink metaDataNewAction {cache:false, icons: {primary:'ui-icon-circle-plus'}}">%buttontitle%</a>%TMPL:END%
%TMPL:DEF{"DISmetadata::new"}%<a href="%SCRIPTURL{"rest"}%/RenderPlugin/template?topic=%topic%&name=metadataplugin&expand=metadata::editor&metadata=%meta%&metadata::title=%title%&map=%ENCODE{"%map%"}%&querystring=%ENCODE{"%QUERYSTRING%"}%&t=%GMTIME{"$epoch"}%" class="jqUIButton jqUIDialogLink metaDataNewAction {cache:false, icons: {primary:'%icon%'}}">%buttontitle%</a>%TMPL:END%
%TMPL:DEF{"metadata::new"}%%BUTTON{"%buttontitle%" icon="%icon%" href="%SCRIPTURL{"rest"}%/RenderPlugin/template?topic=%topic%&name=metadataplugin&expand=metadata::editor&metadata=%meta%&metadata::title=%title%&map=%ENCODE{"%map%"}%&querystring=%ENCODE{"%QUERYSTRING%"}%&%values%&t=%GMTIME{"$epoch"}%" class="jqUIDialogLink metaDataNewAction {cache:false}"}%%TMPL:END%

%TMPL:DEF{"metadata::editor"}%%IF{
"%RENDERMETADATA{"%URLPARAM{"metadata"}%" header="$islocked" footer="" format=""}%"
Expand Down

0 comments on commit 20f168f

Please sign in to comment.