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
:data => data,
:interval_labels => labels,
:title => "Voters Over Time",
- :size => "700x400",
+ :size => "270x230",
:x_axis_label => scale,
:y_axis_label => "Number of Votes")
send_data(*graph.output)
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")
@results = @election.results
@candidates = {}
@election.candidates.each {|c| @candidates[c.id] = c}
+ @sidebar_content = render_to_string :partial => 'results_sidebar'
end
def my_quickvotes
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/>
--- /dev/null
+<%= image_tag( graph_url( :action => 'votes_per_interval', :id => @election ))%>
+
<div style="clear:both;"></div>
</div>
-<div class="main-content">
-
<p><label for="quickvote_candidate_names">Choices</p>
<!-- the list of candidates -->
<% end %>
-</div>
<span class="subheader">Results</span>
</div>
-<div class="main-content">
-
<% if @election.shortdesc %>
<p><strong>Vote Description:</strong></p>
<blockquote><em><%=h @election.shortdesc %></em>
<% end %>
</table>
-<%=image_tag( graph_url( :action => 'votes_per_interval', :id => @election ))%>
<br />
+<!--
<%= image_tag( graph_url( :action => 'choices_positions', :id => @election ) ) %><br />
+-->
-</div>
<div style="clear:both;"></div>
</div>
-<div class="main-content">
-
<p>Please direct voters to:</p>
<blockquote><strong>
participate in this election.</p>
<p><%= link_to "Jump to QuickVote", quickvote_url( :ident => @quickvote.name ) %></p>
-</div>
<span class="subheader">Vote Recorded Successfully</span>
</div>
-<div class="main-content">
-
<p>Your vote has been recorded with the following ranked
preferences:</p>
<li><%= link_to "View Current Results", quickaction_url( :ident => @voter.election.name, :action => 'results' ) %></li>
</ul>
-</div>
<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)
);
overflow: hidden;
}
+#page-title {
+ margin: -20px -20px 1em -20px;
+}
+
.plain-header {
- margin: 1em -1.2em 1em -1.2em;
+ margin: 1em -20px 1em -20px;
}
.header {
#main-box {
float: right;
- width: 611px;
- padding: 0;
+ width: 571px;
+ padding: 20px;
background: #f9f9f9;
border: 1px solid #b3b3b3;
}
-.main-content {
- margin: 1.2em;
- line-height: 1.5em;
- text-color: #454545;
-}
-
-.main-content p, .main-content blockquote, .main-content ul {
+#main-box p, #main-box blockquote, #main-box ul {
margin-bottom: 1em;
}