cms-inquiries 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (58) hide show
  1. data/app/controllers/admin/inquiries_controller.rb +41 -0
  2. data/app/controllers/admin/inquiry_settings_controller.rb +48 -0
  3. data/app/controllers/inquiries_controller.rb +43 -0
  4. data/app/helpers/inquiries_helper.rb +2 -0
  5. data/app/mailers/inquiry_mailer.rb +21 -0
  6. data/app/models/inquiry.rb +23 -0
  7. data/app/models/inquiry_setting.rb +47 -0
  8. data/app/views/admin/inquiries/_inquiry.html.erb +24 -0
  9. data/app/views/admin/inquiries/_submenu.html.erb +27 -0
  10. data/app/views/admin/inquiries/index.html.erb +30 -0
  11. data/app/views/admin/inquiries/show.html.erb +72 -0
  12. data/app/views/admin/inquiry_settings/_confirmation_email_form.html.erb +59 -0
  13. data/app/views/admin/inquiry_settings/_notification_recipients_form.html.erb +25 -0
  14. data/app/views/admin/inquiry_settings/edit.html.erb +5 -0
  15. data/app/views/inquiries/new.html.erb +34 -0
  16. data/app/views/inquiries/thank_you.html.erb +1 -0
  17. data/app/views/inquiry_mailer/confirmation.html.erb +1 -0
  18. data/app/views/inquiry_mailer/notification.html.erb +18 -0
  19. data/cms-inquiries.gemspec +98 -0
  20. data/config/locales/bg.yml +75 -0
  21. data/config/locales/cs.yml +75 -0
  22. data/config/locales/da.yml +68 -0
  23. data/config/locales/de.yml +76 -0
  24. data/config/locales/en-GB.yml +75 -0
  25. data/config/locales/en.yml +75 -0
  26. data/config/locales/es.yml +79 -0
  27. data/config/locales/fr.yml +76 -0
  28. data/config/locales/it.yml +77 -0
  29. data/config/locales/lolcat.yml +76 -0
  30. data/config/locales/lt.yml +76 -0
  31. data/config/locales/lv.yml +76 -0
  32. data/config/locales/nb.yml +75 -0
  33. data/config/locales/nl.yml +75 -0
  34. data/config/locales/pl.yml +76 -0
  35. data/config/locales/pt-BR.yml +76 -0
  36. data/config/locales/ru.yml +75 -0
  37. data/config/locales/sk.yml +75 -0
  38. data/config/locales/sl.yml +75 -0
  39. data/config/locales/sv.yml +75 -0
  40. data/config/locales/zh-CN.yml +75 -0
  41. data/config/routes.rb +23 -0
  42. data/db/migrate/20101208082840_create_inquiries.rb +31 -0
  43. data/db/migrate/20101208082841_remove_position_and_open_from_inquiries.rb +11 -0
  44. data/db/migrate/20110719082646_drop_inquiry_settings_table.rb +11 -0
  45. data/db/seeds/pages_for_inquiries.rb +55 -0
  46. data/features/create_inquiries.feature +38 -0
  47. data/features/manage_inquiries.feature +57 -0
  48. data/features/step_definitions/inquiry_steps.rb +25 -0
  49. data/features/support/factories.rb +7 -0
  50. data/features/support/paths.rb +26 -0
  51. data/lib/gemspec.rb +29 -0
  52. data/lib/generators/refinerycms_inquiries_generator.rb +6 -0
  53. data/lib/inquiries.rb +2 -0
  54. data/lib/refinerycms-inquiries.rb +24 -0
  55. data/license.md +21 -0
  56. data/readme.md +49 -0
  57. data/spec/models/inquiry_spec.rb +59 -0
  58. metadata +135 -0
