Skip to content

Commit

Permalink
Added option to enter in to rafflr on checkin as well as after checki…
Browse files Browse the repository at this point in the history
…n if not already entered.
  • Loading branch information
Dishwasha committed May 20, 2012
1 parent 55f14b5 commit 9aeeed0
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 7 deletions.
6 changes: 5 additions & 1 deletion app/controllers/checkins_controller.rb
Expand Up @@ -11,6 +11,10 @@ def index
@checkins = Checkin.unhidden @checkins = Checkin.unhidden
end end


if params[:rafflr] == "true"
@checkins = @checkins.rafflr
end

respond_with(@event, @checkins) do |format| respond_with(@event, @checkins) do |format|
format.html format.html


Expand Down Expand Up @@ -61,7 +65,7 @@ def update
if params[:checkin] if params[:checkin]
if @checkin.update_attributes(params[:checkin]) if @checkin.update_attributes(params[:checkin])
flash[:notice] = "Successfully updated checkin status for #{@checkin.event.name}" flash[:notice] = "Successfully updated checkin status for #{@checkin.event.name}"
redirect_to event_path(@checkin.event) redirect_to event_path(@event)
else else
flash[:alert] = "Failed to update checkin status" flash[:alert] = "Failed to update checkin status"
redirect_to new_event_path redirect_to new_event_path
Expand Down
6 changes: 4 additions & 2 deletions app/models/checkin.rb
Expand Up @@ -5,16 +5,18 @@ class Checkin < ActiveRecord::Base
before_save :set_employer before_save :set_employer


attr_accessor :current_user, :remember_employer attr_accessor :current_user, :remember_employer
attr_accessible :employ, :employer, :employment, :event_id, :remember_employer, :shoutout, :user_id, :as => :default attr_accessible :employ, :employer, :employment, :event_id, :rafflr, :remember_employer, :shoutout, :user_id, :as => :default
attr_accessible :created_at, :employ, :employer, :employment, :event_id, :hidden, :remember_employer, :shoutout, :updated_at, :user_id, :as => :admin attr_accessible :created_at, :employ, :employer, :employment, :event_id, :hidden, :rafflr, :remember_employer, :shoutout, :updated_at, :user_id, :as => :admin


scope :hidden, :conditions => ["checkins.hidden = ?", true] scope :hidden, :conditions => ["checkins.hidden = ?", true]
scope :unhidden, :conditions => ["checkins.hidden = ?", false] scope :unhidden, :conditions => ["checkins.hidden = ?", false]
scope :employ, :conditions => ["checkins.employ = ?", true] scope :employ, :conditions => ["checkins.employ = ?", true]
scope :employment, :conditions => ["checkins.employment = ?", true] scope :employment, :conditions => ["checkins.employment = ?", true]
scope :rafflr, :conditions => ["checkins.rafflr = ?", true]


validates :employ, :inclusion => {:in => [true, false]} validates :employ, :inclusion => {:in => [true, false]}
validates :employment, :inclusion => {:in => [true, false]} validates :employment, :inclusion => {:in => [true, false]}
validates :rafflr, :inclusion => {:in => [true, false]}
validates :remember_employer, :inclusion => {:in => [true, false, "1", "0", 1, 0]} validates :remember_employer, :inclusion => {:in => [true, false, "1", "0", 1, 0]}
validates :employer, :format => {:with => /^[\x20-\x7E]*$/}, :length => {:within => 0..254} validates :employer, :format => {:with => /^[\x20-\x7E]*$/}, :length => {:within => 0..254}
validate :is_user validate :is_user
Expand Down
5 changes: 5 additions & 0 deletions app/models/event.rb
Expand Up @@ -41,6 +41,11 @@ def is_checked_in user=nil
!users.find_by_id(user).nil? !users.find_by_id(user).nil?
end end


def is_in_rafflr user=nil
user ||= current_user
Checkin.find_by_user_id(user).try{|user| user.rafflr if user}
end

