Skip to content

Commit

Permalink
Item10410: disable sorting if =sort="off"= is set in =TABLEPLUGIN_TAB…
Browse files Browse the repository at this point in the history
…LEATTRIBUTES=

git-svn-id: http://svn.foswiki.org/branches/Release01x01@10902 0b4bb1d4-4e5a-0410-9cc4-b2b747904278
  • Loading branch information
ArthurClemens authored and ArthurClemens committed Mar 4, 2011
1 parent 10db9d6 commit ea424d1
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 71 deletions.
1 change: 1 addition & 0 deletions TablePlugin/data/System/TablePlugin.txt
Expand Up @@ -178,6 +178,7 @@ Sort icons in the header are read from System.DocumentGraphics.
| Version: | %$VERSION% |
| Release: | %$RELEASE% |
| Change History: | <!-- specify latest version first -->&nbsp; |
| 04 Mar 2011 | 1.128: Arthur Clemens: disable sorting if =sort="off"= is set in =TABLEPLUGIN_TABLEATTRIBUTES=. |
| 16 Feb 2011 | 1.127: Michael Daum: Foswikitask:Item10357: only emit inline css when there's a foswikiTable on the current page |
| 18 Aug 2010 | 1.126: Paul harvey: Foswikitask:Item9415: minor documentation changes |
| 09 Aug 2010 | 1.125: Crawford Currie: Foswikitask:Item8303: fixed sorting with multiple headers |
Expand Down
4 changes: 3 additions & 1 deletion TablePlugin/lib/Foswiki/Plugins/TablePlugin.pm
Expand Up @@ -9,7 +9,7 @@ use strict;
use warnings;

our $VERSION = '$Rev$';
our $RELEASE = '1.127';
our $RELEASE = '1.128';
our $SHORTDESCRIPTION =
'Control attributes of tables and sorting of table columns';
our $NO_PREFS_IN_TOPIC = 1;
Expand Down Expand Up @@ -42,6 +42,8 @@ sub initPlugin {

$initialised = 0;

debug( 'TablePlugin', "inited" );

return 1;
}

Expand Down
145 changes: 75 additions & 70 deletions TablePlugin/lib/Foswiki/Plugins/TablePlugin/Core.pm
Expand Up @@ -17,7 +17,7 @@ my $didWriteDefaultStyle;
my $defaultAttrs; # to write generic table CSS
my $tableSpecificAttrs; # to write table specific table CSS
my $combinedTableAttrs; # default and specific table attributes
my $styles = {}; # hash of default and specific styles
my $styles = {}; # hash of default and specific styles
my $doneDefaults = 0;

# not yet refactored:
Expand Down Expand Up @@ -120,7 +120,7 @@ $TABLE_FRAME->{border} = 'border-style:solid';

