/[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 1026 by dpavlin, Wed Jan 28 19:54:40 2009 UTC revision 1036 by dpavlin, Sun Feb 8 12:24:17 2009 UTC
# Line 42  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 74  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;
         my @columns;  
         {  
                 my $c = $self->load( $path );  
                 @columns = @$c if $c;  
         }  
         warn "# load $path columns ", $self->dump( @columns );  
83          my @all_columns = $rs->first->columns;          my @all_columns = $rs->first->columns;
84          @columns = @all_columns unless @columns;          @columns = @all_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    
# Line 112  sub as_markup { Line 112  sub as_markup {
112                          position: absolute;                          position: absolute;
113                          top: 1em;                          top: 1em;
114                          right: 1em;                          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 @hidden_cols;          my $visible_columns;
129          {          $visible_columns->{$_}++ foreach @columns;
130                  my $col;  
131                  $col->{$_}++ foreach @columns;          @all_columns = (
132                  @hidden_cols = grep { ! $col->{$_} } @all_columns;                  # 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|          my $column_editor = qq|
139                  <table id="column-editor">                  <form id="column-editor" method="get"><!-- FIXME we really should do post, but it doesn't work! -->
140                  <tr class="nodrag nodrop"><th>Visible</th></tr>                  <table id="column-table">
141          | . join("\n", map { qq|                  <input type="submit" value="refresh">
142                  <tr id="$_"><td>$_</td></tr>          |
143          | } @columns )  
144          . qq|          . join("\n", map {
145                  <tr class="nodrag nodrop"><th>Hidden</th></tr>                  my $checked = '';
146          | . join("\n", map { qq|                  $checked = 'checked=1' if $visible_columns->{$_};
147                  <tr id="$_"><td>$_</td></tr>                  qq|
148          | } @hidden_cols )                  <tr id="$_">
149                            <td><input type="checkbox" name="columns" value="$_" $checked></td>
150                            <td>$_</td>
151                    </tr>
152                    |
153            } @all_columns )
154    
155          . qq|          . qq|
156                  </table>                  </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    
# Line 142  sub as_markup { Line 164  sub as_markup {
164          $self->add_js(q|          $self->add_js(q|
165                  $(document).ready(function() {                  $(document).ready(function() {
166                          // Initialise the table                          // Initialise the table
167                          $("#column-editor").tableDnD();                          $("#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;          my $total = $rs->pager->total_entries;
178    
179          sub form {          my $header = qq|<tr><th>| . join(qq|</th><th>|, @columns) . qq|</th></tr>|;
                 my $column = shift || die;  
                 qq|  
                 <form>  
                 <input type="submit" value="-">  
                 <input type="hidden" name="remove_column" value="$column">  
                 </form>  
                 |  
         }  
   
         my $header = qq|<tr><th>| . join(qq|</th><th>|, map { $_ . form($_) } @columns) . qq|</th></tr>|;  
180    
181          my $html = qq|          my $html = qq|
182                  Rows: <b>$total</b>                  Rows: <b>$total</b>

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

  ViewVC Help
Powered by ViewVC 1.1.26