refinerycms-inquiries 0.9.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (37) hide show
  1. data/app/controllers/admin/inquiries_controller.rb +32 -0
  2. data/app/controllers/admin/inquiry_settings_controller.rb +22 -0
  3. data/app/controllers/inquiries_controller.rb +47 -0
  4. data/app/helpers/inquiries_helper.rb +2 -0
  5. data/app/mailers/inquiry_mailer.rb +20 -0
  6. data/app/models/inquiry.rb +25 -0
  7. data/app/models/inquiry_setting.rb +25 -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 +26 -0
  11. data/app/views/admin/inquiries/show.html.erb +74 -0
  12. data/app/views/admin/inquiries/spam.html.erb +26 -0
  13. data/app/views/admin/inquiry_settings/_confirmation_email_form.html.erb +57 -0
  14. data/app/views/admin/inquiry_settings/_notification_recipients_form.html.erb +24 -0
  15. data/app/views/admin/inquiry_settings/edit.html.erb +5 -0
  16. data/app/views/inquiries/new.html.erb +34 -0
  17. data/app/views/inquiries/thank_you.html.erb +1 -0
  18. data/app/views/inquiry_mailer/confirmation.html.erb +1 -0
  19. data/app/views/inquiry_mailer/notification.html.erb +18 -0
  20. data/config/locales/da.yml +68 -0
  21. data/config/locales/de.yml +71 -0
  22. data/config/locales/en.yml +76 -0
  23. data/config/locales/es.yml +69 -0
  24. data/config/locales/fr.yml +66 -0
  25. data/config/locales/it.yml +67 -0
  26. data/config/locales/lv.yml +76 -0
  27. data/config/locales/nb.yml +77 -0
  28. data/config/locales/nl.yml +76 -0
  29. data/config/locales/pt-BR.yml +86 -0
  30. data/config/locales/ru.yml +79 -0
  31. data/config/locales/sl.yml +68 -0
  32. data/config/locales/zh-CN.yml +73 -0
  33. data/config/routes.rb +20 -0
  34. data/lib/inquiries.rb +24 -0
  35. data/license.md +21 -0
  36. data/readme.md +23 -0
  37. metadata +135 -0
