From 9aeeed0ed87da90f563cfff94dd3954e9ef1f9e3 Mon Sep 17 00:00:00 2001 From: Ethan Waldo Date: Sun, 20 May 2012 01:04:25 -0500 Subject: [PATCH] Added option to enter in to rafflr on checkin as well as after checkin if not already entered. --- app/controllers/checkins_controller.rb | 6 +++++- app/models/checkin.rb | 6 ++++-- app/models/event.rb | 5 +++++ app/views/checkins/_form.html.slim | 5 ++++- app/views/events/_rafflr.js.erb | 2 +- app/views/events/show.html.slim | 6 +++++- db/migrate/20120520052247_add_rafflr_to_checkin.rb | 5 +++++ db/schema.rb | 3 ++- 8 files changed, 31 insertions(+), 7 deletions(-) create mode 100644 db/migrate/20120520052247_add_rafflr_to_checkin.rb diff --git a/app/controllers/checkins_controller.rb b/app/controllers/checkins_controller.rb index 076e848..dde4449 100644 --- a/app/controllers/checkins_controller.rb +++ b/app/controllers/checkins_controller.rb @@ -11,6 +11,10 @@ def index @checkins = Checkin.unhidden end + if params[:rafflr] == "true" + @checkins = @checkins.rafflr + end + respond_with(@event, @checkins) do |format| format.html @@ -61,7 +65,7 @@ def update if params[:checkin] if @checkin.update_attributes(params[:checkin]) flash[:notice] = "Successfully updated checkin status for #{@checkin.event.name}" - redirect_to event_path(@checkin.event) + redirect_to event_path(@event) else flash[:alert] = "Failed to update checkin status" redirect_to new_event_path diff --git a/app/models/checkin.rb b/app/models/checkin.rb index aaed2bb..4e41248 100644 --- a/app/models/checkin.rb +++ b/app/models/checkin.rb @@ -5,16 +5,18 @@ class Checkin < ActiveRecord::Base before_save :set_employer attr_accessor :current_user, :remember_employer - attr_accessible :employ, :employer, :employment, :event_id, :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 :employ, :employer, :employment, :event_id, :rafflr, :remember_employer, :shoutout, :user_id, :as => :default + 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 :unhidden, :conditions => ["checkins.hidden = ?", false] scope :employ, :conditions => ["checkins.employ = ?", true] scope :employment, :conditions => ["checkins.employment = ?", true] + scope :rafflr, :conditions => ["checkins.rafflr = ?", true] validates :employ, :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 :employer, :format => {:with => /^[\x20-\x7E]*$/}, :length => {:within => 0..254} validate :is_user diff --git a/app/models/event.rb b/app/models/event.rb index f76680f..b04c71c 100644 --- a/app/models/event.rb +++ b/app/models/event.rb @@ -41,6 +41,11 @@ def is_checked_in user=nil !users.find_by_id(user).nil? 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 self.start_datetime.to_date.to_s if self.start_datetime end diff --git a/app/views/checkins/_form.html.slim b/app/views/checkins/_form.html.slim index c7f3dcb..d389abb 100644 --- a/app/views/checkins/_form.html.slim +++ b/app/views/checkins/_form.html.slim @@ -12,4 +12,7 @@ div data-role="fieldcontain" = f.label :remember_employer, :"data-inline" => true div data-role="fieldcontain" = f.label :shoutout, "Shout-out!" - = f.text_field :shoutout \ No newline at end of file + = f.text_field :shoutout +div data-role="fieldcontain" + = f.check_box :rafflr + = f.label :rafflr, "Enter in to Rafflr", :"data-inline" => true diff --git a/app/views/events/_rafflr.js.erb b/app/views/events/_rafflr.js.erb index 139b182..f79593c 100644 --- a/app/views/events/_rafflr.js.erb +++ b/app/views/events/_rafflr.js.erb @@ -10,7 +10,7 @@ $(document).ready(function() { if(winners && winners > 0) { started = true; var rafflr = $("body").rafflr({ - url: "<%= event_checkins_path(@event, :format => :json) %>", + url: "<%= event_checkins_path(@event, :format => :json, :rafflr => true) %>", winners: winners }); diff --git a/app/views/events/show.html.slim b/app/views/events/show.html.slim index 3a8a8a4..9546c0d 100644 --- a/app/views/events/show.html.slim +++ b/app/views/events/show.html.slim @@ -7,9 +7,13 @@ p p | Ends at: #{@event.end_datetime.strftime("%A %B %e, %Y %l:%M %p").squeeze(" ")} - if @event.is_checked_in(current_user) - | Checked In + | Checked In
- elsif @event.active? = 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 = link_to "Checkin Carousel", event_carousel_path(@event), :method => :get, :"data-role" => "button", :"data-inline" => "true", :target => "_self" diff --git a/db/migrate/20120520052247_add_rafflr_to_checkin.rb b/db/migrate/20120520052247_add_rafflr_to_checkin.rb new file mode 100644 index 0000000..da6cc12 --- /dev/null +++ b/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 diff --git a/db/schema.rb b/db/schema.rb index 52cc03b..7d68a56 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # 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| t.integer "event_id" @@ -23,6 +23,7 @@ t.string "shoutout" t.boolean "hidden", :default => false, :null => false t.string "employer" + t.boolean "rafflr" end create_table "events", :force => true do |t|