<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array">
    <added>
      <filename>app/views/votes/_voting_box.html.erb</filename>
    </added>
    <added>
      <filename>db/migrate/20080701085004_add_hiring_stage_to_votes.rb</filename>
    </added>
  </added>
  <modified type="array">
    <modified>
      <diff>@@ -1,6 +1,34 @@
 class VotesController &lt; ApplicationController
-  # GET /votes
-  # GET /votes.xml
+
+  
+  def vote
+    hiring_stage = HiringStage.find_by_hiring_stage_id( params[:hiring_stage_id] )
+    vote_value = params[:vote]
+    
+    # Is the current_user allowed to vote on this hiring_stage?
+    if current_user.positions.include?( hiring_stage.position )
+      logger.debug &quot;&gt;&gt; #{vote_value}&quot;
+      
+      # Does this user already have a vote for this hiring stage for this position?
+      vote = Vote.find_vote_by_hiring_stage( hiring_stage )
+      if vote.nil?
+        vote = Vote.new.construct_from_basic_elements( current_user, hiring_stage, vote_value )
+      else
+        vote.update_attribute( :vote_value, vote_value )
+      end
+    end
+    
+    respond_to do |wants|
+      wants.js do
+        render :update do |page|
+          logger.debug &quot;&gt;&gt; Boo&quot;
+          #page.visual_effect :puff, &quot;comment_#{params[:id]}&quot;.to_sym
+        end
+      end
+    end
+  end
+
+=begin
   def index
     @votes = Vote.find(:all)
 
@@ -82,4 +110,5 @@ class VotesController &lt; ApplicationController
       format.xml  { head :ok }
     end
   end
+=end
 end</diff>
      <filename>app/controllers/votes_controller.rb</filename>
    </modified>
    <modified>
      <diff>@@ -31,9 +31,7 @@ module PositionsHelper
   def render_vetting_stage_cell( hiring_stage, v_stage )
     hiring_stage.vetting_stage.is_me_or_is_my_parent?( v_stage ) ? hilite_class = 'hilited' : hilite_class = ''
     
-    cell = &quot;&lt;td class='t c &quot; + hilite_class + &quot;'&gt;&quot;
-    cell += render_voting_box_cell( hiring_stage, v_stage )
-    cell += &quot;&lt;/td&gt;&quot;
+    cell = &quot;&lt;td class='t c &quot; + hilite_class + &quot;'&gt;&quot; + render_voting_box_cell( hiring_stage, v_stage ) + &quot;&lt;/td&gt;&quot;
     
     v_stage.children.each do |child|
       cell += render_vetting_stage_cell( hiring_stage, child )
@@ -44,22 +42,39 @@ module PositionsHelper
   
   
   # TODO: Finish this function
+  # If a user needs to vote on this applicant, display the two voting options.
+  # If a user has voted on this applicant, display the box in the colour of their vote with a delete circle in the top-left
+  # If a user is not allowed to vote on this position, show the user icon
   def render_voting_box_cell( hiring_stage, v_stage )
-    return hiring_stage.vetting_stage == v_stage ? image_tag( 'applicant.png' ) : &quot;&quot;
+    cell = &quot;&quot;
+
+    if hiring_stage.vetting_stage == v_stage
+      if current_user.can_vote_on_position?( hiring_stage.position )
+        vote = Vote.find_vote_by_hiring_stage( hiring_stage )
+        
+        cell += &quot;&lt;div class='vote_value_#{vote.vote_value.to_s}'&gt;&quot; if vote
+        cell += render( :partial =&gt; 'votes/voting_box', :locals =&gt; { :hiring_stage =&gt; hiring_stage } )
+        cell += &quot;&lt;/div&gt;&quot; if vote
+      else
+        cell = image_tag( 'applicant.png' )
+      end
+    end
+  
+    return cell
   end
   
   
   def render_vetting_stage_controls( hiring_stage, applicant )
-    cell = '&lt;td&gt;'
+    cell = '&lt;td class=&quot;t c&quot;&gt;'
     
     if hiring_stage.vetting_stage.parent
