Changeset 17


Ignore:
Timestamp:
03/07/09 18:44:50 (15 years ago)
Author:
nanardon
Message:
  • check count of selected items
Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/lib/Vote/Controller/Ballot.pm

    r16 r17  
    5959    $c->stash->{choices} = { %choices }; 
    6060    $c->stash->{sbal} = { map { $_ => 1 } $c->req->param('sbal') }; 
     61    $c->stash->{fsbal} = [ map { 
     62        s/^\s+//; 
     63        s/\s+$//; 
     64        s/\s+/ /g; 
     65        $_ 
     66    } ($c->req->param('fsbal')) ]; 
     67 
     68    my @torecord = grep { $_ } ( 
     69        (map { $choices{$_} } $c->req->param('sbal')), 
     70        @{ $c->stash->{fsbal} } 
     71    ); 
     72     
     73    warn $vote->vote_info($id)->{choice_count}; 
     74    warn scalar(@torecord); 
     75    warn $_ foreach(@torecord); 
     76    if (scalar(@torecord) > $vote->vote_info($id)->{choice_count}) { 
     77        $c->req->param('ballot', ''); 
     78        $c->stash->{vote_error} = 'Seulement ' . 
     79            $vote->vote_info($id)->{choice_count} . ' choix possible'; 
     80        return; 
     81    } 
    6182 
    6283    if ($c->req->param('confirm')) { 
     
    6485            $uid, 
    6586            $id, 
    66             [ grep { $_ } ( 
    67               map { $choices{$_} } $c->req->param('sbal'), 
    68               $c->req->param('fsbal'), 
    69             ) ], 
     87            [ @torecord ], 
    7088            $c->req->address, 
    7189        ); # TODO trap error 
  • trunk/root/templates/ballot/default.tt

    r15 r17  
    11[% vote = c.model('Vote') %] 
    22 
    3 [% INLCUDE 'includes/poll.tt' %] 
     3[% thisvote = vote.vote_info(voteid) %] 
     4 
     5[% INCLUDE 'includes/poll.tt' %] 
    46 
    57[% IF c.req.param('ballot') %] 
     
    1315[% FOREACH ch = c.req.param('fsbal') %] 
    1416[% ch | html %]<br> 
    15 <input type="hidden" name="sbal" value="[% ch %]"> 
     17<input type="hidden" name="fsbal" value="[% ch %]"> 
    1618[% END %] 
    1719<input type="submit" name="confirm"> 
     
    2022 
    2123[% ELSE %] 
     24 
     25[% IF vote_error %][% vote_error %][% END %] 
    2226 
    2327<form action="[% c.uri_for(voteid) %]"> 
     
    3034[% count = 0 %] 
    3135[% WHILE count < thisvote.free_choice %] 
    32 <input type="text" name="fsbal" value="[% c.req.param('fsbal').count %]"><br> 
     36<input type="text" name="fsbal" value="[% fsbal.$count %]"><br> 
    3337[% count = count + 1 %] 
    3438[% END %] 
Note: See TracChangeset for help on using the changeset viewer.