Changeset 9
- Timestamp:
- 03/06/09 05:09:15 (15 years ago)
- Location:
- trunk
- Files:
-
- 1 added
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/lib/Vote.pm
r2 r9 14 14 # directory 15 15 16 use Catalyst qw/-Debug ConfigLoader Static::Simple/; 16 use Catalyst qw/ 17 -Debug 18 ConfigLoader 19 Static::Simple 20 Session 21 Session::Store::DBI 22 Session::State::Cookie 23 /; 17 24 18 25 our $VERSION = '0.01'; … … 29 36 __PACKAGE__->config( name => 'Vote' ); 30 37 38 __PACKAGE__->config->{session} = { 39 expires => 1800, 40 dbi_table => 'sessions', 41 dbi_dsn => 'noo', 42 }; 43 44 31 45 # Start the application 32 46 __PACKAGE__->setup; 47 48 # This is after because db config is in config file 49 __PACKAGE__->config->{session}{dbi_dsn} = 'dbi:Pg:' . __PACKAGE__->config->{db}; 33 50 34 51 -
trunk/lib/Vote/Controller/Ballot.pm
r8 r9 33 33 $c->stash->{voteid} = $id; 34 34 35 my $uid = $c->session->{uid} || $c->req->param('uid'); 36 my $password = $c->session->{password} || $c->req->param('password'); 37 38 if (!($uid && $password)) { 39 $c->stash->{template} = 'ballot/login.tt'; 40 return; 41 } 42 $c->session->{uid} = $uid; 43 $c->session->{password} = $password; 44 35 45 my $vote = $c->model('Vote'); 36 46 my %choices; … … 38 48 $choices{$_->{key}} = $_->{label}; 39 49 } 50 $c->stash->{choices} = { %choices }; 51 $c->stash->{sbal} = { map { $_ => 1 } $c->req->param('sbal') }; 40 52 41 53 my $uid = 'Olivier Thauvin'; # for test now 42 if ($c->req->param(' ballot')) {54 if ($c->req->param('confirm')) { 43 55 $vote->register_ballot( 44 56 $uid, … … 50 62 $c->req->address, 51 63 ); # TODO trap error 64 $c->forward('done'); 52 65 } 53 66 } 54 67 68 sub done : Private { 69 my ( $self, $c ) = @_; 70 $c->response->body('Vote réussi.'); 71 $c->delete_session('Vote terminé'); 72 } 55 73 56 74 =head1 AUTHOR -
trunk/root/templates/ballot/default.tt
r8 r9 3 3 [% thisvote = vote.vote_info(voteid) %] 4 4 [% thisvote.label | html %] 5 <hr> 6 7 [% IF c.req.param('ballot') %] 8 Confirmez votre vote: 9 <form action="[% c.uri_for(voteid) %]"> 10 [% FOREACH ch = c.req.param('sbal') %] 11 [% choices.$ch | html %] 12 <input type="hidden" name="sbal" value="[% ch %]"> 13 <br> 14 [% END %] 15 [% FOREACH ch = c.req.param('fsbal') %] 16 [% ch | html %]<br> 17 <input type="hidden" name="sbal" value="[% ch %]"> 18 [% END %] 19 <input type="submit" name="confirm"> 20 <input type="submit" name="Modify" value="Modifier mon vote"> 21 </form> 22 23 [% ELSE %] 5 24 6 25 <form action="[% c.uri_for(voteid) %]"> 7 26 [% FOREACH choice = vote.vote_choices(voteid) %] 8 <input type="checkbox" name="sbal" value="[% choice.key %]">[% choice.label | html %]<br> 27 [% key = choice.key %] 28 <input type="checkbox" name="sbal" value="[% choice.key %]"[% " checked" IF sbal.$key %]> 29 [% choice.label | html %]<br> 9 30 [% END %] 10 31 11 [% count = 1%]12 [% WHILE count < =thisvote.free_choice %]13 <input type="text" name="fsbal" value=" "><br>32 [% count = 0 %] 33 [% WHILE count < thisvote.free_choice %] 34 <input type="text" name="fsbal" value="[% c.req.param('fsbal').count %]"><br> 14 35 [% count = count + 1 %] 15 36 [% END %] 16 37 <input type="submit" name="ballot"> 17 38 </form> 39 40 [% END %]
Note: See TracChangeset
for help on using the changeset viewer.