@@ -0,0 +1,32 @@
1
+ class Admin::InquiriesController < Admin::BaseController
2
+
3
+ crudify :inquiry, :title_attribute => "name", :order => "created_at DESC"
4
+
5
+ before_filter :get_spam_count, :only => [:index, :spam]
6
+
7
+ def index
8
+ @inquiries = Inquiry.ham.with_query(params[:search]) if searching?
9
+
10
+ @grouped_inquiries = group_by_date(Inquiry.ham)
11
+ end
12
+
13
+ def spam
14
+ @inquiries = Inquiry.spam.with_query(params[:search]) if searching?
15
+
16
+ @grouped_inquiries = group_by_date(Inquiry.spam)
17
+ end
18
+
19
+ def toggle_spam
20
+ find_inquiry
21
+ @inquiry.toggle!(:spam)
22
+
23
+ redirect_to :back
24
+ end
25
+
26
+ protected
27
+
28
+ def get_spam_count
29
+ @spam_count = Inquiry.count(:conditions => {:spam => true})
30
+ end
31
+
32
+ end
@@ -0,0 +1,22 @@
1
+ class Admin::InquirySettingsController < Admin::BaseController
2
+
3
+ crudify :inquiry_setting, :title_attribute => "name", :order => 'name ASC', :redirect_to_url => "admin_inquiries_url"
4
+
5
+ before_filter :redirect_back_to_inquiries?, :only => [:index]
6
+ before_filter :set_url_override?, :only => [:edit]
7
+ after_filter :save_subject_for_confirmation?, :only => [:create, :update]
8
+
9
+ protected
10
+ def save_subject_for_confirmation?
11
+ InquirySetting.confirmation_subject = params[:subject] if params.keys.include?('subject')
12
+ end
13
+
14
+ def redirect_back_to_inquiries?
15
+ redirect_to admin_inquiries_url
16
+ end
17
+
18
+ def set_url_override?
19
+ @url_override = admin_inquiry_setting_url(@inquiry_setting, :dialog => from_dialog?)
20
+ end
21
+
22
+ end
@@ -0,0 +1,47 @@
1
+ class InquiriesController < ApplicationController
2
+
3
+ before_filter :find_page, :only => [:create, :new]
4
+
5
+ def index
6
+ redirect_to :action => "new"
7
+ end
8
+
9
+ def thank_you
10
+ @page = Page.find_by_link_url("/contact/thank_you", :include => [:parts, :slugs])
11
+ end
12
+
13
+ def new
14
+ @inquiry = Inquiry.new
15
+ end
16
+
17
+ def create
18
+ @inquiry = Inquiry.new(params[:inquiry])
19
+
20
+ if @inquiry.save
21
+ if @inquiry.ham?
22
+ begin
23
+ InquiryMailer.notification(@inquiry, request).deliver
24
+ rescue
25
+ logger.warn "There was an error delivering an inquiry notification.\n#{$!}\n"
26
+ end
27
+
28
+ begin
29
+ InquiryMailer.confirmation(@inquiry, request).deliver
30
+ rescue
31
+ logger.warn "There was an error delivering an inquiry confirmation:\n#{$!}\n"
32
+ end
33
+ end
34
+
35
+ redirect_to thank_you_inquiries_url
36
+ else
37
+ render :action => 'new'
38
+ end
39
+ end
40
+
41
+ protected
42
+
43
+ def find_page
44
+ @page = Page.find_by_link_url('/contact', :include => [:parts, :slugs])
45
+ end
46
+
47
+ end
@@ -0,0 +1,2 @@
1
+ module InquiriesHelper
2
+ end
@@ -0,0 +1,20 @@
1
+ class InquiryMailer < ActionMailer::Base
2
+
3
+ def confirmation(inquiry, request)
4
+ subject InquirySetting.confirmation_subject.value
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.value.split(',').first
8
+ sent_on Time.now
9
+ @inquiry = inquiry
10
+ end
11
+
12
+ def notification(inquiry, request)
13
+ subject InquirySetting.notification_subject.value
14
+ recipients InquirySetting.notification_recipients.value
15
+ from "\"#{RefinerySetting[:site_name]}\" <no-reply@#{request.domain(RefinerySetting.find_or_set(:tld_length, 1))}>"
16
+ sent_on Time.now
17
+ @inquiry = inquiry
18
+ end
19
+
20
+ end
@@ -0,0 +1,25 @@
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
+ scope :newest, :order => 'created_at DESC'
16
+
17
+ def self.latest(number = 7, include_spam = false)
18
+ unless include_spam
19
+ ham.find(:all, :limit => number)
20
+ else
21
+ newest.find(:all, :limit => number)
22
+ end
23
+ end
24
+
25
+ end
@@ -0,0 +1,25 @@
1
+ class InquirySetting < ActiveRecord::Base
2
+
3
+ def self.confirmation_body
4
+ RefinerySetting.find_or_set(:inquiry_confirmation_body,
5
+ "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."
6
+ )
7
+ end
8
+
9
+ def self.confirmation_subject
10
+ RefinerySetting.find_or_set(:inquiry_confirmation_subject, "Thank you for your inquiry")
11
+ end
12
+
13
+ def self.confirmation_subject=(value)
14
+ RefinerySetting[:inquiry_confirmation_subject] = value
15
+ end
16
+
17
+ def self.notification_recipients
18
+ RefinerySetting.find_or_set(:inquiry_notification_recipients, (Role[:refinery].users.first.email if defined?(Role)))
19
+ end
20
+
21
+ def self.notification_subject
22
+ RefinerySetting.find_or_set(:inquiry_notification_subject, "New inquiry from your website")
23
+ end
24
+
25
+ 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
+ :class => "cancel confirm-delete",
9
+ :title => t('admin.inquiries.delete'),
10
+ :'data-confirm' => t('shared.admin.delete.message', :title => inquiry.name),
11
+ :'data-method' => "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(InquirySetting.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(InquirySetting.confirmation_body, :dialog => true),
24
+ :class => "edit_email_icon" %>
25
+ </li>
26
+ </ul>
27
+ </div>
@@ -0,0 +1,26 @@
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
+ <ul>
7
+ <%= render :partial => "inquiry", :collection => @inquiries %>
8
+ </ul>
9
+ <% else %>
10
+ <p><%= t('shared.admin.search.no_results') %></p>
11
+ <% end %>
12
+ <% else %>
13
+ <% if @grouped_inquiries.any? -%>
14
+ <% @grouped_inquiries.each do |container| %>
15
+ <h3><%= l((inquiry_group = container.last).first.created_at) %></h3>
16
+ <ul>
17
+ <%= render :partial => 'inquiry', :collection => inquiry_group %>
18
+ </ul>
19
+ <% end %>
20
+ <% else -%>
21
+ <p>
22
+ <strong><%= t('.no_inquiries') %></strong>
23
+ </p>
24
+ <% end -%>
25
+ <% end %>
26
+ </div>
@@ -0,0 +1,74 @@
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
+ :'data-confirm' => t('shared.admin.delete.message', :title => @inquiry.name),
22
+ :'data-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
+ <p style='margin-top: 0px'>
69
+ <%= @inquiry.message.gsub("\r\n\r\n", "\r\n").gsub("\r\n", "</p><p>") %>
70
+ </p>
71
+ </td>
72
+ </tr>
73
+ </table>
74
+ </div>
@@ -0,0 +1,26 @@
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
+ <ul>
7
+ <%= render :partial => "inquiry", :collection => @inquiries %>
8
+ </ul>
9
+ <% else %>
10
+ <p><%= t('shared.admin.search.no_results') %></p>
11
+ <% end %>
12
+ <% else %>
13
+ <% if @grouped_inquiries.any? -%>
14
+ <% @grouped_inquiries.each do |container| %>
15
+ <h3><%= l((inquiry_group = container.last).first.created_at) %></h3>
16
+ <ul>
17
+ <%= render :partial => 'inquiry', :collection => inquiry_group %>
18
+ </ul>
19
+ <% end %>
20
+ <% else -%>
21
+ <p>
22
+ <strong><%= t('.no_spam') %></strong>
23
+ </p>
24
+ <% end -%>
25
+ <% end %>
26
+ </div>
@@ -0,0 +1,57 @@
1
+ <%= form_for([:admin, @inquiry_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
+ <tr>
27
+ <td>
28
+ <label class='stripped'><%= t('.subject') %></label>
29
+ </td>
30
+ <td>
31
+ <%= text_field_tag 'subject', InquirySetting.confirmation_subject.value,
32
+ :class => 'widest' %>
33
+ </td>
34
+ </tr>
35
+ <tr>
36
+ <td valign='top'>
37
+ <%= f.label :value, t('.message'),
38
+ :class => 'stripped' %>
39
+ </td>
40
+ <td>
41
+ <%= f.text_area :value,
42
+ :rows => "5",
43
+ :class => 'widest' %>
44
+ <br/>
45
+ <em><%= t('.note') %></em>
46
+ </td>
47
+ </tr>
48
+ </table>
49
+
50
+ <%= render :partial => "/shared/admin/form_actions",
51
+ :locals => {
52
+ :f => f,
53
+ :continue_editing => false,
54
+ :cancel_url => admin_inquiries_url,
55
+ :hide_delete => true
56
+ } %>
57
+ <% end %>
@@ -0,0 +1,24 @@
1
+ <%= form_for([:admin, @inquiry_setting], :url => (@url_override || @url)) do |f| %>
2
+
3
+ <div class='field'>
4
+ <span class='label_with_help'>
5
+ <%= f.label :value, t('.inquiry_settings_value_name') %>
6
+ </span>
7
+ <%= f.text_field :value, :class => "larger widest" %>
8
+ </div>
9
+
10
+ <p>
11
+ <%= t('.hint') %>
12
+ </p>
13
+ <p>
14
+ <%= t('.example') %>
15
+ </p>
16
+
17
+ <%= render :partial => "/shared/admin/form_actions",
18
+ :locals => {
19
+ :f => f,
20
+ :continue_editing => false,
21
+ :cancel_url => admin_inquiries_url,
22
+ :hide_delete => true
23
+ } %>
24
+ <% end %>