def start_date def start_date
self.start_datetime.to_date.to_s if self.start_datetime self.start_datetime.to_date.to_s if self.start_datetime
end end
Expand Down
5 changes: 4 additions & 1 deletion app/views/checkins/_form.html.slim
Expand Up @@ -12,4 +12,7 @@ div data-role="fieldcontain"
= f.label :remember_employer, :"data-inline" => true = f.label :remember_employer, :"data-inline" => true
div data-role="fieldcontain" div data-role="fieldcontain"
= f.label :shoutout, "Shout-out!" = f.label :shoutout, "Shout-out!"
= f.text_field :shoutout = f.text_field :shoutout
div data-role="fieldcontain"
= f.check_box :rafflr
= f.label :rafflr, "Enter in to Rafflr", :"data-inline" => true
2 changes: 1 addition & 1 deletion app/views/events/_rafflr.js.erb
Expand Up @@ -10,7 +10,7 @@ $(document).ready(function() {
if(winners && winners > 0) { if(winners && winners > 0) {
started = true; started = true;
var rafflr = $("body").rafflr({ var rafflr = $("body").rafflr({
url: "<%= event_checkins_path(@event, :format => :json) %>", url: "<%= event_checkins_path(@event, :format => :json, :rafflr => true) %>",
winners: winners winners: winners
}); });


Expand Down
6 changes: 5 additions & 1 deletion app/views/events/show.html.slim
Expand Up @@ -7,9 +7,13 @@ p
p p
| Ends at: #{@event.end_datetime.strftime("%A %B %e, %Y %l:%M %p").squeeze(" ")} | Ends at: #{@event.end_datetime.strftime("%A %B %e, %Y %l:%M %p").squeeze(" ")}
- if @event.is_checked_in(current_user) - if @event.is_checked_in(current_user)
| Checked In | Checked In<br/>
- elsif @event.active? - elsif @event.active?
= link_to "Check In", new_event_checkin_path(@event), :"data-role" => "button", :"data-inline" => "true" = link_to "Check In", new_event_checkin_path(@event), :"data-role" => "button", :"data-inline" => "true"
- if @event.is_in_rafflr(current_user)
| Entered in to Rafflr
- elsif @event.active? && @event.is_checked_in(current_user)
= link_to "Enter in to Rafflr", event_checkin_path(@event, @event.checkins.find_by_user_id(current_user.id), :checkin => {:rafflr => true}), :method => :put, :target => "_self", :"data-role" => "button", :"data-inline" => "true"


p p
= link_to "Checkin Carousel", event_carousel_path(@event), :method => :get, :"data-role" => "button", :"data-inline" => "true", :target => "_self" = link_to "Checkin Carousel", event_carousel_path(@event), :method => :get, :"data-role" => "button", :"data-inline" => "true", :target => "_self"
Expand Down
5 changes: 5 additions & 0 deletions db/migrate/20120520052247_add_rafflr_to_checkin.rb
@@ -0,0 +1,5 @@
class AddRafflrToCheckin < ActiveRecord::Migration
def change
add_column :checkins, :rafflr, :boolean
end
end
3 changes: 2 additions & 1 deletion db/schema.rb
Expand Up @@ -11,7 +11,7 @@
# #
# It's strongly recommended to check this file into your version control system. # It's strongly recommended to check this file into your version control system.


ActiveRecord::Schema.define(:version => 20120222053740) do ActiveRecord::Schema.define(:version => 20120520052247) do


create_table "checkins", :force => true do |t| create_table "checkins", :force => true do |t|
t.integer "event_id" t.integer "event_id"
Expand All @@ -23,6 +23,7 @@
t.string "shoutout" t.string "shoutout"
t.boolean "hidden", :default => false, :null => false t.boolean "hidden", :default => false, :null => false
t.string "employer" t.string "employer"
t.boolean "rafflr"
end end


create_table "events", :force => true do |t| create_table "events", :force => true do |t|
Expand Down

0 comments on commit 9aeeed0

Please sign in to comment.