added overwrite checkbox to code console
authorDobrica Pavlinusic <dpavlin@rot13.org>
Fri, 18 Jun 2010 18:19:44 +0000 (20:19 +0200)
committerDobrica Pavlinusic <dpavlin@rot13.org>
Fri, 18 Jun 2010 18:19:44 +0000 (20:19 +0200)
Newly generated code will always be saved, but modifications won't
witout user explicitly clicking on checkbox or renaming description.

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

index b8b7786..291f6fa 100644 (file)
@@ -605,6 +605,7 @@ sub items {
                }
        }
 
+       my $code_path = $self->app->home->rel_dir('public') . "/code";
        if ( $commit ) {
                warn "# commit on ", $#$filtered + 1, " items:\n$code\n";
                foreach ( 0 .. $#$filtered ) {
@@ -614,9 +615,13 @@ sub items {
                }
                if ( my $description = $self->param('code_description') ) {
                        my $depends = $self->param('code_depends') || die "no code_depends?";
-                       my $path = $self->app->home->rel_dir('public') . "/code/$depends.$description.pl";
-                       write_file $path, $code;
-                       warn "code $path ", -s $path, " bytes saved\n";
+                       my $path = "$code_path/$depends.$description.pl";
+                       if ( -e $path && ! $self->param('overwrite') ) {
+                               warn "# code $path not saved\n";
+                       } else {
+                               write_file $path, $code;
+                               warn "code $path ", -s $path, " bytes saved\n";
+                       }
                }
                $code = '';
        }
@@ -662,6 +667,7 @@ sub items {
                code_description =>
                        $self->param('code_description') ||
                        join(',', grep { defined $cols_changed->{$_} && $cols_changed->{$_} == 2 } @columns ),
+               code_path => $code_path,
        );
 
 }
index 1699ca7..d3b99c1 100644 (file)
@@ -79,6 +79,10 @@ filter
 % if ( $code_depends ) {
 <input name=code_depends type=hidden value="<%= $code_depends %>">
 <tt><%= $code_depends %>.<input name=code_description type=text value="<%= $code_description %>">.pl</tt>
+%  my $path = "$code_path/$code_depends.$code_description.pl";
+%  if ( -e $path ) {
+<input type=checkbox name=overwrite value=1 title="Overwrite old version of this code">
+%  }
 % }
 
 <input id=close name=close  type=button value="Close" style="float: right">