From 34fe63727a8929d7e9c529feee1f0c1e827acdfa Mon Sep 17 00:00:00 2001
From:
Date: Fri, 13 Oct 2006 18:06:08 -0400
Subject: [PATCH] a long variety of improvements and tweaks
---
app/controllers/election_controller.rb | 12 ++-
app/controllers/site_controller.rb | 16 +++-
app/models/election.rb | 20 ++++-
app/models/quick_vote.rb | 2 +-
app/models/voter_notify.rb | 2 +-
app/views/election/_candidate_form.rhtml | 4 +-
app/views/election/_candidate_line_edit.rhtml | 9 +-
app/views/election/_overview_form.rhtml | 9 +-
app/views/election/_voters_form.rhtml | 3 +-
app/views/election/edit_candidates.rhtml | 2 +-
app/views/election/edit_voters.rhtml | 2 +-
app/views/election/new.rhtml | 4 +-
app/views/election/show.rhtml | 86 +++++++++++--------
app/views/user/_edit.rhtml | 9 ++
app/views/voter_notify/votestart.rhtml | 1 +
config/environment.rb | 7 +-
public/stylesheets/hc.css | 12 ++-
17 files changed, 139 insertions(+), 61 deletions(-)
create mode 100644 app/views/user/_edit.rhtml
diff --git a/app/controllers/election_controller.rb b/app/controllers/election_controller.rb
index 7145d3d..3a43c8e 100644
--- a/app/controllers/election_controller.rb
+++ b/app/controllers/election_controller.rb
@@ -52,11 +52,12 @@ class ElectionController < ApplicationController
@election = Election.find(params[:id])
@election.voters.each do |voter|
- email = VoterNotify.create_votestart(voter)
- render(:text => "" + email.encoded + " ")
+ email = VoterNotify.deliver_votestart(voter)
+ #render(:text => "" + email.encoded + " ")
end
- #@election.activate!
+ @election.activate!
+ redirect_to :action => 'show', :id => @election.id
end
# methods fod display, adding, deleting, and manipulating candidate
@@ -213,7 +214,10 @@ class ElectionController < ApplicationController
@raw_voter_list.email = incoming_voters.email
end
- def email_voter
+ def email_voter(email=nil)
+ if email
+
+ end
end
end
diff --git a/app/controllers/site_controller.rb b/app/controllers/site_controller.rb
index daa74f8..47ae2cb 100644
--- a/app/controllers/site_controller.rb
+++ b/app/controllers/site_controller.rb
@@ -3,10 +3,20 @@ class SiteController < ApplicationController
model :user, :election
def index
+ # if the person claims they are logged in
if session[:user]
- session[:user] = User.find(session[:user].id)
- @current_elections = session[:user].elections.sort do |a,b|
- b.enddate <=> a.enddate
+
+ # check to see that we actually have record of them
+ if User.find_all(["id = ?", session[:user].id]).length == 1
+ # if we have record of them, grab the list of their elections
+ session[:user] = User.find(session[:user].id)
+ @current_elections = session[:user].elections.sort do |a,b|
+ b.enddate <=> a.enddate
+ end
+ else
+ # if we have no record of them, set the session id back to
+ # nothing and start again
+ session[:user] = nil
end
end
end
diff --git a/app/models/election.rb b/app/models/election.rb
index eaf0727..0907e68 100644
--- a/app/models/election.rb
+++ b/app/models/election.rb
@@ -8,11 +8,18 @@ class Election < ActiveRecord::Base
require 'date'
def startdate
- read_attribute( :startdate ) || DateTime.now
+ read_attribute( :startdate ) || Time.now
end
def enddate
- read_attribute( :enddate ) || DateTime.now + 14
+ date = read_attribute( :enddate ) || Time.now + 14
+ date - 1.second
+ end
+
+ def enddate=(date)
+ date += 1.day
+ date = Time.gm(*date)
+ super(date)
end
def destroy
@@ -38,12 +45,21 @@ class Election < ActiveRecord::Base
def activate!
self.active = 1
+ self.save!
end
def quickvote?
quickvote.to_i == 1
end
+ def active?
+ active == 1
+ end
+
+ def done?
+ active == 2
+ end
+
def shortdesc
shortdesc = description.split(/\n/)[0]
end
diff --git a/app/models/quick_vote.rb b/app/models/quick_vote.rb
index fba31a8..1df25af 100644
--- a/app/models/quick_vote.rb
+++ b/app/models/quick_vote.rb
@@ -16,7 +16,7 @@ class QuickVote < Election
def initialize(params={})
super
- self.enddate = DateTime.now + 30
+ self.enddate = Time.now + 30
self.active = 1
self.anonymous = 1
self.quickvote = 1
diff --git a/app/models/voter_notify.rb b/app/models/voter_notify.rb
index 09f7899..d9fded5 100644
--- a/app/models/voter_notify.rb
+++ b/app/models/voter_notify.rb
@@ -1,7 +1,7 @@
class VoterNotify < ActionMailer::Base
def votestart(voter)
- @subject = "[%s] Election In Progress!" % voter.election.name
+ @subject = "[%s] Election Begun!" % voter.election.name
@recipients = voter.email
@from = MAIL_CONFIG[:from]
@sent_on = Time.now
diff --git a/app/views/election/_candidate_form.rhtml b/app/views/election/_candidate_form.rhtml
index 6e0fb1f..ed14dff 100644
--- a/app/views/election/_candidate_form.rhtml
+++ b/app/views/election/_candidate_form.rhtml
@@ -1,10 +1,10 @@
<% %>
New candidate name:
-<%= text_field :candidate, :name %>
+<%= text_field :candidate, :name, :size => 60 %>
Candidate description/platform (optional):
-<%= text_area :candidate, :description %>
+<%= text_area :candidate, :description, :cols => 60, :rows => 5 %>
Candidate picture (optional and < 100x100 pixels):
<%= file_field :candidate, :picture %>
diff --git a/app/views/election/_candidate_line_edit.rhtml b/app/views/election/_candidate_line_edit.rhtml
index ea20a4f..78f8580 100644
--- a/app/views/election/_candidate_line_edit.rhtml
+++ b/app/views/election/_candidate_line_edit.rhtml
@@ -12,13 +12,18 @@
<% if @current_candidate.picture? %>
+ align="top" width="80px" />
<% end %>
+ <% if @current_candidate.description.length > 0 %>
Description:
<%= h(@current_candidate.description) %>
-
+
+ <% else %>
+
+ <% end %>
+
diff --git a/app/views/election/_overview_form.rhtml b/app/views/election/_overview_form.rhtml
index 899f00b..d5d7b6c 100644
--- a/app/views/election/_overview_form.rhtml
+++ b/app/views/election/_overview_form.rhtml
@@ -1,11 +1,11 @@
<%= error_messages_for 'election' %>
-Name
-<%= text_field 'election', 'name' %>
+Summary
+<%= text_field 'election', 'name', :size => 60 %>
Description
-<%= text_area 'election', 'description' %>
+<%= text_area 'election', 'description', :rows => 5, :cols => 60 %>
Election End Date
-<%= datetime_select :election, :enddate %>
+All elections end at 23:59.
+<%= date_select :election, :enddate %>
diff --git a/app/views/election/_voters_form.rhtml b/app/views/election/_voters_form.rhtml
index 3b01c00..87df4ce 100644
--- a/app/views/election/_voters_form.rhtml
+++ b/app/views/election/_voters_form.rhtml
@@ -1,7 +1,7 @@
Please enter a list of new email addresses of voters (one email
address per line).
-<%= text_area :raw_voter_list, :input_addresses %>
+<%= text_area :raw_voter_list, :input_addresses, :cols => 60, :rows => 8 %>
+<%= hidden_field :raw_voter_list, :email, :value => 2 %>
<%= submit_tag "Add Voters" %>
diff --git a/app/views/election/edit_candidates.rhtml b/app/views/election/edit_candidates.rhtml
index dbcc3f8..cc2c16a 100644
--- a/app/views/election/edit_candidates.rhtml
+++ b/app/views/election/edit_candidates.rhtml
@@ -1,4 +1,4 @@
-<%= @election.name %>: Edit/Add Candidates
+Edit/Add Candidates
<%= error_messages_for :candidate %>
diff --git a/app/views/election/edit_voters.rhtml b/app/views/election/edit_voters.rhtml
index 36de3eb..429a907 100644
--- a/app/views/election/edit_voters.rhtml
+++ b/app/views/election/edit_voters.rhtml
@@ -1,5 +1,5 @@
<% @edit = true %>
-<%= @election.name %>: Edit Voter Rolls
+Edit Voter List
<%= render :partial => 'voter_list' %>
diff --git a/app/views/election/new.rhtml b/app/views/election/new.rhtml
index 5e6fa1f..fc390a0 100644
--- a/app/views/election/new.rhtml
+++ b/app/views/election/new.rhtml
@@ -1,6 +1,6 @@
-Create A New Election
+Create A New Vote
-Step 1: Describe The Election
+Vote Overview
<%= form_tag :action => 'create_election' %>
<%= render :partial => 'overview_form' %>
diff --git a/app/views/election/show.rhtml b/app/views/election/show.rhtml
index 90c93ea..0051861 100644
--- a/app/views/election/show.rhtml
+++ b/app/views/election/show.rhtml
@@ -1,30 +1,47 @@
<% %>
-Information On <%= @election.name %>
+Vote Information
+
+<% if @election.active? %>
+ Vote is in currently in progress. Return to
+ this page for results on <%= @election.enddate %>.
+<% elsif @election.done? %>
+ Election is finished. <%= link_to "View results",
+ :action => 'results', :id => @election.id %>.
+<% end %>
+
+Overview
+
+Summary
+
+
+<%= h(@election.name) %>
+
-Election Overview
-
Description
<%= h(@election.description) %>
-Election End Date
+End Date
<%= @election.enddate %>
-<%= link_to "Edit election overview.", :action => 'edit', :id => @election.id %>
+<% unless @election.active %>
+<%= link_to "Edit overview.", :action => 'edit', :id => @election.id %>
+<% end %>
Candidates
<% unless @election.candidates.empty? %>
<%= render :partial => 'candidate_list' %>
+ <% unless @election.active %>
<%= link_to "Add, remove, or edit candidates.", :action => 'edit_candidates', :id => @election.id %>
+ <% end %>
<% else %>
- There are currently no candidates registered for this election.
- <%= link_to "Add some!", :action => 'edit_candidates', :id => @election.id %>
+ There are currently no candidates registered. <%= link_to "Add some!", :action => 'edit_candidates', :id => @election.id unless @election.active %>
<% end %>
@@ -32,36 +49,37 @@
<% unless @election.voters.empty? %>
<%= render :partial => 'voter_list' %>
- <%= link_to "Add or remove voters.", :action => 'edit_voters', :id => @election.id %>
+ <%= link_to "Add or remove voters.", :action => 'edit_voters', :id => @election.id unless @election.active %>
<% else %>
- There are currently no voters registered for this election.
- <%= link_to "Add some!", :action => 'edit_voters', :id => @election.id %>
+ There are currently no voters registered. <%= link_to "Add some!", :action => 'edit_voters', :id => @election.id unless @election.active %>
<% end %>
-Start Election
-
-<% if @election.start_blockers.length > 0 %>
- Your election cannot be started for the following reasons:
-
- <% for reason in @election.start_blockers %>
- <%= reason %>
+<% unless @election.active %>
+ Start Election
+
+ <% if @election.start_blockers.length > 0 %>
+ Your vote cannot be started for the following reasons:
+
+ <% for reason in @election.start_blockers %>
+ <%= reason %>
+ <% end %>
+
+ <% else %>
+ Please check eveything carefully on this page before starting this
+ vote. Once you begin the vote, you will not be able to add or
+ change candidates, modify the voting lists, or change the end
+ time.
+
+ When you begin the vote, the following will happen:
+
+
+ The vote will be "frozen" so that further edits to the
+ candidate list and voting list cannot occur.
+ All voters will be emailed notifying them that the vote has
+ begun and of their unique login token.
+
+
+ <%= button_to 'Start Election!', :action => 'start_election', :id => @election.id %>
<% end %>
-
-<% else %>
-Please check eveything carefully on this page before starting this
-election. Once you begin the election, you will not be able to
-add or change candidates, modify the voting lists, or change the
-election end time.
-
-When you begin the election, the following will happen:
-
-
- The election will be "frozen" so that further edits to the
- candidate list and voting list cannot occur.
- All voters will be emailed notifying them that the election has
- begun and of their unique login token.
-
-
-<%= button_to 'Start Election!', :action => 'start_election', :id => @election.id %>
<% end %>
diff --git a/app/views/user/_edit.rhtml b/app/views/user/_edit.rhtml
new file mode 100644
index 0000000..80fbac1
--- /dev/null
+++ b/app/views/user/_edit.rhtml
@@ -0,0 +1,9 @@
+
+
+ <%= form_input changeable(user, "login"), "Login ID", "login", :size => 30 %>
+ <%= form_input changeable(user, "email"), "Email", "email" %>
+ <% if submit %>
+ <%= form_input :submit_button, (user.new_record? ? 'Signup' : 'Change Settings'), :class => 'two_columns' %>
+ <% end %>
+
+
diff --git a/app/views/voter_notify/votestart.rhtml b/app/views/voter_notify/votestart.rhtml
index c2918da..ead6a43 100644
--- a/app/views/voter_notify/votestart.rhtml
+++ b/app/views/voter_notify/votestart.rhtml
@@ -11,6 +11,7 @@ need to use the following token to log in to hyperchad.media.mit.edu:
<%= @voter.password %>
Alternatively, you can just click this URL:
+ <%= url_for :controller => 'election', :action => 'show', :id => @voter.election.id %>
If you have any questions or if you feel you have recieved this message
in error, you should contact:
diff --git a/config/environment.rb b/config/environment.rb
index 69addb1..6edda72 100644
--- a/config/environment.rb
+++ b/config/environment.rb
@@ -78,8 +78,11 @@ end
module LoginEngine
config :salt, "voothingboat"
config :email_from, MAIL_CONFIG[:from]
-end
-
+ config :admin_email, MAIL_CONFIG[:from]
+ config :app_name, 'HyperChad'
+ config :changeable_fields, []
+ config :use_email_notification, true
+ config :confirm_account, false
Engines.start :login
# action mailer configuration
diff --git a/public/stylesheets/hc.css b/public/stylesheets/hc.css
index 0a9f362..62c3a36 100644
--- a/public/stylesheets/hc.css
+++ b/public/stylesheets/hc.css
@@ -89,7 +89,17 @@ a:active { color: #FFFFFF; text-decoration: none; background: #0259C4; }
margin-top: 10px;
margin-left: 50px;
padding: 5px 5px 5px 15px;
- width: 85%; }
+ width: 400px; }
+
+#status {
+ width: 400px;
+ border: 1px solid #0000FF;
+ border-width: 1px;
+ padding: 7px;
+ padding-bottom: 12px;
+ margin-bottom: 20px;
+ background-color: #f0f0f0;
+}
#footer { text-align: center;
font-size: 12px;
--
2.39.5