@@ -0,0 +1,41 @@
1
+ class Admin::InquiriesController < Admin::BaseController
2
+
3
+ crudify :inquiry, :title_attribute => "name", :order => "created_at DESC"
4
+ helper_method :group_by_date
5
+
6
+ before_filter :find_all_ham, :only => [:index]
7
+ before_filter :find_all_spam, :only => [:spam]
8
+ before_filter :get_spam_count, :only => [:index, :spam]
9
+
10
+ def index
11
+ @inquiries = @inquiries.with_query(params[:search]) if searching?
12
+ @inquiries = @inquiries.paginate({:page => params[:page]})
13
+ end
14
+
15
+ def spam
16
+ self.index
17
+ render :action => 'index'
18
+ end
19
+
20
+ def toggle_spam
21
+ find_inquiry
22
+ @inquiry.toggle!(:spam)
23
+
24
+ redirect_to :back
25
+ end
26
+
27
+ protected
28
+
29
+ def find_all_ham
30
+ @inquiries = Inquiry.ham
31
+ end
32
+
33
+ def find_all_spam
34
+ @inquiries = Inquiry.spam
35
+ end
36
+
37
+ def get_spam_count
38
+ @spam_count = Inquiry.count(:conditions => {:spam => true})
39
+ end
40
+
41
+ end
@@ -0,0 +1,48 @@
1
+ class Admin::InquirySettingsController < Admin::BaseController
2
+
3
+ crudify :refinery_setting,
4
+ :title_attribute => "name",
5
+ :order => 'name ASC',
6
+ :redirect_to_url => "admin_inquiries_url"
7
+
8
+ before_filter :set_url_override?, :only => [:edit, :update]
9
+ after_filter :save_subject_for_confirmation?, :only => :update
10
+ after_filter :save_message_for_confirmation?, :only => :update
11
+ around_filter :rewrite_flash?, :only => :update
12
+
13
+ protected
14
+ def rewrite_flash?
15
+ yield
16
+
17
+ flash[:notice] = flash[:notice].to_s.gsub(/(\'.*\')/) {|m| m.titleize}.gsub('Inquiry ', '')
18
+ end
19
+
20
+ def save_subject_for_confirmation?
21
+ InquirySetting.confirmation_subject = params[:subject] if params.keys.include?('subject')
22
+ end
23
+
24
+ def save_message_for_confirmation?
25
+ InquirySetting.confirmation_message = params[:message] if params.keys.include?('message')
26
+ end
27
+
28
+ def set_url_override?
29
+ @url_override = admin_inquiry_setting_url(@refinery_setting, :dialog => from_dialog?)
30
+ end
31
+
32
+ def find_refinery_setting
33
+ # ensure that we're dealing with the name of the setting, not the id.
34
+ begin
35
+ if params[:id].to_i.to_s == params[:id]
36
+ params[:id] = RefinerySetting.find(params[:id]).name.to_s
37
+ end
38
+ rescue
39
+ end
40
+
41
+ # prime the setting first, if it's valid.
42
+ if InquirySetting.methods.map(&:to_sym).include?(params[:id].to_s.gsub('inquiry_', '').to_sym)
43
+ InquirySetting.send(params[:id].to_s.gsub('inquiry_', '').to_sym)
44
+ end
45
+ @refinery_setting = RefinerySetting.find_by_name(params[:id])
46
+ end
47
+
48
+ end
@@ -0,0 +1,43 @@
1
+ class InquiriesController < ApplicationController
2
+
3
+ before_filter :find_page, :only => [:create, :new]
4
+
5
+ def thank_you
6
+ @page = Page.find_by_link_url("/contact/thank_you", :include => [:parts, :slugs])
7
+ end
8
+
9
+ def new
10
+ @inquiry = Inquiry.new
11
+ end
12
+
13
+ def create
14
+ @inquiry = Inquiry.new(params[:inquiry])
15
+
16
+ if @inquiry.save
17
+ if @inquiry.ham?
18
+ begin
19
+ InquiryMailer.notification(@inquiry, request).deliver
20
+ rescue
21
+ logger.warn "There was an error delivering an inquiry notification.\n#{$!}\n"
22
+ end
23
+
24
+ begin
25
+ InquiryMailer.confirmation(@inquiry, request).deliver
26
+ rescue
27
+ logger.warn "There was an error delivering an inquiry confirmation:\n#{$!}\n"
28
+ end if InquirySetting.send_confirmation?
29
+ end
30
+
31
+ redirect_to thank_you_inquiries_url
32
+ else
33
+ render :action => 'new'
34
+ end
35
+ end
36
+
37
+ protected
38
+
39
+ def find_page
40
+ @page = Page.find_by_link_url('/contact', :include => [:parts, :slugs])
41
+ end
42
+
43
+ end
@@ -0,0 +1,2 @@
1
+ module InquiriesHelper
2
+ end
@@ -0,0 +1,21 @@
1
+ class InquiryMailer < ActionMailer::Base
2
+
3
+ def confirmation(inquiry, request)
4
+ subject InquirySetting.confirmation_subject(Globalize.locale)
5
+ recipients inquiry.email
6
+ from "\"#{RefinerySetting[:site_name]}\" <no-reply@#{request.domain(RefinerySetting.find_or_set(:tld_length, 1))}>"
7
+ reply_to InquirySetting.notification_recipients.split(',').first
8
+ sent_on Time.now
9
+ @inquiry = inquiry
10
+ end
11
+
12
+ def notification(inquiry, request)
13
+ subject InquirySetting.notification_subject
14
+ recipients InquirySetting.notification_recipients
15
+ from "\"#{RefinerySetting[:site_name]}\" <no-reply@#{request.domain(RefinerySetting.find_or_set(:tld_length, 1))}>"
16
+ reply_to inquiry.email
17
+ sent_on Time.now
18
+ @inquiry = inquiry
19
+ end
20
+
21
+ end
@@ -0,0 +1,23 @@
1
+ class Inquiry < ActiveRecord::Base
2
+
3
+ filters_spam :message_field => :message,
4
+ :email_field => :email,
5
+ :author_field => :name,
6
+ :other_fields => [:phone],
7
+ :extra_spam_words => %w()
8
+
9
+ validates :name, :presence => true
10
+ validates :message, :presence => true
11
+ validates :email, :format=> { :with => /^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/i }
12
+
13
+ acts_as_indexed :fields => [:name, :email, :message, :phone]
14
+
15
+ default_scope :order => 'created_at DESC' # previously scope :newest
16
+
17
+ attr_accessible :name, :phone, :message, :email
18
+
19
+ def self.latest(number = 7, include_spam = false)
20
+ include_spam ? limit(number) : ham.limit(number)
21
+ end
22
+
23
+ end
@@ -0,0 +1,47 @@
1
+ class InquirySetting < ActiveRecord::Base
2
+
3
+ class << self
4
+ def confirmation_body
5
+ RefinerySetting.find_or_set(:inquiry_confirmation_body,
6
+ "Thank you for your inquiry %name%,\n\nThis email is a receipt to confirm we have received your inquiry and we'll be in touch shortly.\n\nThanks."
7
+ )
8
+ end
9
+
10
+ def confirmation_subject(locale='en')
11
+ RefinerySetting.find_or_set("inquiry_confirmation_subject_#{locale}".to_sym,
12
+ "Thank you for your inquiry")
13
+ end
14
+
15
+ def confirmation_subject=(value)
16
+ value.first.keys.each do |locale|
17
+ RefinerySetting.set("inquiry_confirmation_subject_#{locale}".to_sym, value.first[locale.to_sym])
18
+ end
19
+ end
20
+
21
+ def confirmation_message(locale='en')
22
+ RefinerySetting.find_or_set("inquiry_confirmation_messeage_#{locale}".to_sym,
23
+ RefinerySetting[:inquiry_confirmation_body])
24
+ end
25
+
26
+ def confirmation_message=(value)
27
+ value.first.keys.each do |locale|
28
+ RefinerySetting.set("inquiry_confirmation_messeage_#{locale}".to_sym, value.first[locale.to_sym])
29
+ end
30
+ end
31
+
32
+ def notification_recipients
33
+ RefinerySetting.find_or_set(:inquiry_notification_recipients,
34
+ ((Role[:refinery].users.first.email rescue nil) if defined?(Role)).to_s)
35
+ end
36
+
37
+ def notification_subject
38
+ RefinerySetting.find_or_set(:inquiry_notification_subject,
39
+ "New inquiry from your website")
40
+ end
41
+
42
+ def send_confirmation?
43
+ RefinerySetting.find_or_set(:inquiry_send_confirmation, true)
44
+ end
45
+ end
46
+
47
+ end
@@ -0,0 +1,24 @@
1
+ <li class='clearfix record <%= cycle("on", "on-hover") %>'>
2
+ <span class='title'>
3
+ <%= link_to inquiry.name, admin_inquiry_url(inquiry) %> <%= t('.said') %>
4
+ <span class="preview"><%= truncate(strip_tags(inquiry.message), :length => 60) -%></span>
5
+ </span>
6
+ <span class='actions'>
7
+ <%= link_to refinery_icon_tag('delete.png'), admin_inquiry_url(inquiry),
8
+ { :method => :delete,
9
+ :confirm => t('shared.admin.delete.message', :title => inquiry.name) },
10
+ :class => "cancel confirm-delete",
11
+ :title => t('admin.inquiries.delete') -%>
12
+
13
+ <%= link_to refinery_icon_tag('zoom.png'), admin_inquiry_url(inquiry),
14
+ :title => t('.read_inquiry') -%>
15
+
16
+ <% if inquiry.spam? %>
17
+ <%= link_to refinery_icon_tag('email.png'), toggle_spam_admin_inquiry_url(inquiry),
18
+ :title => t('.mark_as_ham') -%>
19
+ <% else %>
20
+ <%= link_to refinery_icon_tag('bin_closed.png'), toggle_spam_admin_inquiry_url(inquiry),
21
+ :title => t('.mark_as_spam') -%>
22
+ <% end %>
23
+ </span>
24
+ </li>
@@ -0,0 +1,27 @@
1
+ <div id='actions'>
2
+ <ul>
3
+ <li>
4
+ <%= render :partial => "/shared/admin/search", :locals => {:url => request.path} %>
5
+ </li>
6
+ <li <%= "class='selected'" if params[:action] == "index" %>>
7
+ <%= link_to t('.inbox'), admin_inquiries_url, :class => "email_icon" %>
8
+ </li>
9
+ <li <%= "class='selected'" if params[:action] == "spam" %>>
10
+ <% if @spam_count > 0 %>
11
+ <%= link_to "#{t('.spam')} (#{@spam_count})", spam_admin_inquiries_url, :class => "spam_icon" %>
12
+ <% else %>
13
+ <%= link_to t('.spam'), spam_admin_inquiries_url, :class => "spam_empty_icon" %>
14
+ <% end %>
15
+ </li>
16
+ <li>
17
+ <%= link_to t('.update_notified'),
18
+ edit_admin_inquiry_setting_url(:inquiry_notification_recipients, :dialog => true, :height => 300),
19
+ :class => "user_comment_icon" %>
20
+ </li>
21
+ <li>
22
+ <%= link_to t('.edit_confirmation_email'),
23
+ edit_admin_inquiry_setting_url(:inquiry_confirmation_body, :dialog => true),
24
+ :class => "edit_email_icon" %>
25
+ </li>
26
+ </ul>
27
+ </div>
@@ -0,0 +1,30 @@
1
+ <%= render :partial => "submenu" %>
2
+ <div id='records'>
3
+ <% if searching? %>
4
+ <h2><%= t('shared.admin.search.results_for', :query => params[:search]) %></h2>
5
+ <% if @inquiries.any? %>
6
+ <%= will_paginate @inquiries %>
7
+ <ul>
8
+ <%= render :partial => "inquiry", :collection => @inquiries %>
9
+ </ul>
10
+ <%= will_paginate @inquiries %>
11
+ <% else %>
12
+ <p><%= t('shared.admin.search.no_results') %></p>
13
+ <% end %>
14
+ <% else %>
15
+ <% if @inquiries.any? -%>
16
+ <%= will_paginate @inquiries %>
17
+ <% group_by_date(@inquiries).each do |container| %>
18
+ <h3><%= l((inquiry_group = container.last).first.created_at, :format => :short) %></h3>
19
+ <ul>
20
+ <%= render :partial => 'inquiry', :collection => inquiry_group %>
21
+ </ul>
22
+ <% end %>
23
+ <%= will_paginate @inquiries %>
24
+ <% else -%>
25
+ <p>
26
+ <strong><%= t(".no_#{action_name == 'index' ? 'inquiries' : 'spam'}") %></strong>
27
+ </p>
28
+ <% end -%>
29
+ <% end %>
30
+ </div>
@@ -0,0 +1,72 @@
1
+ <div id='actions'>
2
+ <h2><%= t('.details')%></h2>
3
+ <p>
4
+ <strong><%= t('.age') %>:</strong> <%= time_ago_in_words(@inquiry.created_at) %>
5
+ </p>
6
+ <% if @inquiry.spam? %>
7
+ <p>
8
+ <strong><%= t('.spam') %>:</strong> <%= t('.spam_yes') %>
9
+ </p>
10
+ <% end %>
11
+ <h2><%= t('.actions') %></h2>
12
+ <ul>
13
+ <li>
14
+ <%= link_to t('.back_to_all_inquiries'), {:action => 'index'}, :class => "back_icon" %>
15
+ </li>
16
+ <li>
17
+ <%= link_to t('admin.inquiries.delete'),
18
+ admin_inquiry_url(@inquiry),
19
+ :class => 'delete_icon no-tooltip confirm-delete',
20
+ :title => t('admin.inquiries.delete'),
21
+ :confirm => t('shared.admin.delete.message', :title => @inquiry.name),
22
+ :method => :delete %>
23
+ </li>
24
+ </ul>
25
+ </div>
26
+ <div id='records'>
27
+ <h2><%= t('.inquiry') %></h2>
28
+ <table id='inquiry'>
29
+ <tr>
30
+ <td>
31
+ <strong><%= t('.to') %></strong>
32
+ </td>
33
+ <td>
34
+ <%= RefinerySetting[:site_name] %>
35
+ </td>
36
+ </tr>
37
+ <tr>
38
+ <td>
39
+ <strong><%= t('.from') %></strong>
40
+ </td>
41
+ <td>
42
+ <%= @inquiry.name %> [<%= mail_to @inquiry.email, @inquiry.email, {:title => t('.click_to_email')} %>]
43
+ </td>
44
+ </tr>
45
+ <% unless @inquiry.phone.blank? %>
46
+ <tr>
47
+ <td>
48
+ <strong><%= t('.phone') %></strong>
49
+ </td>
50
+ <td>
51
+ <%= @inquiry.phone %>
52
+ </td>
53
+ </tr>
54
+ <% end %>
55
+ <tr>
56
+ <td>
57
+ <strong><%= t('.date') %></strong>
58
+ </td>
59
+ <td>
60
+ <%= l(Date.parse(@inquiry.created_at.to_s), :format => :long) %>
61
+ </td>
62
+ </tr>
63
+ <tr>
64
+ <td valign='top'>
65
+ <strong><%= t('.message') %></strong>
66
+ </td>
67
+ <td>
68
+ <%= simple_format strip_tags(@inquiry.message), :style => 'margin-top: 0' %>
69
+ </td>
70
+ </tr>
71
+ </table>
72
+ </div>
@@ -0,0 +1,59 @@
1
+ <%= form_for([:admin, @refinery_setting], :url => (@url_override || @url)) do |f| %>
2
+
3
+ <p>
4
+ <%= t('.explanation') %>
5
+ </p>
6
+ <p>
7
+ <%= t('.below_edit_email_sent') %>
8
+ </p>
9
+ <table id='inquiry'>
10
+ <tr>
11
+ <td>
12
+ <label class='stripped'><%= t('.to') %></label>
13
+ </td>
14
+ <td>
15
+ <%= t('.the_customer_making_inquiry') %>
16
+ </td>
17
+ </tr>
18
+ <tr>
19
+ <td>
20
+ <label class='stripped'><%= t('.from') %></label>
21
+ </td>
22
+ <td>
23
+ <%= "#{RefinerySetting[:site_name]} &lt;no-reply@#{request.domain(RefinerySetting.find_or_set(:tld_length, 1))}&gt;".html_safe %>
24
+ </td>
25
+ </tr>
26
+ <% (RefinerySetting.get("i18n_translation_frontend_locales", :scoping => 'refinery')||[I18n.locale]).each do |locale| %>
27
+ <tr>
28
+ <td>
29
+ <label class='stripped'><%= t('.subject') %> (<%= locale.to_s %>)</label>
30
+ </td>
31
+ <td>
32
+ <%= text_field_tag "subject[][#{locale.to_s}]", InquirySetting.confirmation_subject(locale),
33
+ :class => 'widest' %>
34
+ </td>
35
+ </tr>
36
+ <tr>
37
+ <td valign='top'>
38
+ <%= f.label :value, t('.message'),
39
+ :class => 'stripped' %> (<%= locale.to_s %>)
40
+ </td>
41
+ <td>
42
+ <%= text_area_tag "message[][#{locale.to_s}]", InquirySetting.confirmation_message(locale), # required, we can't use :value
43
+ :rows => "5",
44
+ :class => 'widest' %>
45
+ <br/>
46
+ <em><%= t('.note') %></em>
47
+ </td>
48
+ </tr>
49
+ <% end %>
50
+ </table>
51
+
52
+ <%= render :partial => "/shared/admin/form_actions",
53
+ :locals => {
54
+ :f => f,
55
+ :continue_editing => false,
56
+ :cancel_url => admin_inquiries_url,
57
+ :hide_delete => true
58
+ } %>
59
+ <% end %>