_row_id now include offset in dataset array
authorDobrica Pavlinusic <dpavlin@rot13.org>
Thu, 27 May 2010 10:08:28 +0000 (12:08 +0200)
committerDobrica Pavlinusic <dpavlin@rot13.org>
Thu, 27 May 2010 10:08:28 +0000 (12:08 +0200)
this allows edits to reference exact element to change

lib/MojoFacets/Data.pm
public/edit_table.js
templates/data/items/table.html.ep

index 420ecbf..7eccd2c 100644 (file)
@@ -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";
index 651f3ad..34fa44c 100644 (file)
@@ -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('<span class=d>¶</span>');
                update.replaceWith( data );
index a23e18d..b55d7c0 100644 (file)
@@ -25,7 +25,7 @@ filter
 </tr>
 
 % foreach my $row ( @$sorted ) {
-<tr>
+<tr title="<%= $row->{_row_id} %>">
 % foreach my $col ( @$columns ) {
 <td<%= $numeric->{$col} ? ' class=numeric' : '' %>>
 %  if ( ref $row->{$col} eq 'ARRAY' ) {