Skip to content

Commit

Permalink
Item13309: fixes for TablePlugin compatibility, and an amount of simp…
Browse files Browse the repository at this point in the history
…lifcation required. Moved a function I had for formatting HTML tags up to Foswiki::Render (internal API at this stage, though we may want to publish it in 1.3)
  • Loading branch information
Comment committed Mar 30, 2015
1 parent 7ba4fb4 commit 9625fec
Show file tree
Hide file tree
Showing 32 changed files with 721 additions and 545 deletions.
63 changes: 30 additions & 33 deletions EditRowPlugin/data/System/EditRowPlugin.txt
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
%META:TOPICINFO{author="ProjectContributor" date="1427072400" format="1.1" version="1"}%
%META:TOPICINFO{author="ProjectContributor" date="1427736226" format="1.1" version="1"}%
---+!! !EditRowPlugin
<!--
One line description, required for extensions repository catalog.
* Set SHORTDESCRIPTION = Replacement for some of !EditTablePlugin, some of !EditTablerowPlugin and some of !TablePlugin.
%JQREQUIRE{"UI"}%
* Set UICON = <img class="ui-icon ui-icon-demo ui-icon-
* Set NOCIU = " style="display:inline" src="%ATTACHURLPATH%/onepixel.png"/>
# * Set UICON = <img class="ui-icon ui-icon-demo ui-icon-
# * Set NOCIU = " style="display:inline" src="%ATTACHURLPATH%/onepixel.png"/>
* Set UICON = <button type="button" class="ui-icon erp-button ui-icon-
* Set NOCIU = " ></button>
-->
<literal>
<style type="text/css">
@import url(%PUBURL%/%WEB%/%TOPIC%/erp.uncompressed.css);
</style>
</literal>

%SHORTDESCRIPTION%

Expand Down Expand Up @@ -71,8 +78,8 @@ Parameters:
* ==disable== - By default, the plugin shows both full table and individual row editing controls.
You can choose to disable one or both of these modes using the =disable= parameter, by setting it to =row= or =full=
(or =row,full= to disable all editing and just leave sorting). If full table editing is disabled, but =changerows= is =on=,
then the <img src="%ATTACHURLPATH%/edittable.png" /> (edit table) button will be replaced with a
<img src="%ATTACHURLPATH%/addrow.png" /> (add row) button. Defaults to the value of the
then the <button type="button" class="erp-edittable"></button> (edit table) button will be replaced with a
<button type="button" class="erp-addrow""></button> (add row) button. Defaults to the value of the
[[%SYSTEMWEB%.Macros][preference]] =EDITROWPLUGIN_DISABLE=, or =none= if it isn't set.
* ==buttons== - set to =left= (the default) or =right= to position edit controls in the first or last columns in the table. =buttons="right"= may be required if you are using other plugins that expect a certain column order.
* ==quietsave== - Quiet Save button is shown if ="on"=. Defaults to the
Expand Down Expand Up @@ -109,12 +116,12 @@ Parameters:
* ==helptopic== Topic name containing help text shown when editing a table. The [[VarSTARTINCLUDE][%<nop>STARTINCLUDE%]] and [[VarSTOPINCLUDE][%<nop>STOPINCLUDE%]] markers can be used in the topic to specify what is shown. Note that newlines are removed from the included text so the that text can be used inside a table.
* ==js== gives local, per-table control over the =EDITROWPLUGIN_JS= preference <a href="#js">described below</a>.
Table rows are shown with a row edit button %UICON%pencil%NOCIU% in the first column,
and a table edit button <img src="%ATTACHURLPATH%/edittable.png" /> after the
and a table edit button <button type="button" class="erp-edittable"></button> after the
table. When the table is
edited, then a number of buttons may be shown depending on the
settings of =changerows= and =quietsave=.
* %UICON%disk%NOCIU% saves the changes
* <img src="%ATTACHURLPATH%/quiet.png" /> saves without notification
* <button type="button" class="erp-button erp-quietsave"></button> saves without notification
* %UICON%plusthick%NOCIU% adds a new row after the current row, taking for its contents the initial values specified in the EDITTABLE macro
* %UICON%minusthick%NOCIU% deletes the row
* %UICON%arrow-1-n%NOCIU% Move this row up one row in the table
Expand Down Expand Up @@ -182,7 +189,7 @@ then="enabled in this site. Click on the buttons to try it out."}%
=%<nop>EDITTABLE{ format="| text,12 | textarea, 3x30 |" js="assumed"}%= <br />
<img src="%ATTACHURLPATH%/screenshot2.png"></div>
When a table is editable and Javascript is enabled, then when the user rolls the mouse over a table row:
* individual table cells have a yellow stain <img src="%ATTACHURL%/editbutton.png"> on the corner that can be clicked to open an in-place editor,
* individual table cells have a yellow stain <button type="button" class="erp-editbutton"></button> on the corner that can be clicked to open an in-place editor,
* table rows *that contain at least one editable cell* can be manually sorted using drag-and-drop, by dragging the %UICON%arrowthick-2-n-s%NOCIU% (though beware that a =TABLE= tag with an =initsort= will override this, which can be confusing),
Table columns can be sorted in the browser, by clicking the heading above the row.

