Skip to content

Commit

Permalink
Item12148: fixed creating an empty table with a solo EDITTABLE tag
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.foswiki.org/trunk@16147 0b4bb1d4-4e5a-0410-9cc4-b2b747904278
  • Loading branch information
CrawfordCurrie authored and CrawfordCurrie committed Dec 3, 2012
1 parent a410316 commit cb0ae8b
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 13 deletions.
6 changes: 3 additions & 3 deletions EditRowPlugin/lib/Foswiki/Plugins/EditRowPlugin/DEPENDENCIES
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Foswiki::Contrib::JSCalendarContrib,>=14754,perl,Javascript calendar module
Foswiki::Contrib::JSCalendarContrib,>0,perl,Javascript calendar module
Foswiki::Plugins::JQueryPlugin,>=4.00,perl,JQuery
Foswiki::Contrib::JEditableContrib,>1.7.1,perl,Required, JQuery plugin
Foswiki::Contrib::JEditableContrib,>0,perl,Required, JQuery plugin
ONLYIF not(eval('require Foswiki::Tables::Table'))
Foswiki::Contrib::TablesContrib,>=1.0.0,perl,Required for Foswiki < 1.2.0
Foswiki::Contrib::TablesContrib,>0,perl,Required for Foswiki < 1.2.0
2 changes: 1 addition & 1 deletion EditRowPlugin/lib/Foswiki/Plugins/EditRowPlugin/Save.pm
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ sub process {
my $minor = 0; # If true, this is a quiet save
my $no_return = 0; # if true, we want to finish editing after the action
my $no_save = 0; # if true, we are cancelling
my $clicked = $query->param('erp_action') || '';
my $clicked = join( '', $query->param('erp_action') ) || '';
if ( $clicked =~ /^#?(quiet)?(save(Table|Row|Cell)Cmd)$/ ) {
$action = $2;
$minor = $1 ? 1 : 0;
Expand Down
45 changes: 43 additions & 2 deletions EditRowPlugin/lib/Foswiki/Plugins/EditRowPlugin/Table.pm
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,6 @@ sub render {

# Disallow vertical display for whole table edits
$orientation = 'horizontal' if $wholeTable;

if ( $editing && $this->{attrs}->{js} ne 'assumed' ) {
my $format = $attrs->{format} || '';

Expand Down Expand Up @@ -217,6 +216,25 @@ sub render {

my %render_opts = ( need_tabledata => 1 );

my $fake_row = 0;
if ( $editing && scalar( @{ $this->{rows} } ) == 0 ) {

# Editing a zero-row table causes automatic creation of a single
# row. This is to support the creation of a new table in the
# presence of an EDITTABLE macro witho no data.
$this->addRow(-1);

# A row added this way will be used for an edit, so needs assigned
# cell numbers. These normally come from the raw table, but there
# isn't one when the table is being created.
my $n = 0;
foreach my $cell ( @{ $this->{rows}->[0]->{cols} } ) {
$cell->number( $n++ );
}
$fake_row = 1;
$wholeTable = 1; # it should be already; just make sure
# we need to make sure controls are added....
}
foreach my $row ( @{ $this->{rows} } ) {
my $isLard = ( $row->isHeader || $row->isFooter );
$n++ unless $isLard;
Expand All @@ -228,8 +246,10 @@ sub render {

# Render an editable row
# Get the row from the real_table, read raw from the topic
# (or use the fake_row if one was required)
my $real_row =
$opts->{real_table} ? $opts->{real_table}->{rows}->[$r] : $row;
$real_row = $row if $fake_row;
if ($real_row) {
push(
@out,
Expand Down Expand Up @@ -465,6 +485,26 @@ sub saveTableCmd {

# Whole table (sans header and footer rows)
my $end = scalar( @{ $this->{rows} } ) - $this->{attrs}->{footerrows};
if ( $end <= 0 ) {
$end = 0;

# Fabricating a new table. Sniff the URL params to determine
# the number of new rows
my $count = scalar( @{ $this->{colTypes} } );
my $rowSeen;
do {
$rowSeen = 0;
for ( my $i = 0 ; $i < $count ; $i++ ) {
my $cellName = 'erp_cell_' . $this->getID() . "_${end}_$i";
if ( defined $urps->{$cellName} ) {
$rowSeen = 1;
$this->addRow($end);
$end++;
last;
}
}
} while ($rowSeen);
}
for ( my $i = $this->{attrs}->{headerrows} ; $i < $end ; $i++ ) {
my $cols = $this->_getCols( $urps, $i );
$this->{rows}->[$i]->setRow($cols);
Expand Down Expand Up @@ -650,7 +690,8 @@ sub _makeButton {
name => 'erp_action',
value => $action,
title => $title,
class => "ui-icon ui-icon-$icon erpNoJS_button"
class => "ui-icon ui-icon-$icon erpNoJS_button",
style => "width:16px"
}
);
}
Expand Down
5 changes: 2 additions & 3 deletions EditRowPlugin/lib/Foswiki/Plugins/EditRowPlugin/TableCell.pm
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,9 @@ our @ISA = ('Foswiki::Tables::Cell');
my $defCol ||= { type => 'text', size => 20, values => [] };

sub new {
my ( $class, $row, $number, $precruft, $text, $postcruft, $ish ) = @_;
my ( $class, $row, $precruft, $text, $postcruft, $ish ) = @_;

return $class->SUPER::new( $row, $number, $precruft, $text, $postcruft,
$ish );
return $class->SUPER::new( $row, $precruft, $text, $postcruft, $ish );
}

# Row index offset by size in the columnn definition
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,7 @@ sub parse {
$postcruft = $1 if $line =~ s/(\|\s*)$//;
my @cols = split( /\|/, $line, -1 );

# my $row =
# $t->row_class->new( $t, $precruft, $postcruft, \@cols );
my $row =
$t->addRow(0); #so that the internal table bits get updated
my $row = $t->addRow(0);
$row->setRow( \@cols );
$row->isHeader(1);
$t->{headerrows} = 1;
Expand Down
3 changes: 3 additions & 0 deletions EditRowPlugin/pub/System/EditRowPlugin/erp_src.js
Original file line number Diff line number Diff line change
Expand Up @@ -189,8 +189,11 @@
// dragee and target are both TRs
var target_data = target.data('erp_data');
var dragee_data = dragee.data('erp_data');
// Can't use erp_row without a refresh - either renumber the rows,
// or compute the offset
var old_pos = dragee_data.erp_row;
var new_pos = target_data.erp_row;

var table = container.closest('table');
var move_data = $.extend({ noredirect: 1 }, target_data,
table.data('erp_data'));
Expand Down

0 comments on commit cb0ae8b

Please sign in to comment.