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