Expand Down Expand Up @@ -259,6 +266,7 @@ Provides the vertical row editing interface like
Another great Foswiki extension from the <a style="text-decoration:none" href="http://wikiring.com"><img src="%ATTACHURLPATH%/wikiringlogo20x20.png" alt="" /> *WikiRing* </a> - working together to improve your wiki experience!

| Change History: | <!-- versions below in reverse order -->&nbsp; |
| 3.200 (30 Mar 2015) | Foswikitask:13309: fixed for compatibility with !TablePlugin |
| 3.100 (18 Dec 2014) | Foswikitask:Item12855: Core extensions should require JQueryPlugin 6.00<br />\
Foswikitask:Item13125: Support Request multi_param<br />\
Foswikitask:Item13115: Don't require JQuery theme<br />\
Expand Down Expand Up @@ -308,28 +316,17 @@ Another great Foswiki extension from the <a style="text-decoration:none" href="h
%META:FIELD{name="License" title="License" value="[[http://www.gnu.org/licenses/gpl.html][GPL (Gnu General Public License)]]"}%
%META:FIELD{name="Home" title="Home" value="http://foswiki.org/Extensions/EditRowPlugin"}%
%META:FIELD{name="Support" title="Support" value="http://foswiki.org/Support/EditRowPlugin"}%
%META:FILEATTACHMENT{name="addrow.png" attr="h" autoattached="1" comment="" date="1427072400" size="425" user="ProjectContributor" version="1"}%
%META:FILEATTACHMENT{name="edittopic.png" attr="h" comment="" user="ProjectContributor" date="1427072400" size="280" version="1"}%
%META:FILEATTACHMENT{name="clock.gif" attr="h" comment="" user="ProjectContributor" date="1427072400" size="1418" version="1"}%
%META:FILEATTACHMENT{name="onepixel.png" attr="h" comment="" user="ProjectContributor" date="1427072400" size="101" version="1"}%
%META:FILEATTACHMENT{name="plus.png" attr="h" comment="" user="ProjectContributor" date="1427072400" size="163" version="1"}%
%META:FILEATTACHMENT{name="screenshot2.png" attr="h" autoattached="1" comment="" date="1427072400" size="12013" user="ProjectContributor" version="1"}%
%META:FILEATTACHMENT{name="example5.png" attr="h" autoattached="1" comment="" date="1427072400" size="9132" user="ProjectContributor" version="1"}%
%META:FILEATTACHMENT{name="example4.png" attr="h" autoattached="1" comment="" date="1427072400" size="22834" user="ProjectContributor" version="1"}%
%META:FILEATTACHMENT{name="stop.png" attr="h" comment="" user="ProjectContributor" date="1427072400" size="248" version="1"}%
%META:FILEATTACHMENT{name="quiet.png" attr="h" autoattached="1" comment="" date="1427072400" size="356" user="ProjectContributor" version="1"}%
%META:FILEATTACHMENT{name="editbutton.png" attr="h" comment="" user="ProjectContributor" date="1427072400" size="357" version="1"}%
%META:FILEATTACHMENT{name="screenshot1.png" attr="h" autoattached="1" comment="" date="1427072400" size="19461" user="ProjectContributor" version="1"}%
%META:FILEATTACHMENT{name="arrowdown.png" attr="h" comment="" user="ProjectContributor" date="1427072400" size="185" version="1"}%
%META:FILEATTACHMENT{name="TableSort.js" attr="h" comment="" user="ProjectContributor" date="1427072400" size="3956" version="1"}%
%META:FILEATTACHMENT{name="erp.uncompressed.js" attr="h" comment="" user="ProjectContributor" date="1427072400" size="23426" version="1"}%
%META:FILEATTACHMENT{name="erp.css" attr="h" comment="" user="ProjectContributor" date="1427072400" size="875" version="1"}%
%META:FILEATTACHMENT{name="edittable.png" attr="h" autoattached="1" comment="" date="1427072400" size="3287" user="ProjectContributor" version="1"}%
%META:FILEATTACHMENT{name="wikiringlogo20x20.png" attr="h" autoattached="1" comment="" date="1427072400" size="1343" user="ProjectContributor" version="1"}%
%META:FILEATTACHMENT{name="TableSort.uncompressed.js" attr="h" comment="" user="ProjectContributor" date="1427072400" size="11219" version="1"}%
%META:FILEATTACHMENT{name="minus.png" attr="h" comment="" user="ProjectContributor" date="1427072400" size="157" version="1"}%
%META:FILEATTACHMENT{name="save.png" attr="h" comment="" user="ProjectContributor" date="1427072400" size="292" version="1"}%
%META:FILEATTACHMENT{name="arrowup.png" attr="h" comment="" user="ProjectContributor" date="1427072400" size="190" version="1"}%
%META:FILEATTACHMENT{name="erp.uncompressed.css" attr="h" comment="" user="ProjectContributor" date="1427072400" size="1328" version="1"}%
%META:FILEATTACHMENT{name="erp.js" attr="h" comment="" user="ProjectContributor" date="1427072400" size="10286" version="1"}%
%META:FILEATTACHMENT{name="example3.png" attr="h" autoattached="1" comment="" date="1427072400" size="15337" user="ProjectContributor" version="1"}%
%META:FILEATTACHMENT{name="clock.gif" attr="h" user="ProjectContributor" date="1427736226" version="1"}%
%META:FILEATTACHMENT{name="erp.css" attr="h" user="ProjectContributor" date="1427736226" version="1"}%
%META:FILEATTACHMENT{name="erp.js" attr="h" user="ProjectContributor" date="1427736226" version="1"}%
%META:FILEATTACHMENT{name="erp.uncompressed.js" attr="h" user="ProjectContributor" date="1427736226" version="1"}%
%META:FILEATTACHMENT{name="erp.uncompressed.css" attr="h" user="ProjectContributor" date="1427736226" version="1"}%
%META:FILEATTACHMENT{name="example3.png" attr="h" date="1427736226" user="ProjectContributor" version="1"}%
%META:FILEATTACHMENT{name="example4.png" attr="h" date="1427736226" user="ProjectContributor" version="1"}%
%META:FILEATTACHMENT{name="example5.png" attr="h" date="1427736226" user="ProjectContributor" version="1"}%
%META:FILEATTACHMENT{name="icons.png" attr="h" user="ProjectContributor" date="1427736226" version="1"}%
%META:FILEATTACHMENT{name="screenshot1.png" attr="h" date="1427736226" user="ProjectContributor" version="1"}%
%META:FILEATTACHMENT{name="screenshot2.png" attr="h" date="1427736226" user="ProjectContributor" version="1"}%
%META:FILEATTACHMENT{name="TableSort.js" attr="h" user="ProjectContributor" date="1427736226" version="1"}%
%META:FILEATTACHMENT{name="TableSort.uncompressed.js" attr="h" user="ProjectContributor" date="1427736226" version="1"}%
%META:FILEATTACHMENT{name="wikiringlogo20x20.png" attr="h" date="1427736226" user="ProjectContributor" version="1"}%
25 changes: 22 additions & 3 deletions EditRowPlugin/lib/Foswiki/Plugins/EditRowPlugin.pm
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
package Foswiki::Plugins::EditRowPlugin;

