Changeset 959 for LATMOS-Accounts-Web


Ignore:
Timestamp:
05/15/12 03:30:21 (12 years ago)
Author:
nanardon
Message:
  • merge all work around forms
Location:
LATMOS-Accounts-Web
Files:
6 edited

Legend:

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

    r946 r959  
    5454    $c->stash->{datarequest} = 
    5555        LATMOS::Accounts::Bases::Sql::DataRequest->new($accreq); 
     56    $c->stash->{datarequest}->set_ptr_object($c->stash->{object}) 
     57        if ($c->stash->{object}); 
     58 
    5659    $c->stash->{form} = $c->model( 
    5760        'AttrForms', 
    5861        '', 
    59         $c->stash->{object}, 
     62        $c->stash->{datarequest}, 
    6063        $c->model('Accounts')->db 
    6164    ); 
     65 
     66    # Default apply date: 
     67    my @date = localtime( time + 3600 * 24 ); 
     68    $c->stash->{default_apply_date} = sprintf( 
     69        '%02d/%02d/%d', 
     70        @date[3,4], 
     71        $date[5] + 1900 
     72    ); 
     73 
     74    if ($c->req->param('send')) { 
     75        my %attrs; 
     76        foreach ($c->stash->{datarequest}->attributes) { 
     77            my $htmlname = $c->stash->{form}->attr_field_name($_); 
     78            my @vals = $c->req->param($htmlname); 
     79            $attrs{$_} = @vals > 1 ? \@vals : $vals[0]; 
     80        } 
     81        if ($c->stash->{datarequest}->register( 
     82            $c->user->{username}, 
     83            $c->req->param('apply') || $c->stash->{default_apply_date}, 
     84            %attrs, 
     85        )) { 
     86            $c->go('recorded'); 
     87        } 
     88    } 
     89 
    6290} 
    6391 
     92sub recorded : Private { 
     93    my ($self, $c) = @_; 
    6494 
     95    my %attrs = $c->stash->{datarequest}->get_values; 
     96    $c->stash->{values} = \%attrs; 
     97} 
    6598 
    6699=head1 AUTHOR 
  • LATMOS-Accounts-Web/lib/LATMOS/Accounts/Web/Model/AttrFilter.pm

    r861 r959  
    9191sub search_field { 
    9292    my ($self, $count) = @_; 
    93     my $form = $self->{c}->model('AttrForms'); 
     93    my $form = $self->{c}->model('AttrForms', '', $self->otype, $self->{c}->stash->{db}); 
    9494    my $html = '<select name="attr"> 
    9595    <option value=""></option>'; 
  • LATMOS-Accounts-Web/lib/LATMOS/Accounts/Web/Model/AttrForms.pm

    r955 r959  
    216216 
    217217sub attr_label { 
    218     my ($self, $attr) = @_; 
    219     my ($hint, $label) = ('', ''); 
     218    my ($self, $attr, $label, $hint) = @_; 
     219    $label ||= ''; 
     220    $hint ||= ''; 
    220221    LATMOS::Accounts::Web->config->{attrs} ||= {}; 
    221     my $htmlname = ($self->{object} ? $self->{object}->id . '_' : '') . $attr; 
     222    my $attribute = $self->base->attribute($self->otype, $attr); 
     223    my $htmlname = $self->escape($self->attr_field_name($attr)); 
    222224    if (my $attr_config = LATMOS::Accounts::Web->config->{attrs}{$attr}) { 
    223         $label = $attr_config->{label} || ''; 
     225        $label ||= $attr_config->{label} || ''; 
    224226        #utf8::is_utf8($label) && utf8::encode($label); 
    225         $hint = $attr_config->{hint} || ''; 
     227        $hint ||= $attr_config->{hint} || ''; 
    226228        #utf8::is_utf8($hint) && utf8::encode($hint); 
    227229    } 
     
    243245 
    244246sub attr_raw_value { 
    245     my ($self, $attr) = @_; 
    246     return $self->{c}->req->param($attr) || 
    247         ($self->{object} ? $self->{object}->get_attributes($attr) : '') 
     247    my ($self, $attribute) = @_; 
     248    my @val = grep { $_ }   
     249        ($self->{c}->req->param($attribute->name)) 
     250        || ($self->{object} 
     251            ? ($self->{object}->get_attributes($attribute->name)) 
     252            : ()); 
     253 
     254    if (@val) { 
     255        return @val; 
     256    } else { 
     257        return (grep { $_ } ($attribute->default_value)) 
     258    } 
    248259} 
    249260 
     
    251262    my ($self, $attr) = @_; 
    252263    my $id = $self->{object} 
    253         ? $self->{object}->id . '_' 
     264        ? ($self->{object}->id || '') 
    254265        : ''; 
     266    $id .= '_' if ($id); 
    255267    $id =~ s/\./_/g; 
    256268    $id =~ s/-/_/g; 
     
    403415                last; 
    404416            }; 
    405  
    406             warn $_; 
    407417        } 
    408418    return ''; 
     
    450460                    frequency => 1, 
    451461                    with => "'val='+element.value" . 
    452                     ($self->{object} ? "+'&exclude=" . $self->{object}->id . "'" : 
    453                         ''), 
     462                    ($self->{object} ? 
     463                        "+'&exclude=" . ($self->{object}->id || '') . "'"  
     464                        : ''), 
    454465                } 
    455466            ) 
     
    463474    my ($self, $attr, $type) = @_; 
    464475 
    465     my $attr_info = $type 
    466         ? { formtype => $type } 
    467         : undef; 
    468  
    469     my $attribute = ($self->{object} 
    470         ? $self->{object}->attribute($attr) 
    471         : $self->base->attribute($self->otype, $attr)); 
    472  
    473     $attribute ||= $self->base->attribute( 
    474         $self->otype, 
    475         {  
    476             name => $attr, 
    477             formtype => $type 
    478         }, 
    479     ); 
     476    my $attribute = ($type 
     477        ? ref $type 
     478            ? $self->base->attribute( 
     479                $self->otype, 
     480                { %$type, name => $attr },) 
     481            : $self->base->attribute( 
     482                $self->otype, 
     483                { formtype => $type , name => $attr },) 
     484        : ($self->{object} 
     485            ? $self->{object}->attribute($attr) 
     486            : $self->base->attribute($self->otype, $attr, { formtype => $type }))) 
     487        || $self->base->attribute($self->otype, { name => $attr }); 
     488 
    480489 
    481490    my $htmlname = $self->escape($self->attr_field_name($attr)); 
    482491 
    483492    my @html_fields; 
    484     foreach my $attr_raw_value ( 
    485         $attribute->multiple 
    486             ? (grep { $_ } $self->attr_raw_value($attr)) 
    487             : $self->attr_raw_value($attr) || '') { 
     493 
     494    # Force Array context: 
     495    my @attr_raw_value = (); 
     496    if ($attribute->multiple) { 
     497        @attr_raw_value = grep { $_ } $self->attr_raw_value($attribute); 
     498    } else { 
     499        my ($val) = $self->attr_raw_value($attribute); 
     500        @attr_raw_value = ($val || ''); 
     501    } 
     502 
     503    foreach my $attr_raw_value (@attr_raw_value) { 
    488504 
    489505        my $html_id = $htmlname . 
     
    501517    } 
    502518 
    503     if ($attribute->{multiple}) { 
     519    if ($attribute->{multiple} && !$attribute->readonly) { 
    504520        my $html_id = $htmlname . '_m_SUBID'; 
    505521 
  • LATMOS-Accounts-Web/root/html/includes/header.tt

    r888 r959  
    103103        </span> 
    104104        <span> 
    105             <a href="[% c.uri_for('/sites') %]" 
    106             onMouseOver="document.getElementById('menui').innerHTML='Liste des sites';" 
    107             onMouseOut="resetmenu();" 
    108             > 
    109             <img title="Sites" src="[% c.uri_for('/static', 'icons', 'xfce-internet.png') %]"></a> 
    110         </span> 
    111         [% # On cache volontairement les alias si l'utilisateur ne doit pas y 
    112         toucher %] 
    113         [% IF c.model('Accounts').db.check_acl('aliases', '@CREATE', 'w') %] 
    114         <span> 
    115             <a href="[% c.uri_for('/aliases') %]" 
    116             onMouseOver="document.getElementById('menui').innerHTML= 
    117                 'Alias mail sans utilisateur';" 
    118             onMouseOut="resetmenu();" 
    119             > 
    120             <img title="Alias mail" src="[% c.uri_for('/static', 'icons', 'mail_forward.png') %]"></a> 
    121         </span> 
    122         [% END %] 
    123         <span> 
    124105            <a href="[% c.uri_for('/nethosts') %]" 
    125106            onMouseOver="document.getElementById('menui').innerHTML='Liste des hÃŽtes réseau';" 
     
    135116        [% END %] 
    136117        </span> 
    137         [% # On cache volontaire les zones si l'utilisateur ne doit pas y 
    138         toucher %] 
    139         [% IF c.model('Accounts').db.check_acl('netzone', '@CREATE', 'w') %] 
    140118        <span> 
    141             <a href="[% c.uri_for('/netzones') %]" 
    142             onMouseOver="document.getElementById('menui').innerHTML='Liste des zones réseaux';" 
     119            <a href="[% c.uri_for('/request') %]" 
     120            onMouseOver="document.getElementById('menui').innerHTML='Demandes';" 
    143121            onMouseOut="resetmenu();" 
    144122            > 
    145             <img title="Gestion Réseau" src="[% c.uri_for('/static', 'icons', 'network-workgroup.png') %]"></a> 
    146             <a href="[% c.uri_for('/create', 'netzone') %]" 
    147             onMouseOver="document.getElementById('menui').innerHTML='Ajouter une zones réseau';" 
     123            <img title="Demandes" src="[% c.uri_for('/static', 'icons', 'logviewer.png') %]"></a> 
     124        </span> 
     125        <span> 
     126            <a href="[% c.uri_for('/admin') %]" 
     127            onMouseOver="document.getElementById('menui').innerHTML='Administrer...';" 
    148128            onMouseOut="resetmenu();" 
    149             ><img title="Ajouter une zone" src="[% c.uri_for('/static', 'icons', 'add.png') %]"></a> 
     129            > 
     130            <img title="Administrer..." src="[% c.uri_for('/static', 'icons', 'gtk-execute.png') %]"></a> 
    150131        </span> 
    151         [% END %] 
    152132        <span> 
    153133            <a href="[% c.uri_for('/about') %]" 
  • LATMOS-Accounts-Web/root/html/request/default.tt

    r952 r959  
    11<!-- $Id$ --> 
     2 
     3<h2>[% accreq.get_attributes('description') | html %]</h2> 
    24 
    35[% IF select_object %] 
     
    2527[% ELSE %] 
    2628 
     29[% IF accreq.get_attributes('requireObject') %] 
     30<h3>[% datarequest.get_attributes('displayName') || datarequest.id %]</h3> 
     31[% END %] 
     32 
    2733<form action="[% c.uri_for('/request', accreq.id, object.id) %]"> 
    2834[% FOREACH attr = datarequest.attributes %] 
     
    3137[% END %] 
    3238<tr> 
    33 <th>[% form.attr_label(attr) %]</th> 
     39[% attrinfo = datarequest.attribute_info(attr) %] 
     40<th>[% form.attr_label(attr, attrinfo.label) %]</th> 
    3441<td>[% form.attr_field(attr) %]</td> 
    3542</tr> 
    3643[% IF loop.last %] 
    37  
     44<tr> 
     45<th>Date d'application</th> 
     46<td> 
     47[% form.attr_field('apply', { formtype => 'date', _noacl => 1, default => default_apply_date } ) %] 
     48</td> 
     49</tr> 
     50<tr><td></td><td> 
     51<input type="submit" name="send"> 
     52</td></tr> 
    3853</table> 
    3954[% END %] 
    4055[% END %] 
    41 [% form.attr_field('apply', 'DATE') %] 
    42 <input type="submit" name="send"> 
    4356</form> 
    4457 
  • LATMOS-Accounts-Web/root/html/request/index.tt

    r946 r959  
    11<!-- $Id$ --> 
    22 
     3<h2>Formuler une demande:</h2> 
     4 
    35[% FOREACH h = c.model('Accounts').db.search_objects('accreq', 'exported=*') %] 
     6[% IF loop.first %] 
     7<ul> 
     8[% END %] 
    49[% o = c.model('Accounts').db.get_object('accreq', h) %] 
     10<li> 
    511<a href="[% c.uri_for(h) %]"> 
    612[% o.get_attributes('description') || o.id | html %] 
    713</a> 
    8 <br> 
    9  
     14</li> 
     15[% IF loop.last %] 
     16</ul> 
    1017[% END %] 
     18[% END %] 
Note: See TracChangeset for help on using the changeset viewer.