--- trunk/lib/Frey/ObjectBrowser.pm 2008/07/10 15:41:17 83 +++ trunk/lib/Frey/ObjectBrowser.pm 2008/07/16 14:17:46 143 @@ -1,8 +1,14 @@ package Frey::ObjectBrowser; use Moose; -use MooseX::Method; extends 'Frey'; +with 'Frey::Web'; + +has 'fey_class' => ( + is => 'rw', + isa => 'Str', + required => 1, +); my @callbacks; @@ -24,63 +30,60 @@ #use Data::Dumper; #$Data::Dumper::Deparse = 1; use Data::Dump qw/dump/; -use Data::Structure::Util qw(unbless); +use Frey::Web::Item; +use Frey::Web::Links; +use Frey::Pager; -#method 'html' => positional( -# isa => 'Continuity::RequestHolder', -# required => 1, -#) => sub { sub html { my ( $self, $req ) = @_; - use Strix::User; - use Strix::View::User; - - my $s = Strix::User->rows(); - #warn "# s = ",dump( $s ); - + $self->add_css( 'static/form.css' ); my @w; - while ( my $u = $s->next ) { - my $w = Strix::View::User->new( %{ $u } ); - $w->_fey( $u ); - warn "# w = ",dump( $w ) if $self->debug; - push @w, $w; - } - my $f = { $req->params }; + my $pager; + while ( 1 ) { - - warn "# got $#w elements: ",dump( map { $_->id } @w ); - warn "<<< GOT REQUEST ",dump( $f ); - warn "does last element have id? ",dump( $w[$#w]->id ); + warn "<<< GOT REQUEST ",dump( $f ); - if ( $w[ $#w ]->_fey ) { - warn "+++ added new widget\n"; - push @w, Strix::View::User->new( render_as => 'edit' ); + $pager = Frey::Pager->new( + fey_class => $self->fey_class, + item_constructor => sub { + Frey::Web::CRUD->new( fey_class => $self->fey_class, @_ ); + }, + ) if ! $pager; + + $pager->pager->current_page( $f->{page} ) if $f->{page}; + $pager->pager->entries_per_page( $f->{pre_page} ) if $f->{per_page}; + + $pager->update_collection; + + my $last = $pager->last_item; + + if ( $last->fey ) { + warn "+++ add item widget\n"; + $pager->add_item( $pager->item_constructor->( render_as => 'edit' )); } - my $form = join('
', map { $_->process($f) || '[deleted]' } @w ); - my $doc = Continuity::Widget::DomNode->create( - html => [ - head => [ - link => { rel=>"stylesheet", href=>"/static/form.css", type=>"text/css" } - ], - body => [ - h1 => [ 'Strix::User' ], - form => { method=>'post' } => [ - $form, - ], - ], - ] + my $form = $pager->items_in_layout( $f ); + $form = $last->render_table_wrapper( $form ); + + my $html = $self->page( + body => '

' . $self->fey_class . '

' + . $last->layout_picker # FIXME ugly + . $pager->render_pager + . qq|
$form
| ); - $req->print( $doc->to_string ); + warn ">>> ",length( $html ),"\n"; + + $req->print( $html ); $req->next; +# process_links( $req ); $f = { $req->params }; }