BEGIN {
$translationToken = "\0";
$doneDefaults = 0;
$doneDefaults = 0;

# the maximum number of columns we will handle
$MAX_SORT_COLS = 10000;
Expand Down Expand Up @@ -225,37 +225,11 @@ sub _parseTableSpecificTableAttributes {
=cut

sub _cleanParamValue {
my ($inValue) = @_;

return undef if !$inValue;

$inValue =~ s/ //go; # remove spaces
return $inValue;
}

=pod
=cut

sub _arrayRefFromParam {
my ($inValue) = @_;

return undef if !$inValue;

$inValue =~ s/ //go; # remove spaces
my @list = split( /,/, $inValue );
return \@list;
}

=pod
=cut

sub _parseAttributes {
my ( $modeSpecific, $inCollection, $inParams ) = @_;
my ( $isTableSpecific, $inCollection, $inParams ) = @_;

_debugData( "modeSpecific=$modeSpecific; _parseAttributes=", $inParams );
_debugData( "isTableSpecific=$isTableSpecific; _parseAttributes=",
$inParams );

# include topic to read definitions
my $includeTopicParam = $inParams->{include};
Expand All @@ -266,44 +240,44 @@ sub _parseAttributes {

_storeAttribute( 'generateInlineMarkup',
Foswiki::Func::isTrue( $inParams->{inlinemarkup} ),
$inCollection ) if defined $inParams->{inlinemarkup};

$inCollection )
if defined $inParams->{inlinemarkup};

# sort attributes
if ($modeSpecific) {
my $sort = Foswiki::Func::isTrue( $inParams->{sort} || 'on' );
_storeAttribute( 'sort', $sort, $inCollection );
_storeAttribute( 'initSort', $inParams->{initsort}, $inCollection )
if defined( $inParams->{initsort} )
and $inParams->{initsort} =~ /\s*[0-9]+\s*/;
_storeAttribute( 'sortAllTables', $sort, $inCollection );
if ( $inParams->{initdirection} ) {
_storeAttribute( 'initDirection', $SORT_DIRECTION->{'ASCENDING'},
$inCollection )
if $inParams->{initdirection} =~ /^down$/i;
_storeAttribute( 'initDirection', $SORT_DIRECTION->{'DESCENDING'},
$inCollection )
if $inParams->{initdirection} =~ /^up$/i;
}
my $sort = Foswiki::Func::isTrue( $inParams->{sort} || 'on' );
_debug("sort=$sort");
_storeAttribute( 'sort', $sort, $inCollection );
_storeAttribute( 'initSort', $inParams->{initsort}, $inCollection )
if defined( $inParams->{initsort} )
and $inParams->{initsort} =~ /\s*[0-9]+\s*/;
_storeAttribute( 'sortAllTables', $sort, $inCollection );
if ( $inParams->{initdirection} ) {
_storeAttribute( 'initDirection', $SORT_DIRECTION->{'ASCENDING'},
$inCollection )
if $inParams->{initdirection} =~ /^down$/i;
_storeAttribute( 'initDirection', $SORT_DIRECTION->{'DESCENDING'},
$inCollection )
if $inParams->{initdirection} =~ /^up$/i;
}

# If EditTablePlugin is installed and we are editing a table,
# the CGI parameter 'sort' is defined as "off" to disable all
# header sorting ((Item5135)
my $cgi = Foswiki::Func::getCgiQuery();
my $urlParamSort = $cgi->param('sort');
if ( $urlParamSort && $urlParamSort =~ /^off$/oi ) {
delete $inCollection->{sortAllTables};
}
# If EditTablePlugin is installed and we are editing a table,
# the CGI parameter 'sort' is defined as "off" to disable all
# header sorting ((Item5135)
my $cgi = Foswiki::Func::getCgiQuery();
my $urlParamSort = $cgi->param('sort');
if ( $urlParamSort && $urlParamSort =~ /^off$/oi ) {
delete $inCollection->{sortAllTables};
}

# If EditTablePlugin is installed and we are editing a table, the
# 'disableallsort' TABLE parameter is added to disable initsort and header
# sorting in the table that is being edited. (Item5135)
if ( Foswiki::Func::isTrue( $inParams->{disableallsort} ) ) {
$inCollection->{sortAllTables} = 0;
delete $inCollection->{initSort};
}
# If EditTablePlugin is installed and we are editing a table, the
# 'disableallsort' TABLE parameter is added to disable initsort and header
# sorting in the table that is being edited. (Item5135)
if ( Foswiki::Func::isTrue( $inParams->{disableallsort} ) ) {
$inCollection->{sortAllTables} = 0;
delete $inCollection->{initSort};
}

if ($modeSpecific) {
if ($isTableSpecific) {

_storeAttribute( 'summary', $inParams->{summary}, $inCollection );
my $id = $inParams->{id}
Expand Down Expand Up @@ -1460,6 +1434,7 @@ sub emitTable {
my $singleIndent = "\n\t";
my $doubleIndent = "\n\t\t";
my $tripleIndent = "\n\t\t\t";

# Only *one* row of the table has sort links, and it will either
# be the last row in the header or the first row in the footer.
my $sortLinksWritten = 0;
Expand All @@ -1470,8 +1445,8 @@ sub emitTable {

# keep track of header cells: if all cells are header cells, do not
# update the data color count
my $headerCellCount = 0;
my $numberOfCols = scalar(@$row);
my $headerCellCount = 0;
my $numberOfCols = scalar(@$row);
my $writingSortLinks = 0;

foreach my $fcell (@$row) {
Expand Down Expand Up @@ -1566,10 +1541,13 @@ sub emitTable {

# END html attribute

if ( $sortThisTable
&& (!$combinedTableAttrs->{headerrows}
|| $rowCount == $combinedTableAttrs->{headerrows} - 1)
&& ($writingSortLinks || !$sortLinksWritten)) {
if (
$sortThisTable
&& ( !$combinedTableAttrs->{headerrows}
|| $rowCount == $combinedTableAttrs->{headerrows} - 1 )
&& ( $writingSortLinks || !$sortLinksWritten )
)
{
$writingSortLinks = 1;
my $linkAttributes = {
href => $url
Expand Down Expand Up @@ -1869,6 +1847,33 @@ sub _mergeHashes {

=pod
=cut

sub _cleanParamValue {
my ($inValue) = @_;

return undef if !$inValue;

$inValue =~ s/ //go; # remove spaces
return $inValue;
}

=pod
=cut

sub _arrayRefFromParam {
my ($inValue) = @_;

return undef if !$inValue;

$inValue =~ s/ //go; # remove spaces
my @list = split( /,/, $inValue );
return \@list;
}

=pod
Shorthand debugging call.
=cut
Expand Down

0 comments on commit ea424d1

Please sign in to comment.