Skip to content

Commit

Permalink
Rails 3.1 support. Wip.
Browse files Browse the repository at this point in the history
  • Loading branch information
ugisozols committed Jul 5, 2011
1 parent d9b499b commit ef55f81
Show file tree
Hide file tree
Showing 33 changed files with 448 additions and 418 deletions.
41 changes: 0 additions & 41 deletions app/controllers/admin/inquiries_controller.rb

This file was deleted.

48 changes: 0 additions & 48 deletions app/controllers/admin/inquiry_settings_controller.rb

This file was deleted.

43 changes: 0 additions & 43 deletions app/controllers/inquiries_controller.rb

This file was deleted.

48 changes: 48 additions & 0 deletions app/controllers/refinery/admin/inquiries_controller.rb
@@ -0,0 +1,48 @@
module Refinery
module Admin
class InquiriesController < ::Admin::BaseController

crudify :'refinery/inquiry',
:title_attribute => "name",
:order => "created_at DESC"

helper_method :group_by_date

before_filter :find_all_ham, :only => [:index]
before_filter :find_all_spam, :only => [:spam]
before_filter :get_spam_count, :only => [:index, :spam]

def index
@inquiries = @inquiries.with_query(params[:search]) if searching?
@inquiries = @inquiries.page(params[:page])
end

def spam
self.index
render :action => 'index'
end

def toggle_spam
find_inquiry
@inquiry.toggle!(:spam)

redirect_to :back
end

protected

def find_all_ham
@inquiries = Refinery::Inquiry.ham
end

def find_all_spam
@inquiries = Refinery::Inquiry.spam
end

def get_spam_count
@spam_count = Refinery::Inquiry.count(:conditions => {:spam => true})
end

end
end
end
53 changes: 53 additions & 0 deletions app/controllers/refinery/admin/inquiry_settings_controller.rb
@@ -0,0 +1,53 @@
module Refinery
module Admin
class InquirySettingsController < ::Admin::BaseController

crudify :'refinery/setting',
:title_attribute => "name",
:order => 'name ASC',
:redirect_to_url => main_app.refinery_admin_inquiries_path

before_filter :set_url_override?, :only => [:edit, :update]
after_filter :save_subject_for_confirmation?, :only => :update
after_filter :save_message_for_confirmation?, :only => :update
around_filter :rewrite_flash?, :only => :update

protected

def rewrite_flash?
yield

flash[:notice] = flash[:notice].to_s.gsub(/(\'.*\')/) {|m| m.titleize}.gsub('Inquiry ', '')
end

def save_subject_for_confirmation?
Refinery::InquirySetting.confirmation_subject = params[:subject] if params.keys.include?('subject')
end

def save_message_for_confirmation?
Refinery::InquirySetting.confirmation_message = params[:message] if params.keys.include?('message')
end

def set_url_override?
@url_override = admin_inquiry_setting_url(@refinery_setting, :dialog => from_dialog?)
end

def find_refinery_setting
# ensure that we're dealing with the name of the setting, not the id.
begin
if params[:id].to_i.to_s == params[:id]
params[:id] = Refinery::RefinerySetting.find(params[:id]).name.to_s
end
rescue
end

# prime the setting first, if it's valid.
if Refinery::InquirySetting.methods.map(&:to_sym).include?(params[:id].to_s.gsub('inquiry_', '').to_sym)
Refinery::InquirySetting.send(params[:id].to_s.gsub('inquiry_', '').to_sym)
end
@refinery_setting = Refinery::RefinerySetting.find_by_name(params[:id])
end

end
end
end
45 changes: 45 additions & 0 deletions app/controllers/refinery/inquiries_controller.rb
@@ -0,0 +1,45 @@
module Refinery
class InquiriesController < ::ApplicationController

before_filter :find_page, :only => [:create, :new]

def thank_you
@page = Refinery::Page.find_by_link_url("/contact/thank_you", :include => [:parts, :slugs])
end

def new
@inquiry = Refinery::Inquiry.new
end

def create
@inquiry = Refinery::Inquiry.new(params[:inquiry])

if @inquiry.save
if @inquiry.ham?
begin
Refinery::InquiryMailer.notification(@inquiry, request).deliver
rescue
logger.warn "There was an error delivering an inquiry notification.\n#{$!}\n"
end

begin
Refinery::InquiryMailer.confirmation(@inquiry, request).deliver
rescue
logger.warn "There was an error delivering an inquiry confirmation:\n#{$!}\n"
end
end

redirect_to thank_you_inquiries_url
else
render :action => 'new'
end
end

protected

def find_page
@page = Refinery::Page.find_by_link_url('/contact', :include => [:parts, :slugs])
end

end
end
20 changes: 0 additions & 20 deletions app/mailers/inquiry_mailer.rb

This file was deleted.

22 changes: 22 additions & 0 deletions app/mailers/refinery/inquiry_mailer.rb
@@ -0,0 +1,22 @@
module Refinery
class InquiryMailer < ActionMailer::Base

def confirmation(inquiry, request)
subject Refinery::InquirySetting.confirmation_subject(Globalize.locale)
recipients inquiry.email
from "\"#{Refinery::RefinerySetting[:site_name]}\" <no-reply@#{request.domain(Refinery::RefinerySetting.find_or_set(:tld_length, 1))}>"
reply_to Refinery::InquirySetting.notification_recipients.split(',').first
sent_on Time.now
@inquiry = inquiry
end

def notification(inquiry, request)
subject Refinery::InquirySetting.notification_subject
recipients Refinery::InquirySetting.notification_recipients
from "\"#{Refinery::RefinerySetting[:site_name]}\" <no-reply@#{request.domain(Refinery::RefinerySetting.find_or_set(:tld_length, 1))}>"
sent_on Time.now
@inquiry = inquiry
end

end
end
21 changes: 0 additions & 21 deletions app/models/inquiry.rb

This file was deleted.

41 changes: 0 additions & 41 deletions app/models/inquiry_setting.rb

This file was deleted.

0 comments on commit ef55f81

Please sign in to comment.