create save link
authorDobrica Pavlinusic <dpavlin@rot13.org>
Thu, 27 May 2010 14:32:41 +0000 (16:32 +0200)
committerDobrica Pavlinusic <dpavlin@rot13.org>
Thu, 27 May 2010 14:32:41 +0000 (16:32 +0200)
This allows us to preserve our changes in storable dump

lib/MojoFacets/Data.pm
public/edit_table.js
public/mojo_facets.css
templates/admin.html.ep

index 316e37e..41134cb 100644 (file)
@@ -63,6 +63,7 @@ sub _save {
        utime $mtime, $mtime, $dump_path;
 
        warn $dump_path, ' ', -s $dump_path, " bytes\n";
+       return $dump_path;
 }
 
 sub _load_path {
@@ -696,6 +697,7 @@ sub edit {
                        }
 
                        $status = 201; # created
+                       $self->session('save_path' => $path);
 
                } else {
                        warn "# unchanged $path $i $old\n";
@@ -713,4 +715,16 @@ sub edit {
        );
 }
 
+
+sub save {
+       my $self = shift;
+       my $path = $self->param('path');
+       $path  ||= $self->session('path');
+
+       my $dump_path = $self->_save( $path );
+       $self->session('save_path' => 0);
+
+       $self->redirect_to( '/data/items' );
+}
+
 1;
index 326891f..b9e9959 100644 (file)
@@ -28,8 +28,12 @@ var cell_blur = function() {
                path: document.title, _row_id: _row_id,
                name: name, content: content
        } , function(data, textStatus) {
-               if ( data.length == 0 ) data = content; // 304 doesn't return content
                console.debug( 'data:', data, 'status:', textStatus );
+               if ( ! data ) {
+                       data = content; // fallback to submited data for 304
+               } else {
+                       $('a.changes').before('<a class=save_changes href="/data/save">save</a>')
+               }
                var vals = data.split('¶');
                data = vals.join('<span class=d>¶</span>');
                update.replaceWith( data );
index ab09c72..80c8c76 100644 (file)
@@ -52,6 +52,12 @@ span.h {
        float: right;
 }
 
+.admin .save_changes {
+       float: right;
+       color: #f00;
+       padding-left: 1em;
+}
+
 .debug {
        color: #aaa;
 }
index 2ae6554..9dc92f0 100644 (file)
@@ -9,6 +9,9 @@ items:
 <a href="<%= url_for( controller => 'data', action => 'items' )->query( show => $show ) %>" <%= $class %>><%= $show %></a>
 % }
 
+% if ( my $path = session('save_path') ) {
+<a class=save_changes title="<%= $path %>" href="<%= url_for( controller => 'data', action => 'save', path => $path ) %>">save</a>
+% }
 <a class=changes href="<%= url_for( controller => 'changes', action => 'index' ) %>">changes</a>
 
 </div>