From eb91b48c88ce4008232c700a023d9481be5e97d8 Mon Sep 17 00:00:00 2001 From: Dobrica Pavlinusic Date: Thu, 27 May 2010 12:08:28 +0200 Subject: [PATCH] _row_id now include offset in dataset array this allows edits to reference exact element to change --- lib/MojoFacets/Data.pm | 5 ++++- public/edit_table.js | 9 ++++++--- templates/data/items/table.html.ep | 2 +- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/lib/MojoFacets/Data.pm b/lib/MojoFacets/Data.pm index 420ecbf..7eccd2c 100644 --- a/lib/MojoFacets/Data.pm +++ b/lib/MojoFacets/Data.pm @@ -522,7 +522,10 @@ sub items { my $i = $_ + $offset; last unless defined $filtered->[$i]; $i = $from_end - $i if $from_end; - push @$sorted_items, $data->{items}->[ $filtered->[$i] ]; + my $id = $filtered->[$i]; + push @$sorted_items, + my $item = $data->{items}->[ $id ]; + $item->{_row_id} ||= $id; } warn "# sorted_items ", $#$sorted_items + 1, " offset $offset limit $limit order $sort"; diff --git a/public/edit_table.js b/public/edit_table.js index 651f3ad..34fa44c 100644 --- a/public/edit_table.js +++ b/public/edit_table.js @@ -6,9 +6,12 @@ var cell_blur = function() { // , $(this).val() ); +/* // FIXME primary key is fixed to 1st column var pk = $('table tr th:nth(0) > a').text(); var id = $(this).parent().siblings(':nth(0)').text() +*/ + var _row_id = $(this).parent().parent().attr('title'); var x = $(this).parent().attr('cellIndex'); var y = $(this).parent().parent().attr('rowIndex'); @@ -17,15 +20,15 @@ var cell_blur = function() { // $(this).replaceWith( content ); var name = $('table tr th:nth('+x+') > a').text(); - console.info( x, y, pk, id, name, content ); + console.info( x, y, _row_id, name, content ); var update = $(this); $.post( '/data/edit', { - path: document.title, pk: pk, id: id, + path: document.title, _row_id: _row_id, name: name, content: content } , function(data) { - console.debug( data ); + console.debug( 'server data', data ); var vals = content.split('¶'); data = vals.join('¶'); update.replaceWith( data ); diff --git a/templates/data/items/table.html.ep b/templates/data/items/table.html.ep index a23e18d..b55d7c0 100644 --- a/templates/data/items/table.html.ep +++ b/templates/data/items/table.html.ep @@ -25,7 +25,7 @@ filter % foreach my $row ( @$sorted ) { - + % foreach my $col ( @$columns ) { {$col} ? ' class=numeric' : '' %>> % if ( ref $row->{$col} eq 'ARRAY' ) { -- 2.20.1