move columns generation to MojoFacet::Data
authorDobrica Pavlinusic <dpavlin@rot13.org>
Sun, 4 Apr 2010 19:27:39 +0000 (21:27 +0200)
committerDobrica Pavlinusic <dpavlin@rot13.org>
Sun, 4 Apr 2010 19:27:39 +0000 (21:27 +0200)
lib/MojoFacets/Data.pm
templates/data/columns.html.ep

index 251cd64..61fb385 100644 (file)
@@ -79,9 +79,20 @@ sub load {
 sub columns {
     my $self = shift;
 
+
+       my @columns;
+       @columns = @{ $self->session('columns') } if $self->session('columns');
+
+       foreach my $c ( sort { $stats->{$b}->{count} <=> $stats->{$a}->{count} } keys %$stats ) {
+               push @columns, $c unless grep { /^\Q$c\E$/ } @columns;
+       }
+
+       $self->redirect_to( '/data/index' ) unless @columns;
+
     $self->render(
                message => 'Select columns to display',
                stats => $stats,
+               columns => \@columns,
                checked => $self->_checked( $self->_perm_array('columns') ),
        );
 }
index 64a1e36..13548eb 100644 (file)
@@ -1,10 +1,28 @@
-% layout 'default';
-<h2><%= $message %></h2>
+% layout 'ui';
+
+<style type="text/css">
+/*
+#sortable { list-style-type: none; margin: 0; padding: 0; width: 60%; }
+#sortable li { margin: 0 3px 3px 3px; padding: 0.4em; padding-left: 1.5em; font-size: 1.4em; height: 18px; }
+#sortable li span { position: absolute; margin-left: -1.3em; }
+*/
+</style>
+<script type="text/javascript">
+$(function() {
+       $("#sortable").sortable();
+       $("#sortable").disableSelection();
+});
+</script>
+
+
+
+
+<h2>Select and reorder columns</h2>
 
 <form method=post action=/data/table >
 
-<ul>
-% foreach my $n ( sort { $stats->{$b}->{count} <=> $stats->{$a}->{count} } keys %$stats ) {
+<ul id="sortable">
+% foreach my $n ( @$columns ) {
 <li>
 <label>
 <input type=checkbox name=columns value="<%= $n %>" <%= $checked->{$n} ? 'checked' : '' %>>
@@ -19,5 +37,6 @@
 </form>
 
 <pre class=debug>
+$columns = <%= dumper $columns %>
 $stats = <%= dumper $stats %>
 </pre>