From: Dobrica Pavlinusic Date: Fri, 4 Jun 2010 14:59:23 +0000 (+0200) Subject: don't use $content - Mojo doesn't like it X-Git-Url: http://git.rot13.org/?a=commitdiff_plain;h=6c43b118ce8e3ba0ae5bf7210d867af17a6bb218;p=MojoFacets.git don't use $content - Mojo doesn't like it Using content variable caused last bug which caused strange serializations of perl hash when editing previously undefined value and replacing it with 0, so I just replaced it with new_content all around --- diff --git a/lib/MojoFacets/Data.pm b/lib/MojoFacets/Data.pm index b13f7a0..29c7886 100644 --- a/lib/MojoFacets/Data.pm +++ b/lib/MojoFacets/Data.pm @@ -684,7 +684,7 @@ sub facet { sub edit { my $self = shift; - my $content = $self->param('content'); + my $new_content = $self->param('new_content'); my $i = $self->param('_row_id'); die "invalid _row_id ",dump($i) unless $i =~ m/^\d+$/; @@ -695,19 +695,19 @@ sub edit { my $data = $self->_loaded('data'); if ( defined $loaded->{$path}->{data}->{items}->[$i] ) { - $content =~ s/^\s+//s; - $content =~ s/\s+$//s; + $new_content =~ s/^\s+//s; + $new_content =~ s/\s+$//s; my $v; - if ( $content =~ /\xB6/ ) { # para - $v = [ split(/\s*\xB6\s*/, $content) ]; + if ( $new_content =~ /\xB6/ ) { # para + $v = [ split(/\s*\xB6\s*/, $new_content) ]; } else { - $v = [ $content ]; + $v = [ $new_content ]; } my $old = dump $loaded->{$path}->{data}->{items}->[$i]->{$name}; my $new = dump $v; if ( $old ne $new - && ! ( $old eq 'undef' && length($content) == 0 ) # new value empty, previous undef + && ! ( $old eq 'undef' && length($new_content) == 0 ) # new value empty, previous undef ) { warn "# update $path $i $old -> $new\n"; $loaded->{$path}->{data}->{items}->[$i]->{$name} = $v; @@ -724,21 +724,23 @@ sub edit { $status = 201; # created $self->session('save_path' => $path); + + $new_content = join("\xB6",@$v); } else { warn "# unchanged $path $i $old\n"; $status = 304; } } else { - $content = "$path $i $name doesn't exist\n"; + $new_content = "$path $i $name doesn't exist\n"; $status = 404; } - warn "# edit $status $content"; + warn "# edit $status ", dump $new_content; $self->render( status => $status, - content => $content, + new_content => scalar $new_content, ); } diff --git a/public/edit_table.js b/public/edit_table.js index 67ab62b..03a1ad8 100644 --- a/public/edit_table.js +++ b/public/edit_table.js @@ -16,21 +16,21 @@ var cell_blur = function() { var x = $(this).parent().attr('cellIndex'); var y = $(this).parent().parent().attr('rowIndex'); - var content = $(this).val(); -// $(this).replaceWith( content ); + var new_content = $(this).val(); +// $(this).replaceWith( new_content ); var name = $('table tr th:nth('+x+') > a').text(); - console.info( x, y, _row_id, name, content ); + console.info( x, y, _row_id, name, new_content ); var update = $(this); $.post( '/data/edit', { path: document.title, _row_id: _row_id, - name: name, content: content + name: name, new_content: new_content } , function(data, textStatus) { console.debug( 'data:', data, 'status:', textStatus ); if ( ! data ) { - data = content; // fallback to submited data for 304 + data = new_content; // fallback to submited data for 304 } else { if ( $('a.save_changes').length == 0 ) $('a.changes').before('save') @@ -47,14 +47,14 @@ var cell_click = function(event) { , event , $(this).text() ); - var content = $(this).text() // we don't want para markup + var new_content = $(this).text() // we don't want para markup .replace(/^[ \n\r]+/,'') .replace(/[ \n\r]+$/,'') ; -console.debug( 'content', content ); - var rows = content.split('¶').length * 2 + 1; +console.debug( 'new_content', new_content ); + var rows = new_content.split('¶').length * 2 + 1; var textarea = $('