####################################################################
def new
+ redirect_to :action => 'general_information'
+ end
+
+ def general_information
@election = Election.new
+ render :action => 'general_information'
end
def create_election
flash[:notice] = 'Election was successfully created.'
redirect_to :action => 'edit_candidates', :id => @election.id
else
- render :action => 'new'
+ render :action => 'general_information'
end
end
def add_candidate
@election = Election.find(params[:id])
@candidate = Candidate.new(params[:candidate])
-
+ @election.candidates << @candidate
+
if @candidate.save
- @election.candidates << @candidate
@candidate = Candidate.new
redirect_to :action => 'edit_candidates', :id => @election.id
else
def candidate_picture
candidate = Candidate.find( params[:id] )
- send_data( candidate.picture_data,
- :filename => candidate.picture_filename,
- :type => candidate.picture_type,
+ send_data( candidate.picture.data,
+ :filename => candidate.picture.filename,
+ :type => candidate.picture.filetype,
:disposition => 'inline' )
end
## for a particular election
####################################################################
def new_voters
- @election = Election.find( params[:id] )
- if params.has_key?[:raw_voter_list]
- process_incoming_voters( params[:raw_voter_list] )
- end
- @raw_voter_list = RawVoterList.new
-
+ edit_voters
end
def edit_voters
end
# the new voter should be in good shape. save add to the election
- new_voter.save
@election.voters << new_voter
+ new_voter.save
end
end
belongs_to :election
validates_presence_of :name
+ # i have to call this picture_assoc because picture= does not overload
+ # the normal association method made by has_one
+ has_one :picture_obj, :class_name => "Picture"
+
# validate uniqueness of a name *within a given election*
def <=>(other)
name
end
- def picture=(picture_field)
- if picture_field
- unless picture_field.content_type.match(/^image/)
- return false
- end
- self.picture_filename = base_part_of(picture_field.original_filename)
- self.picture_type = picture_field.content_type.chomp
- self.picture_data = picture_field.read
- end
+ def picture
+ picture_obj
end
- def base_part_of(filename)
- name = File.basename(filename)
- name.gsub(/[^\w._-]/, '')
+ def picture=(field)
+ if field and field.length > 0
+ self.picture_obj = Picture.new.set_from_field(field)
+ return picture_obj.save
+ else
+ return false
+ end
end
def picture?
- !self.picture_filename.nil?
+ !self.picture_obj.nil?
end
end
def start_blockers
reasons = []
- debugger
if self.candidates.length <= 1
reasons << "You must have at least two candidates."
end
--- /dev/null
+class Picture < ActiveRecord::Base
+ belongs_to :candidate
+
+ def set_from_field(field)
+ unless field.content_type.match(/^image/)
+ return false
+ end
+ self.filename = base_part_of(field.original_filename)
+ self.filetype = field.content_type.chomp
+ self.data = field.read
+ self
+ end
+
+ def base_part_of(filename)
+ name = File.basename(filename)
+ name.gsub(/[^\w._-]/, '')
+ end
+
+end
+
--- /dev/null
+<% progress_steps = [ ['overview', 'General Information'],
+ ['candidates', 'Candidates'],
+ ['voters', 'Voters'],
+ ['review', 'Review'] ] %>
+<div id="election_creation_progress_bar">
+
+<ul>
+<% progress_steps.each_with_index do |kv, i| -%>
+ <% step, description = kv -%>
+ <li class="<%= step == progress ? 'step_selected' : 'step_unselected' -%>
+ <%= " last" if i + 1 == progress_steps.length -%>
+ ">Step <%= i + 1 %>: <%= description %></li>
+<% end -%>
+</ul>
+
+</div>
+<%= render_partial 'progress', 'candidates' %>
<h1>Edit/Add Candidates</h1>
<%= error_messages_for :candidate %>
<% unless @election.candidates.empty? %>
<p>The following are valid options or candidates in this election:</p>
+1;3A
<% @election.candidates.each do |candidate| %>
<% @current_candidate = candidate %>
<%= submit_tag "Add Candidate" %>
<% end %>
-<%= button_to "Done!", :action => 'show', :id => @election %>
+<%= button_to "Done!", :action => 'new_voters', :id => @election %>
+<%= render_partial 'progress', 'overview' %>
+
<h1>Create A New Vote</h1>
<h2>Vote Overview</h2>
+<%= render_partial 'progress', 'voters' %>
<% @edit = true %>
<h1><strong><%= @election.name %>:</strong> Enter List of Voter Email Addresses</h1>
<% form_tag(:action => 'new_voters', :id => @election.id) do %>
<%= render :partial => 'voters_form' %>
<% end %>
+<%= button_to "Done", :action => 'show', :id => @election.id %>
-<% %>
+<%= render_partial 'progress', 'review' %>
<h1>Vote Information</h1>
<% if @election.active? %>
<p><em>There are currently no voters registered. <%= link_to "Add some!", :action => 'edit_voters', :id => @election.id unless @election.active %></em></p>
<% end %>
-<% unless @election.active %>
+<% unless @election.active? %>
<h2>Start Election</h2>
<% if @election.start_blockers.length > 0 %>
<p><%= link_to 'Lost or forgot your password?', :controller => 'account', :action => 'forgot_password' %></p>
- <p>Unfortunately, Selectricity is currently being tested and new
- accounts for full votes (i.e., non-<em>QuickVotes</em>) can not
- be automatically created. If you are interested in using
- Selectricity to
- run an organizational election, contact <a
- href="http://mako.cc/contact.html">Benjamin Mako Hill</a>.</p>
-
</div>
election_id int NOT NULL,
name varchar(100) NOT NULL,
description text NULL,
- picture_filename varchar(200),
- picture_data blob,
- picture_type varchar(100),
+ primary key (id)
+);
+
+# CREATE pictures TABLE
+#####################################
+
+drop table if exists pictures;
+create table pictures (
+ id int NOT NULL auto_increment,
+ filename varchar(200),
+ data blob,
+ filetype varchar(100),
+ candidate_id int NULL,
+ constraint fk_candidate_picture foreign key (candidate_id) references candidates(id),
primary key (id)
);
ActiveRecord::Schema.define() do
create_table "candidates", :force => true do |t|
- t.column "election_id", :integer, :null => false
- t.column "name", :string, :limit => 100, :default => "", :null => false
- t.column "description", :text
- t.column "picture_filename", :string, :limit => 200
- t.column "picture_data", :binary
- t.column "picture_type", :string, :limit => 100
+ t.column "election_id", :integer, :null => false
+ t.column "name", :string, :limit => 100, :default => "", :null => false
+ t.column "description", :text
end
create_table "elections", :force => true do |t|
add_index "elections", ["user_id"], :name => "fk_user_election"
+ create_table "pictures", :force => true do |t|
+ t.column "filename", :string, :limit => 200
+ t.column "data", :binary
+ t.column "filetype", :string, :limit => 100
+ t.column "candidate_id", :integer
+ end
+
+ add_index "pictures", ["candidate_id"], :name => "fk_candidate_picture"
+
create_table "rankings", :force => true do |t|
t.column "vote_id", :integer
t.column "candidate_id", :integer
padding: 5px;
}
+#election_creation_progress_bar ul li {
+ display: inline;
+ list-style: default;
+}
+
+#election_creation_progress_bar ul li:after {
+ font-weight: normal;
+ color: #000;
+ content: " || ";
+}
+
+#election_creation_progress_bar ul li.last:after {
+ content: "";
+}
+
+#election_creation_progress_bar li.step_selected {
+ font-weight: bold;
+}
+
+#election_creation_progress_bar li.step_unselected {
+ color: #CCCCCC;
+ font-weight: bold;
+}