Changeset 236


Ignore:
Timestamp:
06/06/09 20:46:24 (15 years ago)
Author:
nanardon
Message:
  • make massedit working
Location:
LATMOS-Accounts-Web
Files:
3 edited

Legend:

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

    r235 r236  
    2626 
    2727    my $base = $c->stash->{db} = $c->model('Accounts')->db; 
     28 
    2829    if ($c->req->param('otype') && $c->req->param('otype') ne $c->session->{filter}{otype}) { 
    2930        $c->session->{filter} = undef; 
     
    3738            $c->req->params->{attrcol} = $c->session->{massedit}{attrcol}; 
    3839        } 
     40    } 
     41 
     42    if (($c->req->param('_change') || '') eq 'all') { 
     43        my %change; 
     44        foreach ($c->req->param('attrcol')) { 
     45            $change{$_} = $c->req->param($_) || undef; 
     46            delete($c->req->params->{$_}); 
     47        } 
     48        foreach my $id ($c->req->param('objid')) { 
     49            my $obj = $base->get_object($c->req->param('otype'), $id) or next; 
     50            $obj->set_c_fields(%change); 
     51        } 
     52        $base->commit; 
     53    } elsif (($c->req->param('_change') || '') eq 'perobj') { 
     54        foreach my $id ($c->req->param('objid')) { 
     55            my $obj = $base->get_object($c->req->param('otype'), $id) or next; 
     56            my %change; 
     57            foreach ($c->req->param('attrcol')) { 
     58                $change{$_} = $c->req->param($id . '_' . $_) || undef; 
     59                delete($c->req->params->{$id . '_' . $_}); 
     60            } 
     61            $obj->set_c_fields(%change); 
     62        } 
     63        $base->commit; 
    3964    } 
    4065    $c->forward('filter'); 
  • LATMOS-Accounts-Web/lib/LATMOS/Accounts/Web/Model/AttrForms.pm

    r215 r236  
    1919    uidNumber => [ 'UID', 'text:6' ], 
    2020    gidNumber => [ 'GID', 'select:group:gidNumber' ], 
    21     manager => [ 'Responsable', 'select-N:user:uid' ], 
    22     managedBy => [ 'Responsable', 'select-N:user:uid' ], 
     21    manager => [ 'Responsable', 'select-N:user' ], 
     22    managedBy => [ 'Responsable', 'select-N:user' ], 
    2323    sn => [ 'Nom' ], 
    2424    givenName => [ 'Prénom' ], 
     
    3737    expire => [ 'Expire le', 'date' ], 
    3838    st => [ 'État (US)' ], 
    39     sutype => [ 'Structure admin.', 'select-N:sutype:name' ], 
     39    sutype => [ 'Structure admin.', 'select-N:sutype' ], 
    4040    exported => [ 'Exporté', 'checkbox' ], 
    4141    locked => [ 'Vérouillé', 'checkbox' ], 
     
    176176    $type ||= 'text'; 
    177177    $type = 'text:6' if (($self->{form} || '') =~ /^group/ && $attr eq 'gidNumber'); 
     178    my $htmlname = ($self->{object} ? $self->{object}->id . '_' : '') . $attr; 
    178179    for ($type) { 
    179180        /^textarea$/ and return sprintf( 
    180181            '<textarea name="%s" cols="40">%s</textarea>', 
    181             $self->escape($attr), 
     182            $self->escape($htmlname), 
    182183            $self->escape($self->attr_raw_value($attr)), 
    183184        ); 
     
    195196            $html .= sprintf( 
    196197                '<input type="text" name="%s" value="%s" size="12">', 
    197                 $attr, 
     198                $htmlname, 
    198199                $self->escape($date) 
    199200            ); 
     
    201202            $html .= qq{ 
    202203            <A HREF="#" 
    203                 onClick="cal13.select(document.forms[0].$attr,'anchor13','dd/MM/yyyy');return false;" 
    204                 TITLE="cal13.select(document.forms[0].$attr,'anchor13','dd/MM/yyyy'); return false;" 
     204                onClick="cal13.select(document.forms[0].$htmlname,'anchor13','dd/MM/yyyy');return false;" 
     205                TITLE="cal13.select(document.forms[0].$htmlname,'anchor13','dd/MM/yyyy'); return false;" 
    205206                NAME="anchor13" ID="anchor13"> 
    206207                <img src="} . $self->{c}->uri_for(qw(/static icons view-calendar-day.png)) 
     
    210211        /^checkbox$/ and do { 
    211212            return sprintf('<input type="checkbox" name="%s"%s>', 
    212                 $attr, 
     213                $self->escape($htmlname), 
    213214                $self->attr_raw_value($attr) ? '  checked="yes"' : '' 
    214215            ); 
     
    219220            my $keyfield = $3; 
    220221            my $select = sprintf('<select name="%s">', 
    221                 $self->escape($attr)) . "\n"; 
     222                $self->escape($htmlname)) . "\n"; 
    222223            $select .= '<option value="">--</option>' . "\n" if ($options =~ /N/); 
    223224            my $value = $self->attr_raw_value($attr) || ''; 
     
    239240            return sprintf( 
    240241                '<input type="text" name="%s" value="%s" size="%d">', 
    241                 $attr, 
     242                $self->escape($htmlname), 
    242243                $self->escape($self->attr_raw_value($attr)), 
    243244                $1 || 30, 
     
    258259    my ($self) = @_; 
    259260    $self->{c}->req->param($self->label) or return; 
     261    my $prefix = $self->{object}->id . '_'; 
    260262    $self->{object}->set_c_fields( 
    261263        map { 
    262264            $_ => 
    263265                ($attrs->{$_}[1] || '') eq 'checkbox' 
    264                 ? ($self->{c}->req->param($_) ? 1 : 0) 
    265                 : $self->{c}->req->param($_) 
     266                ? ($self->{c}->req->param("$prefix$_") ? 1 : 0) 
     267                : ($self->{c}->req->param("$prefix$_") || undef) 
    266268        } $self->attributes 
    267269    ) or return; 
  • LATMOS-Accounts-Web/root/html/massedit/index.tt

    r234 r236  
    4747<form action="[% c.uri_for() %]" method="POST"> 
    4848<input type="hidden" name="otype" value="[% c.req.param('otype') %]"> 
     49<input type="hidden" name="_change" value="all"> 
     50[% FOREACH obj = objectslist %] 
     51<input type="hidden" name="objid" value="[% obj.id | html  %]"> 
     52[% END %] 
    4953[% FOREACH atcol = c.req.param('attrcol') %] 
    5054[% NEXT IF NOT atcol %] 
    51 <input type="hidden" name="attrcol" value="[% atcol %]"> 
    5255[% END %] 
    5356<tr> 
     
    6669<form action="[% c.uri_for() %]" method="POST"> 
    6770<input type="hidden" name="otype" value="[% c.req.param('otype') %]"> 
     71<input type="hidden" name="_change" value="perobj"> 
    6872[% FOREACH atcol = c.req.param('attrcol') %] 
    6973[% NEXT IF NOT atcol %] 
    70 <input type="hidden" name="attrcol" value="[% atcol %]"> 
    7174[% END %] 
    7275[% FOREACH obj = objectslist %] 
    7376[% attrform = c.model('AttrForms', c.req.param('otype'), obj) %] 
    7477<tr> 
    75 <th>[% obj.id | html  %]</th> 
     78<th>[% obj.id | html  %] 
     79<input type="hidden" name="objid" value="[% obj.id | html  %]"> 
     80</th> 
    7681[% FOREACH atcol = c.req.param('attrcol') %] 
    7782[% NEXT IF NOT atcol %] 
Note: See TracChangeset for help on using the changeset viewer.