include AuthenticatedSystem
helper :user
require_dependency "user"
+
before_filter :add_stylesheets
def initialize
end
end
+ #both election_controller and quickvote_controller need this method
+ def sort_candidates
+ @vote = Vote.find(params[:id])
+
+ @vote.rankings.each do |ranking|
+ ranking.rank = params['rankings-list'].index(ranking.candidate.id.to_s) + 1
+ ranking.save
+ end
+ render :nothing => true
+ end
end
def start_election
@election = Election.find(params[:id])
-
@election.voters.each do |voter|
+ voter.vote = Vote.new
email = VoterNotify.deliver_votestart(voter)
#render(:text => "<pre>" + email.encoded + "</pre>")
end
@election.activate!
redirect_to :action => 'show', :id => @election.id
end
-
- def change_notices
- election = Election.find(params[:id])
- if election.notices == 0
- election.notices = 1
- else
- election.notices = 0
- end
- end
# methods fod display, adding, deleting, and manipulating candidate
# information for elections
def lessinfo_candidate
@show_details = false
- @candidate = Candidate.find( params[:id] )
+ @current_candidate = Candidate.find( params[:id] )
render :partial => 'candidate_line'
end
def moreinfo_candidate
@show_details = true
- @candidate = Candidate.find( params[:id] )
+ @current_candidate = Candidate.find( params[:id] )
render :partial => 'candidate_line'
end
@election.voters. each do |voter|
if voter.vote and voter.vote.confirmed?
@voter_list << voter.email
- @vote_list << voter.vote
+ @vote_list << voter.vote
end
end
unless incoming_voters.entries.empty?
incoming_voters.each do |new_voter|
-
+
if incoming_voters.email == 0
new_voter.contacted = 1
elsif incoming_voters.email == 1
voter.destroy
redirect_to quickvote_url( :ident => params[:ident] )
end
-
- def sort_candidates
- @vote = Vote.find(params[:id])
-
- @vote.rankings.each do |ranking|
- ranking.rank = params['rankings-list'].index(ranking.candidate.id.to_s) + 1
- ranking.save
- end
- render :nothing => true
- end
def mapvoters
@map = GMap.new("map_div_id")
password = params[:id]
password = params[:vote][:password] if params[:vote]
if @voter = FullVoter.find(:all, :conditions => [ "password = ?", password ] )[0]
- render :action => 'fullvote'
+ @voter.vote = Vote.new if @voter.vote.nil?
+ @voter.vote.set_defaults! if @voter.vote.rankings.empty?
+ render :action => 'full_vote'
end
end
def review
if authenticate
- # remove any existing votes and reload
- if @voter.vote
- @voter.vote.destroy
- @voter.reload
- end
-
- @vote = Vote.new
- @voter.vote = @vote
- @vote.votestring = params[:vote][:votestring]
- @vote.save
+ @voter.vote.time = Time.now
+ @voter.vote.save
+ @voter.reload
else
redirect_to :action => 'index'
end
class FullVoter < Voter
- before_create :create_password
validates_presence_of :email, :password
+ def initialize(params={})
+ super
+ create_password
+ end
+
def create_password
token_generator = UniqueTokenGenerator.new( 16 )
until password and not password.empty? \
def each
@input_addresses.split("\n").each do |address|
- yield Voter.new( { :email => address } )
+ yield FullVoter.new( { :email => address } )
end
end
end
-class Token < ActiveRecord::Base
- belongs_to :vote
-
+class Token < ActiveRecord::Base
+ belongs_to :vote
+
def initialize
super
# callbacks
after_update :save_rankings
before_destroy :destroy_rankings
-
-
def to_s
votes.join("")
end
def votestring=(string="")
candidate_ids = voter.election.candidates.sort.collect \
{ |candidate| candidate.id.to_i }
-
+
rel_votes = string.split("").collect { |vote| vote.to_i }
# covert relative orders to absolute candidate ids
self.votes.collect {|v| cand_relnums[v]}.join("")
end
- # the following subroutine is used for quickvotes. it creates a vote
- # with the candidates listed in order of preference based on
- # alphabetical order. it is meant to be manipulated and then confirmed
- def set_defaults!
- self.votes = voter.election.candidates.sort.collect {|c| c.id }
+ # the following subroutine is used for quickvotes, but need for elections now
+ # too. It creates a vote with the candidates listed in order of preference
+ # based on alphabetical order. It is meant to be manipulated and then confirmed
+ def set_defaults!
+ self.votes = voter.election.candidates.sort.collect {|c| c.id }
self.save
end
+
end
class Voter < ActiveRecord::Base
belongs_to :election
has_one :vote
-
+
+ def reset_vote
+ self.vote.destroy
+ self.reload
+ end
+
def destroy
vote.destroy if vote
super
-<% -%>
<div id="cand<%= @current_candidate.id %>">
<li><%=h @current_candidate.name -%>
<% if @show_details %>
(<%= link_to_remote "Hide Details",
:update => "cand#{@current_candidate.id}",
- :url => { :action => :lessinfo_candidate, :id => @current_candidate.id } %>)
+ :url => { :action => :lessinfo_candidate,
+ :id => @current_candidate.id } %>)
<br />
<blockquote>
- <%= h(@current_candidate.description) %>
+ <%=h (@current_candidate.description) %>
</blockquote>
<% else %>
(<%= link_to_remote "Show Details",
:update => "cand#{@current_candidate.id}",
:url => { :action => :moreinfo_candidate,
- :id => @current_candidate.id } %>)
+ :id => @current_candidate.id } %>)
<% end %>
</li>
</div>
<% %>
<ul id="candidate_list">
<% @election.candidates.each do |candidate| %>
- <% @current_candidate = candidate %>
- <%= render :partial => 'candidate_line' %>
+ <% @current_candidate = candidate %>
+ <%= render(:partial => 'candidate_line')%>
<% end %>
</ul>
<%= error_messages_for 'election' %>
<!--[form:election]-->
-<p><label for="election_name">Summary</label><br/>
+<p><label for="election_name">Title</label><br/>
<%= text_field 'election', 'name', :size => 60 %></p>
<p><label for="election_description">Description</label><br/>
<div id="control-room" class="main-section">
<div id="control-room-content">
<h2>Control Room</h2>
-
<% if session[:user] %>
<%= render :partial => 'user_summary' %>
<% else %>
--- /dev/null
+<% %>
+<div id="sortable_list">
+<ol id="rankings-list">
+ <% for ranking in @voter.vote.rankings %>
+ <li class="moveable" id="ranking_<%= ranking.candidate.id %>">
+ <%=h ranking.candidate.name.capitalize %></li>
+ <% end %>
+</ol>
+</div>
+
+<div class="clearbox"></div>
+
+<%= sortable_element 'rankings-list',
+ :url => { :action => "sort_candidates", :id => @voter.vote.id },
+ :complete => visual_effect(:highlight, 'rankings-list') %>
\ No newline at end of file
least preferred. Please list <em>all</em> choices in every vote.
<em>(For example, 123 or 321 or 213, etc.)</em></p>
-<% if @voter.election.quickvote? %>
- <% form_tag(quickaction_url( :ident => @voter.election.name, :action => 'confirm')) do %>
-<% else %>
- <%= form_tag :action => 'review', :id => @voter.password %>
-<% end %>
-
+<%= form_tag :action => 'review', :id => @voter.password %>
<%= text_field :vote, :votestring -%>
<%= submit_tag "Vote!" %>
-<% end %>
+
<p><strong>Description:</strong></p>
<blockquote><%= @voter.election.description %></blockquote>
-<%= render_partial 'vote' %>
+<%= render :partial => 'vote' %>
+<%= render :partial => 'sortable_vote' %>
+
+<%= button_to "Submit Vote", :action => 'review', :id => @voter.password %>
<% %>
+<% %>
<h1>Please review your vote carefully before confirming it.</h1>
<p>You have ranked the candidates in the following order (from most
preferred to least preferred:</p>
<ol>
- <% for rank in @vote.rankings.sort %>
- <li><%= rank.candidate.name %> </li>
+ <% for rank in @voter.vote.rankings.sort %>
+ <li><%=h rank.candidate.name.capitalize %> </li>
<% end %>
</ol>
<%= @voter.password %>
Alternatively, you can just click this URL:
- <%= url_for :controller => 'election', :action => 'show', :id => @voter.election.id %>
+ http://selectricity.media.mit.edu<%= url_for :controller => 'election', :action => 'show', :id => @voter.election %>
If you have any questions or if you feel you have received this message
in error, you should contact:
election_id int NOT NULL,
session_id varchar(32) DEFAULT NULL,
ipaddress varchar(32) DEFAULT NULL,
+ `type` varchar(100) NOT NULL,
constraint fk_election_voter foreign key (election_id) references election(id),
primary key (id)
);
create_table "voters", :force => true do |t|
t.column "email", :string, :limit => 100
t.column "password", :string, :limit => 100
- t.column "contacted", :integer, :limit => 4, :default => 0, :null => false
- t.column "election_id", :integer, :null => false
+ t.column "contacted", :integer, :limit => 4, :default => 0, :null => false
+ t.column "election_id", :integer, :null => false
t.column "session_id", :string, :limit => 32
t.column "ipaddress", :string, :limit => 32
+ t.column "type", :string, :limit => 100, :default => "", :null => false
end
add_index "voters", ["election_id"], :name => "fk_election_voter"