We _really_ shouldn't be using the session for this, as that entirely breaks the ability to have multiple crud views open at once. Can you back this out until we have a non-paradigm-breaking way to do it?
On Fri, Nov 20, 2009 at 12:12:13PM -0500, Jifty commits wrote: > Author: yves > Date: Fri Nov 20 12:12:12 2009 > New Revision: 7663 > > Modified: > jifty/trunk/lib/Jifty/View/Declare/CRUD.pm > jifty/trunk/share/web/static/css/crud.css > jifty/trunk/share/web/templates/_elements/paging > > Log: > a new sort header for CRUD which uses session to keep 3 states: up, down and > disable > feel free to improve design ;) > > > Modified: jifty/trunk/lib/Jifty/View/Declare/CRUD.pm > ============================================================================== > --- jifty/trunk/lib/Jifty/View/Declare/CRUD.pm (original) > +++ jifty/trunk/lib/Jifty/View/Declare/CRUD.pm Fri Nov 20 12:12:12 2009 > @@ -568,8 +568,6 @@ > > my ( $page ) = get('page'); > my $item_path = get('item_path') || $self->fragment_for("view"); > - my $sort_by = get ('sort_by') || ''; > - my $order = get ('order') || ''; > my $collection = $self->_current_collection(); > > div { > @@ -579,7 +577,7 @@ > > div { > { class is 'crud-table' }; > - show( './sort_header', $item_path, $sort_by, $order ); > + show( './sort_header', $item_path ); > show( './list_items', $collection, $item_path ); > }; > > @@ -603,8 +601,36 @@ > sub _current_collection { > my $self = shift; > my ( $page ) = get('page') || 1; > - my ( $sort_by ) = get('sort_by'); > - my ( $order ) = get('order'); > + my $sort = get('CRUDSort') || ''; > + my $session_sort = Jifty->web->session->get('CRUDSort') || ''; > + my($sort_by,$order); > + > + if ( $session_sort =~ m/(.*?)-(ASC|DESC)$/) { > + $sort_by=$1;$order=$2; }; > + > + # reset session if args doesn't exist > + if ( $sort_by && ! grep /^$sort_by$/, $self->display_columns ) { > + $order = ''; $sort_by = ''; $sort =''; > + Jifty->web->session->set('CRUDSort'=>undef); > + }; > + # 3 state switch for Sort order and column > + if ($sort) { > + $sort_by = $sort; > + if (!$order) { > + $order = 'ASC'; > + Jifty->web->session->set('CRUDSort'=>$sort.'-ASC'); > + } > + elsif ( $order eq 'ASC') { > + $order = 'DESC'; > + Jifty->web->session->set('CRUDSort'=>$sort.'-DESC'); > + } > + elsif ( $order eq 'DESC') { > + $order = ''; > + $sort_by = ''; > + Jifty->web->session->set('CRUDSort'=>undef); > + }; > + }; > + > my $collection_class = $self->record_class->collection_class; > my $search = ( Jifty->web->response->result('search') ? > Jifty->web->response->result('search')->content('search') : undef ); > my $collection; > @@ -619,8 +645,7 @@ > } else { > $collection = $collection_class->new(); > $collection->find_all_rows(); > - $collection->order_by(column => $sort_by, order=>'ASC') if ($sort_by > && !$order); > - $collection->order_by(column => $sort_by, order=>'DESC') if > ($sort_by && $order); > + $collection->order_by(column => $sort_by, order=>$order) if > ($sort_by && $order); > } > > $collection->set_page_info( current_page => $page, per_page => > $self->per_page ); > @@ -637,43 +662,34 @@ > template 'sort_header' => sub { > my $self = shift; > my $item_path = shift; > - my $sort_by = shift; > - my $order = shift; > - my $record_class = $self->record_class; > + my $sort = get('CRUDSort') || ''; > + my $session_sort = Jifty->web->session->get('CRUDSort') || ''; > + my($sort_by,$order); > > + if ( $session_sort =~ m/(.*?)-(ASC|DESC)$/) { > + $sort_by=$1;$order=$2; }; > + > + my $record_class = $self->record_class; > div { > { class is "crud-column-headers" }; > for my $argument ($self->display_columns) { > + my $label = $record_class->column($argument)->label || $argument; > div { > { class is 'crud-column-header' }; > - my $css_class = ($sort_by && !$order && $sort_by eq > $argument)?'up_select':'up'; > - span { > - { class is $css_class }; > - hyperlink( > - label => _("asc"), > - onclick => > - { args => { sort_by => $argument, order => undef > } }, > - ); > - }; > - $css_class = ($sort_by && $order && $sort_by eq > $argument)?'down_select':'down' ; > - span { > - { class is $css_class }; > - hyperlink( > - label => _("desc"), > - onclick => > - { args => { sort_by => $argument, order => 'D' } > }, > - ); > - }; > - span{ > - {class is "field"}; > - outs $record_class->column($argument)->label || > $argument; > + if ( $sort_by && $argument eq $sort_by ) { > + strong {hyperlink ( label =>$label, onclick => { args => > {CRUDSort=>$argument}});}; > + my $img = ($order eq 'ASC')?'up':'down'; > + img { attr { src => > '/images/css/bullet_arrow_'.$img.'.png' }; }; > + } > + else { > + hyperlink ( label =>$label, onclick => { args => > {CRUDSort=>$argument}}); > }; > + > } > } > }; > }; > > - > use constant predefined_search => (); > > =head2 predefined_search > > Modified: jifty/trunk/share/web/static/css/crud.css > ============================================================================== > --- jifty/trunk/share/web/static/css/crud.css (original) > +++ jifty/trunk/share/web/static/css/crud.css Fri Nov 20 12:12:12 2009 > @@ -57,30 +57,14 @@ > font-weight: bold; > } > > -.up, .down, .up_select, .down_select { > - height : 1.5em; > - float: left; > - margin-right: 0.2em; > +.crud-column-headers img { > + vertical-align:text-bottom; > } > > -.up, .up_select { > - background: url(/static/images/css/bullet_arrow_up.png) no-repeat bottom > center; > -} > - > -.down, .down_select { > - background: url(/static/images/css/bullet_arrow_down.png) no-repeat > bottom center; > -} > - > -.up_select a, .down_select a { > - font-weight: bold; > - color: #900; > -} > - > - > .crud-column-headers a { > color: black; > display: block; > - font-size: 0.6em; > + font-size: 0.8em; > height: 100%; > text-decoration: none; > font-family : sans-serif; > > Modified: jifty/trunk/share/web/templates/_elements/paging > ============================================================================== > --- jifty/trunk/share/web/templates/_elements/paging (original) > +++ jifty/trunk/share/web/templates/_elements/paging Fri Nov 20 12:12:12 2009 > @@ -32,7 +32,7 @@ > label => $goto_page, > onclick => { > args => { > - $argument => $goto_page, > + $argument => $goto_page, CRUDSort => '' > }, > }, > ) %> > @@ -47,7 +47,7 @@ > class => "prev", > onclick => { > args => { > - $argument => $prev, > + $argument => $prev, CRUDSort => '' > }, > }, > ) %> > @@ -61,7 +61,7 @@ > class => "next", > onclick => { > args => { > - $argument => $next, > + $argument => $next, CRUDSort => '' > }, > }, > ) %> > @@ -75,7 +75,7 @@ > class => "all", > onclick => { > args => { > - $argument => 'all', > + $argument => 'all', CRUDSort => '' > }, > }, > ) %> > _______________________________________________ > Jifty-commit mailing list > jifty-com...@lists.jifty.org > http://lists.jifty.org/cgi-bin/mailman/listinfo/jifty-commit > -- _______________________________________________ jifty-devel mailing list jifty-devel@lists.jifty.org http://lists.jifty.org/cgi-bin/mailman/listinfo/jifty-devel