use strict;
use Foswiki::Request;
use Foswiki::Request ();
use Foswiki::Render ();

BEGIN {
# Backwards compatibility for Foswiki 1.1.x
Expand All @@ -11,10 +12,28 @@ BEGIN {
*Foswiki::Request::multi_param = \&Foswiki::Request::param;
use warnings 'redefine';
}

unless ( defined &Foswiki::Render::html ) {
*Foswiki::Render::html = sub {
my ( $tag, $attrs, $innerHTML ) = @_;
my $html = "<$tag";
if ($attrs) {

# SMELL: make the sort conditional on DEBUG
foreach my $k ( sort keys %$attrs ) {
my $v = $attrs->{$k};
$v =~ s/([&<>"\x8b\x9b'])/'&#'.ord($1).';'/ge;
$html .= " $k=\"$v\"";
}
}
$innerHTML = '' unless defined $innerHTML;
return "$html>$innerHTML</$tag>";
}
}
}

our $VERSION = '3.100';
our $RELEASE = '18 Dec 2014';
our $VERSION = '3.300';
our $RELEASE = '30 Mar 2015';
our $SHORTDESCRIPTION = 'Inline edit for tables';
our $NO_PREFS_IN_TOPIC = 1;

Expand Down
26 changes: 17 additions & 9 deletions EditRowPlugin/lib/Foswiki/Plugins/EditRowPlugin/Editor.pm
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,10 @@ Generate an HTML editor for the cell

sub htmlEditor {
my ( $this, $cell, $colDef, $inRow, $unexpandedValue ) = @_;
return CGI::textfield(
return Foswiki::Render::html(
'input',
{
type => 'text',
class => 'erpJS_input',
name => $cell->getElementName(),
size => $colDef->{size} || 10,
Expand Down Expand Up @@ -82,21 +84,27 @@ sub jQueryMetadata {
# Used by subclasses
sub _addSaveButton {
my ( $this, $data ) = @_;
my $purl = Foswiki::Func::getPubUrlPath();

# JS will rewrite this URL to some HTML
$data->{submitimg} =
"$purl/$Foswiki::cfg{SystemWebName}/EditRowPlugin/save.png";
$data->{submit} = Foswiki::Render::html(
'button',
{
type => 'submit',
class => 'ui-icon ui-icon-disk erp-button'
}
);
}

# Used by subclasses
sub _addCancelButton {
my ( $this, $data ) = @_;
my $purl = Foswiki::Func::getPubUrlPath();

# JS will rewrite this URL to some HTML
$data->{cancelimg} =
"$purl/$Foswiki::cfg{SystemWebName}/EditRowPlugin/stop.png";
$data->{cancel} = Foswiki::Render::html(
'button',
{
type => 'submit',
class => 'ui-icon erp-button ui-icon-cancel'
}
);
}

=begin TML
Expand Down
21 changes: 11 additions & 10 deletions EditRowPlugin/lib/Foswiki/Plugins/EditRowPlugin/Editor/select.pm
Original file line number Diff line number Diff line change
Expand Up @@ -19,24 +19,25 @@ sub htmlEditor {
my $expandedValue = Foswiki::Func::expandCommonVariables($unexpandedValue);
$expandedValue =~ s/^\s*(.*?)\s*$/$1/;

# Explicit HTML used because CGI gets it wrong
my $text =
"<select name='"
. $cell->getElementName()
. "' size='"
. $colDef->{size}
. "' class='erpJS_input'>";
my $options;
foreach my $option ( @{ $colDef->{values} } ) {
my $expandedOption = Foswiki::Func::expandCommonVariables($option);
$expandedOption =~ s/^\s*(.*?)\s*$/$1/;
my %opts;
if ( $expandedOption eq $expandedValue ) {
$opts{selected} = 'selected';
}
$text .= CGI::option( \%opts, $option );
$options .= Foswiki::Render::html( 'option', \%opts, $option );
}
$text .= "</select>";
return $text;
return Foswiki::Render::html(
'select',
{
name => $cell->getElementName(),
size => $colDef->{size},
class => 'erpJS_input'
},
$options
);
}

sub jQueryMetadata {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ sub jQueryMetadata {
# URL of rest handler that provides text
$data->{loadurl} = Foswiki::Func::getScriptUrl(
'EditRowPlugin', 'get', 'rest',
%{ $cell->{row}->{table}->getURLParams() },
%{ $cell->{row}->getURLParams() },
%{ $cell->getURLParams() }
$cell->{row}->{table}->getParams('erp_'),
$cell->{row}->getParams('erp_'),
$cell->getParams('erp_')
);

# JEditable "text" type requires "width" not "size"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ sub htmlEditor {
$tmptext =~ s#<br( /)?>#\r\n#gi;
$tmptext =~ s/%BR%/\r\n/gi;

return CGI::textarea(
return Foswiki::Plugins::editRowPlugin::html(
'textarea',
{
class => 'erpJS_input',
rows => $rows,
Expand Down
15 changes: 2 additions & 13 deletions EditRowPlugin/lib/Foswiki/Plugins/EditRowPlugin/MANIFEST
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
!noci
data/System/EditRowPlugin.txt 0755
data/System/EditRowPluginExamples.txt 0644
lib/Foswiki/Configure/Checkers/Plugins/EditRowPlugin/Enabled.pm 0644
Expand All @@ -24,27 +25,15 @@ lib/Foswiki/Plugins/EditRowPlugin/TableRow.pm 0644
lib/Foswiki/Plugins/EditRowPlugin/View.pm 0644
pub/System/EditRowPlugin/TableSort.js 0644
pub/System/EditRowPlugin/TableSort.uncompressed.js 0644
pub/System/EditRowPlugin/addrow.png 0644
pub/System/EditRowPlugin/arrowdown.png 0644
pub/System/EditRowPlugin/arrowup.png 0644
pub/System/EditRowPlugin/clock.gif 0644
pub/System/EditRowPlugin/editbutton.png 0644
pub/System/EditRowPlugin/edittable.png 0644
pub/System/EditRowPlugin/edittopic.png 0644
pub/System/EditRowPlugin/erp.css 0644
pub/System/EditRowPlugin/erp.uncompressed.css 0644
pub/System/EditRowPlugin/erp.js 0644
pub/System/EditRowPlugin/erp.uncompressed.js 0644
pub/System/EditRowPlugin/example3.png 0644
pub/System/EditRowPlugin/example4.png 0644
pub/System/EditRowPlugin/example5.png 0644
pub/System/EditRowPlugin/minus.png 0644
pub/System/EditRowPlugin/onepixel.png 0644
pub/System/EditRowPlugin/plus.png 0644
pub/System/EditRowPlugin/quiet.png 0644
pub/System/EditRowPlugin/save.png 0644
pub/System/EditRowPlugin/icons.png 0644
pub/System/EditRowPlugin/screenshot1.png 0644
pub/System/EditRowPlugin/screenshot2.png 0644
pub/System/EditRowPlugin/stop.png 0644
pub/System/EditRowPlugin/wikiringlogo20x20.png 0644

Loading

0 comments on commit 9625fec

Please sign in to comment.