/[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 1027 by dpavlin, Wed Jan 28 21:41:34 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    
# Line 112  sub as_markup { Line 107  sub as_markup {
107                          position: absolute;                          position: absolute;
108                          top: 1em;                          top: 1em;
109                          right: 1em;                          right: 1em;
110                            z-index: 10;
111                            opacity: .2;
112                            filter: alpha(opacity=20);
113                    }
114                    #column-editor:hover {
115                            opacity: 1;
116                            filter: alpha(opacity=100);
117                    }
118                    #column-editor small {
119                            color: #888;
120                  }                  }
121          |);          |);
122    
123          my @hidden_cols;          my $visible_columns;
124          {          $visible_columns->{$_}++ foreach @columns;
                 my $col;  
                 $col->{$_}++ foreach @columns;  
                 @hidden_cols = grep { ! $col->{$_} } @all_columns;  
         }  
125    
126            @all_columns = (
127                    # dnd_serialize is in php format id[]=foo&id[]=bar
128                    map { s/[^=]+=// ; $_ } split(/&/, $self->dnd_serialize )
129            ) if $self->dnd_serialize;
130            warn "# column-editor for ", $self->dump( @all_columns );
131    
132            my $dnd_serialize = join('&', @all_columns);
133          my $column_editor = qq|          my $column_editor = qq|
134                  <table id="column-editor">                  <form id="column-editor" method="get"><!-- FIXME we really should do post, but it doesn't work! -->
135                  <tr class="nodrag nodrop"><th>Visible</th></tr>                  <table id="column-table">
136          | . join("\n", map { qq|                  <input type="submit" value="refresh">
137                  <tr id="$_"><td>$_</td></tr>          |
138          | } @columns )  
139          . qq|          . join("\n", map {
140                  <tr class="nodrag nodrop"><th>Hidden</th></tr>                  my $checked = '';
141          | . join("\n", map { qq|                  $checked = 'checked=1' if $visible_columns->{$_};
142                  <tr id="$_"><td>$_</td></tr>                  qq|
143          | } @hidden_cols )                  <tr id="$_">
144                            <td><input type="checkbox" name="columns" value="$_" $checked></td>
145                            <td>$_</td>
146                    </tr>
147                    |
148            } @all_columns )
149    
150          . qq|          . qq|
151                  </table>                  </table>
152                    <input type="submit" value="refresh">
153                    <input type="hidden" name="dnd_serialize" id="dnd_serialize" value="$dnd_serialize">
154                    </form>
155          |          |
156          ;          ;
157    
# Line 142  sub as_markup { Line 159  sub as_markup {
159          $self->add_js(q|          $self->add_js(q|
160                  $(document).ready(function() {                  $(document).ready(function() {
161                          // Initialise the table                          // Initialise the table
162                          $("#column-editor").tableDnD();                          $("#column-table").tableDnD({
163                                    onDrop: function(table, row) {
164                                            $('#dnd_serialize').val(
165                                                    $('#column-table').tableDnDSerialize()
166                                            );
167                                    },
168                            });
169                  });                  });
170          |);          |);
171    
172          my $total = $rs->pager->total_entries;          my $total = $rs->pager->total_entries;
173    
174          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>|;  
175    
176          my $html = qq|          my $html = qq|
177                  Rows: <b>$total</b>                  Rows: <b>$total</b>

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

  ViewVC Help
Powered by ViewVC 1.1.26