before_filter :login_required
- ## general methods for dealing with elections
- ####################################################################
- def index
- list
- render :action => 'list'
- end
-
- def list
- @election_pages, @elections = paginate :elections, :per_page => 10
- end
-
## methods for displaying, creating,
## and manipulating election overview data
####################################################################
- def show
- @election = Election.find(params[:id])
- end
-
def new
@election = Election.new
end
- def edit
- @election = Election.find(params[:id])
- end
-
def create_election
@election = Election.new(params[:election])
+
+ # default options
+ @election.user = session[:user]
+ @election.anonymous = 1
+ @election.startdate = Time.now
+
if @election.save
flash[:notice] = 'Election was successfully created.'
redirect_to :action => 'new_candidates', :id => @election.id
render :action => 'new'
end
end
+
+ # add filter to verify that the person working on or looking at
+ # something is the owner
+ def edit
+ @election = Election.find(params[:id])
+ end
+
+ def show
+ @election = Election.find(params[:id])
+ end
def update
@election = Election.find(params[:id])
def add_candidate
election = Election.find( params[:id] )
@candidate = Candidate.new
- @candidate.name = params[:newcandidate]
+ @candidate.name = params[:newcandidate][:name]
+ @candidate.description = params[:newcandidate][:description]
+
@candidate.save
election.candidates << @candidate
render :partial => 'candidate_line'
class SiteController < ApplicationController
layout 'vb'
+ model :user, :election
def index
+ @current_elections = session[:user].elections.sort do |a,b|
+ b.enddate <=> a.enddate
+ end
+
+
end
end
has_many :candidates
has_many :voters
has_many :votes
+ belongs_to :user
validates_presence_of :name, :description
require 'date'
--- /dev/null
+class User < ActiveRecord::Base
+ include LoginEngine::AuthenticatedUser
+ has_many :elections
+
+ def name
+ [ firstname, lastname].join(" ")
+ end
+end
+
+<% %>
<p>Please enter candidates for <strong><%= @election.name %></strong>.</p>
- <%= form_remote_tag(:update => "candidate_list",
- :url => { :action => :add_candidate, :id => @election.id },
- :position => "top" ) %>
+<%= form_remote_tag(:update => "candidate_list",
+ :url => { :action => :add_candidate, :id => @election.id },
+ :position => "bottom" ) %>
- <p>New candidate name:
- <%= text_field_tag :newcandidate %>
+<p>New candidate name:<br />
+<%= text_field :newcandidate, :name %></p>
+
+<p>Candidate description/platform (optional):<br />
+<%= text_area :newcandidate, :description %></p>
- <%= submit_tag "Add" %>
- <%= end_form_tag %>
+<%= submit_tag "Add Candidate" %>
+<%= end_form_tag %>
<p><label for="election_description">Description</label><br/>
<%= text_area 'election', 'description' %></p>
+<!--
<p><label for="election_anonymous">Anonymous Vote</label>
<%= check_box 'election', 'anonymous', {}, 1, 0 %></p>
<p>Election/Voting Start Date<br />
<%= datetime_select :election, :startdate %></p>
+-->
-<p>Election/Voting End Date<br />
+<p>Election End Date<br />
<%= datetime_select :election, :enddate %></p>
<!--[eoform:election]-->
<% @edit = true %>
-<h1><strong><%= @election.name %>:</strong> Enter Candidates</h1>
+<h1><strong><%= @election.name %></strong> Candidates</h1>
+
+<ul id="candidate_list">
+<% for candidate in @election.candidates %>
+ <li><%= candidate.name %></li>
+<% end %>
+</ul>
<%= render :partial => 'candidates_form' %>
<%= button_to "Done!", :action => 'show', :id => @election %>
<% if session[:user] %>
Welcome <strong><%= session[:user].login.capitalize %></strong>
<% else %>
- <%= link_to("Login",:controller => "account", :action => "login") %>/<%= link_to("Sign up", :controller => "account", :action => "signup")%>
+ <%= link_to("Login",:controller => "user", :action => "login")
+ %>/<%= link_to("Sign up", :controller => "user", :action => "signup")%>
<% end %> |
- <%= link_to("Home", :controller => "site", :action => "index")%> |
- <%= link_to("Browse", :controller => "site", :action => "index")%> |
-
<% if session[:user] %>
- <%= link_to("Logout", :controller => "account", :action => "logout") %> |
+ <%= link_to("Logout", :controller => "user", :action => "logout") %> |
<% end %>
<%= link_to("Help/About", :controller => "site", :action => "about") %>
</table>
<div class="button-bar">
- <%= submit_tag 'Login' %>
- <%= link_to 'Register for an account', :controller => 'user', :action => 'signup' %> |
- <%= link_to 'Forgot my password', :controller => 'user', :action => 'forgot_password' %> </div>
+ <p><%= submit_tag 'Login' %></p>
+ <p><%= link_to 'Register for a new account?', :controller => 'user', :action => 'signup' %></p>
+ <p><%= link_to 'Lost or forgot your password?', :controller => 'user', :action => 'forgot_password' %></p>
+ </div>
<%= end_form_tag %>
--- /dev/null
+<% %>
+
+<h2>Activity Summary</h2>
+
+<% if @current_elections.length < 1 %>
+ <em>You have not created any elections.</em>
+<% else %>
+ <ul>
+ <% for election in @current_elections %>
+ <li><%= election.name %> (ends <em><%= election.enddate %></em>)</li>
+ <% end %>
+ </ul>
+<% end %>
+
+<p><%= link_to "Create a new election", :controller => 'election', :action => 'new' %></p>
+<p></p>
+
<td width="6%"></td>
<td width="47%" valign="top">
-<h2>Vote Administrators</h2>
-<p>You must have an account to start a new election or to administer an
-existing vote. You can log in or create a new account below.</p>
+<% if session[:user] %>
+ <%= render_partial 'user_summary' %>
+<% else %>
+ <h2>Election Administrators</h2>
+ <p>You must have an account to start a new election 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 %>
</td>
</tr>
</table>
--- /dev/null
+<div title="<%= title_helper %>" class="form">
+ <h3>Please Login</h3>
+
+ <div class="form-padding">
+ <%= start_form_tag :action => 'login' %>
+ <table>
+ <%= form_input :text_field, "Login ID", "login", :size => 30 %>
+ <%= form_input :password_field, "Password", "password", :size => 30 %>
+ </table>
+
+ <div class="button-bar">
+ <p><%= submit_tag 'Login' %></p>
+ <p><%= link_to 'Register for an account', :action => 'signup' %></p>
+ <p><%= link_to 'Forgot my password', :action => 'forgot_password' %></p>
+ </div>
+ <%= end_form_tag %>
+ </div>
+</div>
anonymous tinyint NOT NULL DEFAULT 0,
startdate datetime NOT NULL,
enddate datetime,
- primary key (id)
+ user_id int NOT NULL,
+ primary key (id),
+ constraint fk_user_election foreign key (user_id) references users(id)
);
# CREATE candidates TABLE
id int NOT NULL auto_increment,
election_id int NOT NULL,
name varchar(100) NOT NULL,
+ description text NULL,
picture blob NOT NULL,
primary key (id)
);
p, blockquote, ul, ol, dl, dd, li, dir, menu {}
h1, h2, h3, h4 {
- border-bottom: 1px solid #009999;
+ border-bottom: 1px solid #BD7589;
text-shadow: #999999 0.2em 0.2em 3px;
}
-a:link { font-weight: bold; color: #066; text-decoration: underline; }
-a:visited { color: #066; text-decoration: underline; }
+a:link { font-weight: bold; color: #BD7589; text-decoration: underline; }
+a:visited { color: #BD7589; text-decoration: underline; }
a:hover { color: #FFFFFF; text-decoration: none; background: #0063DC; }
a:active { color: #FFFFFF; text-decoration: none; background: #0259C4; }
list-style: square;
}
-
-
-#top { margin : 0px;
- padding : 3px;
+#top { padding-left: 10px;
+ padding-right: 10px;
+ padding-top: 5px;
+ padding-bottom: 5px;
font-weight: normal;
- background: #009999;
+ background: #BD7589;
color: #FFFFFF;
-
}
#top h3 { font-size: 30px; }
-
-#links { text-align : right;
- margin-right: 50px; }
-#links a { color: #EAFFD0; }
+#links { text-align : right; }
+#links a { color: #FFF; }
#links a:visited { font-weight: bold; }
.ListLine0 {