Changeset 225


Ignore:
Timestamp:
06/05/09 10:28:37 (15 years ago)
Author:
nanardon
Message:
  • use session to remember settings in massedit
Location:
LATMOS-Accounts-Web
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • LATMOS-Accounts-Web/lib/LATMOS/Accounts/Web/Controller.pm

    r216 r225  
    4444} 
    4545 
     46sub filter : Private { 
     47    my ( $self, $c ) = @_; 
     48    my $otype = $c->stash->{filter}->{otype} or return; 
     49 
     50    $c->stash->{db} ||= $c->model('Accounts')->db; 
     51    my $base = $c->stash->{db}; 
     52    if ($c->req->param('attrval')) { 
     53        $c->stash->{filter}{attrval} = [ $c->req->param('attrval') ]; 
     54        $c->stash->{filter}{attr} = [ $c->req->param('attr') ]; 
     55    } else { 
     56        # avoid undef 
     57        $c->stash->{filter}{attrval} ||= []; 
     58        $c->stash->{filter}{attr} ||= []; 
     59    } 
     60     
     61    my %filter = map  { 
     62        $c->stash->{filter}{attr}[$_] && $c->stash->{filter}{attrval}[$_] 
     63        ? ($c->stash->{filter}{attr}[$_] => $c->stash->{filter}{attrval}[$_]) 
     64        : () 
     65    } (0 .. $#{ $c->stash->{filter}{attr} || []}); 
     66    $c->stash->{objectslist} = [ 
     67        map { $base->get_object($otype, $_) } 
     68        (%filter 
     69            ? ($base->search_objects($otype, %filter) ) 
     70            : ($base->list_objects($otype) )) 
     71    ] 
     72} 
     73 
    4674=head2 end 
    4775 
  • LATMOS-Accounts-Web/lib/LATMOS/Accounts/Web/Controller/MassEdit.pm

    r222 r225  
    33use strict; 
    44use warnings; 
    5 use base 'Catalyst::Controller'; 
     5use base 'LATMOS::Accounts::Web::Controller'; 
    66 
    77=head1 NAME 
     
    2626 
    2727    my $base = $c->stash->{db} = $c->model('Accounts')->db; 
    28     if (my $otype = $c->req->param('otype')) { 
    29         my %filter = map  { 
    30             $c->req->params->{attr}[$_] && $c->req->params->{attrval}[$_] 
    31             ? ($c->req->params->{attr}[$_] => $c->req->params->{attrval}[$_]) 
    32             : () 
    33         } (0 .. $#{ $c->req->params->{attr} || []}); 
    34         $c->stash->{objectslist} = [ 
    35             map { $base->get_object($otype, $_) } 
    36             (%filter 
    37             ? ($base->search_objects($otype, %filter) ) 
    38             : ($base->list_objects($otype) )) 
    39         ] 
     28    if ($c->req->param('otype') && $c->req->param('otype') ne $c->session->{filter}{otype}) { 
     29        $c->session->{filter} = undef; 
     30        $c->stash->{filter}->{otype} = $c->req->param('otype'); 
     31        $c->session->{massedit}{attrcol} = undef; 
     32    } else { 
     33        $c->stash->{filter} = $c->session->{filter}; 
     34        if ($c->req->param('attrcol')) { 
     35            $c->session->{massedit}{attrcol} = [ $c->req->param('attrcol') ]; 
     36        } else { 
     37            $c->req->params->{attrcol} = $c->session->{massedit}{attrcol}; 
     38        } 
    4039    } 
     40    $c->forward('filter'); 
     41    $c->session->{filter} = $c->stash->{filter}; 
    4142} 
    4243 
  • LATMOS-Accounts-Web/root/html/includes/filter.tt

    r221 r225  
    11<!-- $Id$ --> 
    22<p>Filtre:</p> 
    3 <form action="[% formuri %]" method="POST"> 
     3<form action="[% c.action.namespace %]" method="POST"> 
    44<input type="hidden" name="otype" value="[% otype | html %]"> 
    55[% FOREACH item = [0, 1, 2 ] %] 
     
    1313<option value=""></option> 
    1414[% FOREACH f = db.list_canonical_fields(otype, 'r') %] 
    15 <option value="[% f | html %]" [% ' selected="1"' IF c.req.params.attr.$item == f %]> 
     15<option value="[% f | html %]" [% ' selected="1"' IF filter.attr.$item == f %]> 
    1616    [% c.model('AttrForms').attr_label(f) | html %] 
    1717</option> 
     
    1919</select> 
    2020</td> 
    21 <td><input type="text" name="attrval" value="[% c.req.params.attrval.$item | html %]"></td></tr> 
     21<td><input type="text" name="attrval" value="[% filter.attrval.$item | html %]"></td></tr> 
    2222[% IF loop.last %] 
    2323</table> 
Note: See TracChangeset for help on using the changeset viewer.