/[Frey]/trunk/lib/Frey/DBIC/Designer.pm
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /trunk/lib/Frey/DBIC/Designer.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1024 by dpavlin, Mon Jan 26 23:37:34 2009 UTC revision 1036 by dpavlin, Sun Feb 8 12:24:17 2009 UTC
# Line 5  extends 'Frey'; Line 5  extends 'Frey';
5  with 'Frey::Web';  with 'Frey::Web';
6  with 'Frey::Config';  with 'Frey::Config';
7  with 'Frey::Storage';  with 'Frey::Storage';
8    with 'Frey::jQuery';
9    
10  has dbic_class => (  has dbic_class => (
11          is => 'rw',          is => 'rw',
# Line 41  has page => ( Line 42  has page => (
42          default => 1,          default => 1,
43  );  );
44    
45  has remove_column => (  has columns => (
46            is => 'rw',
47            isa => 'ArrayRef[Str]',
48    );
49    
50    has dnd_serialize => (
51          is => 'rw',          is => 'rw',
52          isa => 'Str',          isa => 'Str',
53  );  );
# Line 73  sub as_markup { Line 79  sub as_markup {
79                  ->search( undef, $attrs )                  ->search( undef, $attrs )
80                  ;                  ;
81    
82          my $path = 'var/DBIC/' . $self->result_set . '.yaml';          my @columns = @{ $self->columns } if $self->columns;
83          my @columns;          my @all_columns = $rs->first->columns;
84          {          @columns = @all_columns unless @columns;
                 my $c = $self->load( $path );  
                 @columns = @$c if $c;  
         }  
         warn "# load $path columns ", $self->dump( @columns );  
         @columns = $rs->first->columns unless @columns;  
   
         @columns = grep { $_ ne $self->remove_column } @columns if $self->remove_column;  
   
85          warn "# columns ", $self->dump( @columns );          warn "# columns ", $self->dump( @columns );
         $self->store( $path, [ @columns ] );  
86    
87          my $rows;          my $rows;
88    
89          while ( my $feed = $rs->next ) {          while ( my $row = $rs->next ) {
90  #               my %row = $feed->get_columns;  #               my %row = $row->get_columns;
91    
92                  my $row;                  my $row;
93    
94                  foreach my $name ( @columns ) {                  foreach my $name ( @columns ) {
95                          my $v = $feed->$name;                          my $v = $row->$name;
96                          $v = '<code>NULL</code>' if ! defined $v;                          $v = '<code>NULL</code>' if ! defined $v;
97                          $row .= qq|<td title="$name">$v</td>|;                          $row .= qq|<td title="$name">$v</td>|;
98                  }                  }
99    
100                    my $feed;
101                    if ( $feed = $row->feed ) {
102                            $row .= qq|<td> $feed->title </td>|;
103                    }
104    
105                  $rows .= qq|<tr>$row</tr>\n|;                  $rows .= qq|<tr>$row</tr>\n|;
106          }          }
107    
108          my $total = $rs->pager->total_entries;          $self->add_css(qq|
109                    #column-editor {
110                            border: 1px solid #888;
111                            background: #ffc;
112                            position: absolute;
113                            top: 1em;
114                            right: 1em;
115                            z-index: 10;
116                            opacity: .2;
117                            filter: alpha(opacity=20);
118                    }
119                    #column-editor:hover {
120                            opacity: 1;
121                            filter: alpha(opacity=100);
122                    }
123                    #column-editor small {
124                            color: #888;
125                    }
126            |);
127    
128            my $visible_columns;
129            $visible_columns->{$_}++ foreach @columns;
130    
131          sub form {          @all_columns = (
132                  my $column = shift || die;                  # dnd_serialize is in php format id[]=foo&id[]=bar
133                    map { s/[^=]+=// ; $_ } split(/&/, $self->dnd_serialize )
134            ) if $self->dnd_serialize;
135            warn "# column-editor for ", $self->dump( @all_columns );
136    
137            my $dnd_serialize = join('&', @all_columns);
138            my $column_editor = qq|
139                    <form id="column-editor" method="get"><!-- FIXME we really should do post, but it doesn't work! -->
140                    <table id="column-table">
141                    <input type="submit" value="refresh">
142            |
143    
144            . join("\n", map {
145                    my $checked = '';
146                    $checked = 'checked=1' if $visible_columns->{$_};
147                  qq|                  qq|
148                  <form>                  <tr id="$_">
149                  <input type="submit" value="-">                          <td><input type="checkbox" name="columns" value="$_" $checked></td>
150                  <input type="hidden" name="remove_column" value="$column">                          <td>$_</td>
151                  </form>                  </tr>
152                  |                  |
153          }          } @all_columns )
154    
155            . qq|
156                    </table>
157                    <input type="submit" value="refresh">
158                    <input type="hidden" name="dnd_serialize" id="dnd_serialize" value="$dnd_serialize">
159                    </form>
160            |
161            ;
162    
163            $self->add_js( 'static/Frey/jQuery/jquery.tablednd_0_5.js' );
164            $self->add_js(q|
165                    $(document).ready(function() {
166                            // Initialise the table
167                            $("#column-table").tableDnD({
168                                    onDrop: function(table, row) {
169                                            $('#dnd_serialize').val(
170                                                    $('#column-table').tableDnDSerialize()
171                                            );
172                                    },
173                            });
174                    });
175            |);
176    
177            my $total = $rs->pager->total_entries;
178    
179          my $header = qq|<tr><th>| . join(qq|</th><th>|, map { $_ . form($_) } @columns) . qq|</th></tr>|;          my $header = qq|<tr><th>| . join(qq|</th><th>|, @columns) . qq|</th></tr>|;
180    
181          my $html = qq|          my $html = qq|
182                  Rows: <b>$total</b>                  Rows: <b>$total</b>
183                    $column_editor
184                  <table>                  <table>
185                  $header                  $header
186                  $rows                  $rows

Legend:
Removed from v.1024  
changed lines
  Added in v.1036

  ViewVC Help
Powered by ViewVC 1.1.26