forked from refinery/refinerycms-inquiries
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
33 changed files
with
448 additions
and
418 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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
53
app/controllers/refinery/admin/inquiry_settings_controller.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.