fixed up kiosk mode
author<mako@atdot.cc> <>
Mon, 8 Jun 2009 15:45:34 +0000 (11:45 -0400)
committer<mako@atdot.cc> <>
Mon, 8 Jun 2009 15:45:34 +0000 (11:45 -0400)
app/controllers/voter_controller.rb
app/views/common/_sortable_vote.rhtml
app/views/election/show.rhtml
config/routes.rb

index a912824ebd25f6baf1539b320077e86004613ff3..9ba619c918a3f1e1a0858f8ba962984929b17c1d 100644 (file)
@@ -20,9 +20,7 @@ class VoterController < ApplicationController
           :conditions => ["session_id = ? and election_id = ?",
           session.session_id, @election.id])[0]
      
-        unless @voter and not @voter.election.kiosk
-          @voter = OpenVoter.new
-        end
+        @voter = OpenVoter.new unless @voter
 
         @voter.election = @election
         @voter.session_id = session.session_id
@@ -182,8 +180,10 @@ class VoterController < ApplicationController
   end
  
   def kiosk_ready
+    reset_session
+
     if not authenticate
-      redirect_to :action => 'index', :kiosk => true
+      redirect_to :action => 'index'
     end
   end
 
@@ -192,12 +192,27 @@ class VoterController < ApplicationController
     password = params[:id]
     if password == "open"
       election = Election.find(params[:format])
+
+      # check to see if the person has voted before
       unless election.authenticated?
         @voter = OpenVoter.find(:all,
           :conditions => ["session_id = ? and election_id = ?",
                           session.session_id, election.id])[0]
         @password = "open." + election.id.to_s
       end
+
+      # if it's ready for kiosk_mode, then we create and authenticate
+      unless @voter and params[:action] == 'kiosk_ready' \
+        and election.kiosk
+       
+        # this is maybe not quite as a dry as it should be
+        @voter = OpenVoter.new unless @voter
+
+        @voter.election = election
+        @voter.session_id = session.session_id
+        @password = "open." + election.id.to_s
+      end
+
     else
       @voter = FullVoter.find(:all,
         :conditions => [ "password = ?", password ] )[0]
index f026c4216378f65dfcd832b8699ce9beb6c5bb08..0fe6ad17d6d45b2617fb6f63e6f773707dfc04c7 100644 (file)
@@ -1,6 +1,6 @@
 <div id="sortable_list">
 <ol id="rankings-list">
-  <% for ranking in @voter.vote.rankings %>
+  <% for ranking in @voter.vote.rankings.sort %>
     <li class="moveable" id="ranking_<%= ranking.candidate.id %>">
       <%= white_list(ranking.candidate.name.capitalize) %></li>
   <% end %>
index ff116f47570a1a8f1cb1bab7e12b393a1b2744e8..2f628958434ab99c798dc75a8a0de69590c74ab5 100644 (file)
      (<%= votepassword_url(:urlpassword => "open." + @election.id.to_s) %>)</li>
 
 <% if @election.kiosk %>
-<li><%= (link_to ("Kiosk mode",
-          :controller => 'voter', :action => 'index', :election_id => @election.id, :kiosk => true)).to_s %>
-     (<%= votepassword_url(:urlpassword => "open." + @election.id.to_s, :kiosk => true) %>)</li>
+<li><%= link_to("Kiosk mode",
+           kiosk_ready_url(:urlpassword => "open." + @election.id.to_s,
+                           :kiosk => true)) %>
+        (<%= kiosk_ready_url(:urlpassword => "open." + @election.id.to_s, :kiosk => true) %>)
   <% end %>
 </ul>
 <% end -%>
index efd6a28e9fba914f696a9f78303ea6f3fc97ebc1..8ff6992d906468ba45e6c5bfea0afceeae3573e6 100644 (file)
@@ -27,6 +27,10 @@ ActionController::Routing::Routes.draw do |map|
                    :controller => 'voter',
                    :action => 'index'
 
+  map.kiosk_ready 'voter/kiosk_ready/:urlpassword',
+                  :controller => 'voter',
+                  :action => 'kiosk_ready'
+
   map.connect 'quickvote/:action/:id',
                :controller => 'quickvote',
                :requirements => { :action => /(create|add_candidate|sort_candidates|my_quickvotes)/ }

Benjamin Mako Hill || Want to submit a patch?