#these methods provide basic functionality for the user login system
#===================================================================
def login
+
return unless request.post?
self.current_user = User.authenticate(params[:login], params[:password])
if logged_in?
<div id="page-wrapper">
<div id="header">
+ <div id="top-bar">
+ <a href="/account/login">login</a>
+ <a href="/account/signup">sign up</a>
+ <a href="/site/about">help/about</a>
+ </div>
<a href="index.html"><h1>selectricity: voting machinery for the masses</h1></a>
</div>
-<h3>Approval Result</h3>
<p><font size="-1">(This algorithm assumes that top two choices are "approved.")</font></p>
-<%= render :partial => 'result', :object => @election.approval_result %>
-
<div class="rbmoreinfo">
<h4>About Approval Voting</h4>
accept or not.</p>
</div>
-
-<%= render :partial => 'approval_table' %>
\ No newline at end of file
-<h3>Borda Count Results</h3>
-
-<%= render :partial => 'result', :object => @election.borda_result %>
-
<div class="rbmoreinfo">
<h4>About Borda Count</h4>
-<h3>Simple Condorcet Results</h3>
-
-<%= render :partial => 'result', :object => @election.condorcet_result %>
-
<div class="rbmoreinfo">
<h4>About Simple Cordorcet Voting</h4>
-<h3>Plurality Results</h3>
-
-<%= render :partial => 'result', :object => @election.plurality_result %>
-
<div class="rbmoreinfo">
<h4>About Plurality Voting</h4>
voting.</p>
</div>
+
<%= image_tag(graph_url( :action => 'plurality_pie', :id => @election ) )%>
-<div class="resultbox">
-<h3>Instant Runoff (IRV) Results</h3>
-
<div class="rbmoreinfo">
<h4>About Instant Runoff Voting</h4>
by several other names.</p>
</div>
-
-</div>
\ No newline at end of file
-<h3>Schulze Method Results</h3>
-
-<%= render :partial => 'result', :object => @election.ssd_result %>
-
<div class="rbmoreinfo">
<h4>About the Schulze Method</h4>
-<% %>
+<div class="winner">
<% if result.winner? and result.winners.length == 1%>
- <p><em>The winner is:
- <strong><%=h @candidates[result.winner].name.capitalize %></strong></em></p>
+ <p>The winner is:
+ <strong><%=h @candidates[result.winner].name.capitalize %></strong></p>
<% elsif result.winner? and result.winners.length > 1 %>
- <p><em>There was a tie. The winners are: <strong><%=h( result.winners.collect {|w| @candidates[w].to_s.capitalize}.join(", ") )%></strong></em></p>
+ <p>There was a tie. The winners are: <strong><%=h( result.winners.collect {|w| @candidates[w].to_s.capitalize}.join(", ") )%></strong></p>
<% else %>
- <p><em>There is no winner using this method. </em></strong></p>
+ <p>There is no winner using this method. </strong></p>
<% end %>
+</div>
--- /dev/null
+<div id="<%= method %>_result" class="resultbox"<%= ' style="display: none;"' unless @election.election_method == method %>>
+<div class="normal-header">
+ <span class="header"><%= ELECTION_TYPES[method]%> </span>
+ <span class="subheader">
+ <% if @election.election_method == method %>
+ Selected Method
+ <% else %>
+ Alternative Method
+ <% end %></span>
+</div>
+
+<%= render :partial => 'methodinfo_' + method,
+ :object => @results[@election.election_method] %>
+
+</div>
+
+<h2>Winner</h2>
+<%= render :partial => 'result', :object => @results[@election.election_method] %>
+
+<p>This election was run using:
+<strong><%= ELECTION_TYPES[@election.election_method] %></strong></p>
+
+<p>View results with other methods:<br />
+<% type_hash = {}; ELECTION_TYPES.each {|k,v| type_hash[v] = k} %>
+<%= select_tag 'election_type_select', options_for_select(type_hash, @election.election_method) %></p>
+
+<script>
+var election_methods = new Array(<%= ELECTION_TYPES.keys.collect {|k| "'#{k}'"}.join(', ') %>);
+var method_select = $('election_type_select');
+
+function show_results_for() {
+ var test = $('test');
+
+ method_select.value;
+ var result_boxes = document.getElementsByClassName('resultbox');
+ for (i = 0; i < result_boxes.length; i++) {
+ result_box = result_boxes[i];
+ if (result_box.id == (method_select.value + "_result")) {
+ Element.show(result_box);
+ } else {
+ Element.hide(result_box);
+ }
+ }
+
+ //alert(method_select.value);
+}
+
+Event.observe(method_select, 'change', show_results_for);
+</script>
+
+<h2>Statistics</h2>
<%= image_tag( graph_url( :action => 'votes_per_interval', :id => @election ))%>
<%= @election.voters.reject {|v| not v.voted? }.length %> (see below for details)
</blockquote>
-<div class="normal-header">
- <span class="header">Winner</span>
- <span class="subheader">Computed with
- <%= ELECTION_TYPES[@election.election_method] %></span>
-</div>
+<%= render :partial => 'result_box',
+ :locals => { :method => @election.election_method } %>
-<div class="mainresultbox">
-<%= render :partial => 'result_' + @election.election_method,
- :object => @results[@election.election_method] %>
-</div>
+<% for result_type in @election.other_methods %>
-<div class="normal-header">
- <span class="header">Other Voting Methods</span>
- <span class="subheader"></span>
-</div>
+<%= render :partial => 'result_box',
+ :locals => { :method => result_type } %>
-<% for result_type in @election.other_methods %>
-<div class="resultbox">
-<%= render :partial => 'result_' + result_type,
- :object => @results[result_type] %>
-</div>
<% end %>
<div class="clear-div"></div>
-<h2>Voters <%= link_to "[Stalk Voters]", :controller => "quickvote", :action => "mapvoters", :id => @election.id %></h2>
+<div class="normal-header">
+ <span class="header">Voter Report</span>
+ <span class="subheader"></span>
+</div>
+
+<p><%= link_to "[Stalk Voters]", :controller => "quickvote", :action => "mapvoters", :id => @election.id %></p>
<table class="voterbox">
<tr>
<th>IP/Host</th>
<% form_tag :controller => 'account', :action => 'login' do %>
<p><label for="login">Login</label></p>
- <p><%= text_field "Login", "login", :size => 30 %></p>
+ <p><%= text_field_tag 'login' %></p>
<p><label for="password">Password</label></p>
- <p><%= password_field "Password", "password", :size => 30 %></p>
+ <p><%= password_field_tag 'password' %></p>
- <p><%= submit_tag 'Login' %></p>
+ <p><%= submit_tag 'Log in' %></p>
<% end %>
<p><%= link_to 'Register for an account', :controller => 'account', :action => 'signup' %></p>
<p>You must have an account to start a new vote or to administer an
existing vote. You can log in or create a new account below.</p>
-
- <%= render_partial 'basic_login' %>
+
+ <%= render :partial => 'basic_login' %>
<% end %>
</div>
# Use the database for sessions instead of the file system
# (create the session table with 'rake db:sessions:create')
- # config.action_controller.session_store = :active_record_store
+ config.action_controller.session_store = :active_record_store
# Use SQL instead of Active Record's schema dumper when creating the test database.
# This is necessary if your schema can't be completely dumped by the schema dumper,
require 'gruff-0.2.8/lib/gruff'
require 'sparklines'
require 'rubyvote'
-ELECTION_TYPES = {'ssd' => "Schulze Sequential Dropping",
- 'plurality' => "Plurality/First Past the Post",
- 'approval' => "Approval (Top Two)",
- 'condorcet' => "Simple Condorcet",
+ELECTION_TYPES = {'ssd' => "Schulze Method",
+ 'plurality' => "Plurality",
+ 'approval' => "Approval",
+ 'condorcet' => "Condorcet",
'borda' => "Borda Count"}
class String
primary key (id)
);
+# CREATE sessions TABLE
+######################################
+
+drop table if exists sessions;
+create table sessions (
+ id int(11) NOT NULL auto_increment,
+ sessid varchar(255),
+ data text,
+ updated_at datetime DEFAULT NULL,
+ primary key (id),
+ index session_index (sessid)
+);
+
# CREATE users TABLE
#####################################
#DROP TABLE IF EXISTS `users`;
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"
}
body {
- font-size: 11px;
+ font-size: 0.9em;
font-family: Trebuchet, Verdana, Arial, Helvetica, sans-serif;
}
#footer {
font-size: 11px;
- font-family: Verdana, Arial, Helvetica, sans-serif;
+ font-family: "Trebuchet MS", Trebuchet, Verdana, Arial, sans-serif;
margin-top: 40px;
text-align: center;
}
background: #FFFBB3;
border: 1px black solid;
text-align: center;
- font-weight: bold;
- padding: 5px 5px 5px 15px;
- width: 250px;
-}
+ font-weight: bold
padding: 0;
border: 0;
font-size: 100%;
- font-family: inherit;
+ font-family: "Trebuchet MS", Verdana, Arial, sans-serif;
vertical-align: baseline;
}
}
#body {
- font-family: "Trebuchet MS", Verdana, Arial, Helvetica, sans-serif;
+ font-family: "Trebuchet MS", Verdana, Arial, sans-serif;
color: white;
font-size: 12px;
text-align: left;
padding-top: 189px;
height: 0px;
margin-top: 10px;
+ margin-left: 231px;
+}
+
+#top-bar {
+
+ position: relative;
+ float: right;
+ width: 231px;
+ text-align: center;
+}
+
+#top-bar a {
+ color: black;
+ font-size: 11px;
+ text-decoration: none;
}
margin-bottom: 1em;
}
+
#voters {
padding-top: 50px;
height: 559px;
}
.normal-header {
- margin: 0 -20px 1em -20px;
+ margin: 1.3em -20px 1.3em -20px;
height: 32px;
background-color: #e5e5e5;
}