-      cell += link_to( ( image_tag( 'applicant_og.png', :alt =&gt; 'retreat', :title =&gt; 'Retreat this applicant to the prev stage' ) ), :controller =&gt; 'positions', :action =&gt; 'retreat', :id =&gt; @position, :applicant_id =&gt; applicant.id )
+      cell += link_to( ( image_tag( 'applicant_og.png', :alt =&gt; 'retreat', :title =&gt; 'Retreat this applicant to the prev stage', :class =&gt; 'controls_button' ) ), :controller =&gt; 'positions', :action =&gt; 'retreat', :id =&gt; @position, :applicant_id =&gt; applicant.id )
     else
-      cell += image_tag( 'applicant_blank.png' )
+      cell += image_tag( 'applicant_blank.png', :class =&gt; 'controls_button' )
     end
     
     cell += &quot;&amp;nbsp;&quot;
-    cell += link_to( image_tag( 'applicant_go.png', :alt =&gt; 'advance', :title =&gt; 'Advance this applicant to the next stage' ), :controller =&gt; 'positions', :action =&gt; 'advance', :id =&gt; @position, :applicant_id =&gt; applicant.id ) 
+    cell += link_to( image_tag( 'applicant_go.png', :alt =&gt; 'advance', :title =&gt; 'Advance this applicant to the next stage', :class =&gt; 'controls_button' ), :controller =&gt; 'positions', :action =&gt; 'advance', :id =&gt; @position, :applicant_id =&gt; applicant.id ) 
     cell += '&lt;/td&gt;'
     
     return cell</diff>
      <filename>app/helpers/positions_helper.rb</filename>
    </modified>
    <modified>
      <diff>@@ -5,6 +5,7 @@ class HiringStage &lt; ActiveRecord::Base
 	belongs_to :position
 	belongs_to :vetting_stage
 	
+	has_many :votes
 	
 	def construct_from_basic_elements( applicant, position, vetting_stage )
 	  self.applicant = applicant</diff>
      <filename>app/models/hiring_stage.rb</filename>
    </modified>
    <modified>
      <diff>@@ -21,10 +21,10 @@ class User &lt; ActiveRecord::Base
   validates_inclusion_of    :is_admin, :in =&gt; [false, true]
 
   has_many :comments, :as =&gt; :commentable, :order =&gt; 'comments.created_at DESC', :dependent =&gt; :destroy
-  has_many :votes, :dependent =&gt; :nullify
   has_many :open_positions, :class_name =&gt; 'Position', :conditions =&gt; 'is_closed = 0'
   has_many :closed_positions, :class_name =&gt; 'Position', :conditions =&gt; 'is_closed = 1'
-  
+  has_many :votes, :dependent =&gt; :nullify
+    
   has_and_belongs_to_many :positions, :order =&gt; 'title ASC'
   
 
@@ -61,6 +61,11 @@ class User &lt; ActiveRecord::Base
     return false
   end
   
+  
+  def can_vote_on_position?( position )
+    return positions.include?( position )
+  end
+  
 
 protected
     </diff>
      <filename>app/models/user.rb</filename>
    </modified>
    <modified>
      <diff>@@ -5,6 +5,28 @@ class Vote &lt; ActiveRecord::Base
   belongs_to :applicant
   belongs_to :vetting_stage
   belongs_to :position
+  belongs_to :hiring_stage
   
-  validates_presence_of :vote
+  
+  # ------------------------------------------------------------ Class Methods ------------------------------------------------------------ #
+  
+  
+  def self.find_vote_by_hiring_stage( hiring_stage )
+    return self.find( :first, :conditions =&gt; &quot;hiring_stage_id = #{hiring_stage.id}&quot; )
+  end
+  
+  
+  # ------------------------------------------------------------ Instance Methods ------------------------------------------------------------ #
+  
+  
+  def construct_from_basic_elements( current_user, hiring_stage, vote_value )
+    self.user = current_user
+    self.applicant = hiring_stage.applicant
+    self.vetting_stage = hiring_stage.vetting_stage
+    self.position = hiring_stage.position
+    self.hiring_stage = hiring_stage
+    self.vote_value = vote_value
+    
+    self.save!
+  end
 end</diff>
      <filename>app/models/vote.rb</filename>
    </modified>
    <modified>
      <diff>@@ -8,10 +8,12 @@
 
 		&lt;% for applicant in @applicants %&gt;
 			&lt;tr class=&quot;separated selectable&quot;&gt;
-				&lt;td class=&quot;t l&quot;&gt;&lt;%= link_to( sanitize( applicant.name ), applicant_path( applicant ), :class =&gt; 'new_link' ) %&gt;&lt;/td&gt;
+				&lt;td class=&quot;t l&quot;&gt;
+					&lt;%= link_to( sanitize( applicant.name ), applicant_path( applicant ), :class =&gt; 'new_link' ) %&gt;
+					
+				&lt;/td&gt;
 				&lt;td class=&quot;t l&quot; width=&quot;50%&quot;&gt;
 					&lt;%= truncate( sanitize( applicant.contact_info ), 128 ) %&gt; &lt;br /&gt;
-					&lt;span class=&quot;display_date&quot;&gt;&lt;%= applicant.updated_at.friendly_date %&gt;&lt;/span&gt; &lt;br /&gt;
 					&lt;span class=&quot;small&quot;&gt;&lt;%= &quot;Positions: &quot; + applicant.positions.map { |pos| link_to( pos.title, position_path( pos ) ) }.to_sentence if ( applicant.positions.count &gt; 0 ) %&gt;&lt;/span&gt;
 				&lt;/td&gt;
 				&lt;td class=&quot;t c&quot;&gt;</diff>
      <filename>app/views/applicants/index.html.erb</filename>
    </modified>
    <modified>
      <diff>@@ -31,6 +31,8 @@ ActionController::Routing::Routes.draw do |map|
   
   map.connect 'positions/skip/:id', :controller =&gt; 'positions', :action =&gt; 'skip'
   
+  map.connect 'votes/vote', :controller =&gt; 'votes', :action =&gt; 'vote'
+  
   # The priority is based upon order of creation: first created -&gt; highest priority.
 
   # Sample of regular route:</diff>
      <filename>config/routes.rb</filename>
    </modified>
    <modified>
      <diff>@@ -5,7 +5,7 @@ class CreateVotes &lt; ActiveRecord::Migration
       t.column :applicant_id,     :integer,         :null =&gt; false
       t.column :position_id,      :integer,         :null =&gt; false
       t.column :vetting_stage_id, :integer,         :null =&gt; false
-      t.column :vote,             :boolean,         :null =&gt; false,         :default =&gt; 0
+      t.column :vote_value,       :boolean,         :null =&gt; false,         :default =&gt; 0
       
       t.timestamps
     end</diff>
      <filename>db/migrate/20080623221948_create_votes.rb</filename>
    </modified>
    <modified>
      <diff>@@ -492,6 +492,28 @@ a.new_link img {
 }
 
 
+.controls_button {
+	margin:													0px 4px 0px 4px;
+}
+
+.voting_button {
+	cursor:													pointer;
+	margin-right:											8px;
+}
+
+
+.vote_value_true {
+	border: 1px solid green;
+	padding: 2px;
+}
+
+
+.vote_value_false {
+	border:										1px solid red;
+	padding: 2px;
+}
+
+
 /* ------------------------------------------------------------ Rounded Rect ------------------------------------------------------------ */
 
 .rounded_rect_btn_light, rounded_rect_btn_dark {</diff>
      <filename>public/stylesheets/application.css</filename>
    </modified>
  </modified>
  <removed type="array">
    <removed>
      <filename>app/views/positions/_voting_box.html.erb</filename>
    </removed>
  </removed>
  <parents type="array">
    <parent>
      <id>8ea73d463c5072aa00d88d277bf18a0b89fd1682</id>
    </parent>
  </parents>
  <author>
    <name>Chris</name>
    <email>chris@ChoOyu.local</email>
  </author>
  <url>http://github.com/senorprogrammer/applican/commit/56d286bd036bf2f85fc5901995ad40be51b19113</url>
  <id>56d286bd036bf2f85fc5901995ad40be51b19113</id>
  <committed-date>2008-07-01T02:53:35-07:00</committed-date>
  <authored-date>2008-07-01T02:53:35-07:00</authored-date>
  <message>Voting is now in place (though it is aesthetically ugly a wee bit)</message>
  <tree>4b4745db2c9956777d7b716dc81d3487198f9c93</tree>
  <committer>
    <name>Chris</name>
    <email>chris@ChoOyu.local</email>
  </committer>
</commit>
