spree_easy_contact 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/LICENSE ADDED
@@ -0,0 +1,23 @@
1
+ Redistribution and use in source and binary forms, with or without modification,
2
+ are permitted provided that the following conditions are met:
3
+
4
+ * Redistributions of source code must retain the above copyright notice,
5
+ this list of conditions and the following disclaimer.
6
+ * Redistributions in binary form must reproduce the above copyright notice,
7
+ this list of conditions and the following disclaimer in the documentation
8
+ and/or other materials provided with the distribution.
9
+ * Neither the name of the Rails Dog LLC nor the names of its
10
+ contributors may be used to endorse or promote products derived from this
11
+ software without specific prior written permission.
12
+
13
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
14
+ "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
15
+ LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
16
+ A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
17
+ CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18
+ EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19
+ PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20
+ PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
21
+ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
22
+ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
23
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
@@ -0,0 +1,30 @@
1
+ SpreeEasyContact
2
+ ================
3
+
4
+ Easy to implement contact form with honyepot-captcha, with a topic selection management in admin.
5
+ It stores all messages in DB for an easy recall of messages.
6
+
7
+ This extension is based on joshnuss spree-contact-form (thank you BTW) : https://github.com/joshnuss/spree-contact-form
8
+
9
+ Installation
10
+ ============
11
+
12
+ Put the following line into your gemfile :
13
+
14
+ gem 'spree_easy_contact'
15
+
16
+ Then run all the following command :
17
+
18
+ bundle install
19
+
20
+ rake spree_easy_contact:install
21
+
22
+ rake db:migrate
23
+
24
+ Set properly the mail method in the admin area (/admin/mail_methods)
25
+
26
+ And you're done !
27
+ =================
28
+
29
+
30
+ Copyright (c) 2011 [Mathias Standaert for Organic Web], released under the New BSD License
@@ -0,0 +1,4 @@
1
+ class Admin::ContactsController < Admin::BaseController
2
+ resource_controller
3
+
4
+ end
@@ -0,0 +1,11 @@
1
+ class Admin::TopicsController < Admin::BaseController
2
+ resource_controller
3
+
4
+ create.wants.html {redirect_to collection_path}
5
+ update.wants.html {redirect_to collection_path}
6
+
7
+ new_action.response do |wants|
8
+ wants.html {render :action => :new, :layout => !request.xhr?}
9
+ end
10
+
11
+ end
@@ -0,0 +1,28 @@
1
+ class ContactsController < Spree::BaseController
2
+ before_filter :load_topics
3
+
4
+ def new
5
+ @contact = Contact.new
6
+ end
7
+
8
+ def edit
9
+ redirect_to new_contact_path
10
+ end
11
+
12
+ def create
13
+ @contact = Contact.new(params[:contact] || {})
14
+ respond_to do |format|
15
+ if @contact.valid? && @contact.save
16
+ ContactMailer.message_email(@contact).deliver
17
+ format.html { redirect_to(root_path, :notice => t("message_sended")) }
18
+ else
19
+ format.html { render :action => "new" }
20
+ end
21
+ end
22
+ end
23
+
24
+ private
25
+ def load_topics
26
+ @topics = Topic.all
27
+ end
28
+ end
@@ -0,0 +1,5 @@
1
+ module Admin::ContactsHelper
2
+ def link_to_view(resource)
3
+ link_to_with_icon('view', t('view'), object_url(resource))
4
+ end
5
+ end
@@ -0,0 +1,10 @@
1
+ class ContactMailer < ActionMailer::Base
2
+ helper "spree/base"
3
+
4
+ def message_email(message)
5
+ subject = "#{Spree::Config[:site_name]} - Message from #{message.email}"
6
+
7
+ @message = message
8
+ mail(:to => message.topic.email, :subject => subject, :reply_to => message.email)
9
+ end
10
+ end
@@ -0,0 +1,11 @@
1
+ class Contact < ActiveRecord::Base
2
+
3
+ validates :name, :presence => true
4
+ validates :email, :format => {:with => /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\Z/i}
5
+ validates :order_number, :format => {:with => /(^$)|(^R\d{9}$)/i, :message => I18n.t("invalid_order_number")}
6
+
7
+ def topic
8
+ @topic ||= Topic.find(topic_id)
9
+ end
10
+
11
+ end
@@ -0,0 +1,6 @@
1
+ class Topic < ActiveRecord::Base
2
+
3
+ validates :name, :presence => true, :uniqueness => true
4
+ validates :email, :presence => true
5
+
6
+ end
@@ -0,0 +1,33 @@
1
+ <h1><%= t("contacts")%></h1>
2
+
3
+ <table class="index">
4
+ <tr>
5
+ <%= hook :admin_contact_index_headers do %>
6
+ <th><%= t("name") %></th>
7
+ <th><%= t("email") %></th>
8
+ <th><%= t("topic") %></th>
9
+ <th><%= t("sent") %></th>
10
+ <% end %>
11
+ <th>
12
+ <%= hook :admin_contact_index_header_actions %>
13
+ </th>
14
+ </tr>
15
+ <% @contacts.each do |contact| %>
16
+ <tr id="<%= dom_id contact %>">
17
+ <%- locals = {:contact => contact} %>
18
+ <%= hook :admin_contact_index_rows, locals do %>
19
+ <td><%= contact.name %></td>
20
+ <td><%= contact.email %></td>
21
+ <td><%= contact.topic.name %></td>
22
+ <td><%= contact.created_at %></td>
23
+ <% end %>
24
+ <td class="actions">
25
+ <%= hook :admin_contact_index_row_actions, locals do %>
26
+ <%= link_to_view contact %>
27
+ &nbsp;
28
+ <%= link_to_delete contact %>
29
+ <% end %>
30
+ </td>
31
+ </tr>
32
+ <% end %>
33
+ </table>
@@ -0,0 +1,33 @@
1
+ <h1><%= t("contacts")%> de <%= @contact.name %></h1>
2
+
3
+ <%= render :partial => 'admin/shared/contact_tabs', :locals => {:current => "Contact Details"} %>
4
+
5
+ <%= hook :admin_contact_show do %>
6
+ <div class="adr">
7
+ <h4><%= t("name_and_mail") %></h4>
8
+ <p>
9
+ <%= @contact.name %><br />
10
+ <%= @contact.email %>
11
+ </p>
12
+ </div>
13
+ <div class="adr">
14
+ <h4><%= t("topic") %></h4>
15
+ <p>
16
+ Ici le sujet
17
+ </p>
18
+ </div>
19
+ <% if @contact.order_number %>
20
+ <div class="adr">
21
+ <h4><%= t("order_number") %></h4>
22
+ <p>
23
+ <%= @contact.order_number %>
24
+ </p>
25
+ </div>
26
+ <% end %>
27
+ <div class="adr">
28
+ <h4><%= t("message") %></h4>
29
+ <p>
30
+ <%= @contact.message %>
31
+ </p>
32
+ </div>
33
+ <% end %>
@@ -0,0 +1,15 @@
1
+ <% content_for :sidebar do %>
2
+ <ul class="sidebar">
3
+ <%= hook :admin_contact_tabs do %>
4
+ <li<%== ' class="active"' if current == 'Contact List' %>>
5
+ <%= link_to t("contact_list"), collection_url() %>
6
+ </li>
7
+ <li<%== ' class="active"' if current == 'Contact Details' %>>
8
+ <%= link_to t("contact_details"), object_url(@contact) %>
9
+ </li>
10
+ <li<%== ' class="active"' if current == 'ContactResend' %>>
11
+ <%= link_to t("resend"), "#" %>
12
+ </li>
13
+ <% end %>
14
+ </ul>
15
+ <% end %>
@@ -0,0 +1,19 @@
1
+ <%- locals = {:f => f} %>
2
+
3
+ <%= render "shared/error_messages", :target => f.object %>
4
+
5
+ <%= hook :admin_topic_form, locals do %>
6
+
7
+ <%= f.field_container :name do %>
8
+ <%= f.label :name, t("name") %> <span class="required">*</span><br />
9
+ <%= f.text_field :name, :class => 'fullwidth title' %>
10
+ <%= f.error_message_on :name %>
11
+ <% end %>
12
+
13
+ <%= f.field_container :email do %>
14
+ <%= f.label :email, t("emails") %> (<%= t('comma_delimited') %>) <span class="required">*</span><br />
15
+ <%= f.text_field :email, :class => 'fullwidth title' %>
16
+ <%= f.error_message_on :email %>
17
+ <% end %>
18
+
19
+ <% end %>
@@ -0,0 +1,4 @@
1
+ <%= form_for(@topic, :url => object_url, :html => { :method => :put }) do |f| %>
2
+ <%= render :partial => 'form', :locals => {:f => f} %>
3
+ <%= render :partial => 'admin/shared/edit_resource_links' %>
4
+ <% end %>
@@ -0,0 +1,39 @@
1
+ <div class="toolbar">
2
+ <ul class="actions">
3
+ <li id="new_topic_link">
4
+ <%= button_link_to t("new_topic"), new_object_url, {:remote => true, :icon => "add"} %>
5
+ </li>
6
+ </ul>
7
+ <br class="clear" />
8
+ </div>
9
+ <h1><%= t("topics") %></h1>
10
+
11
+ <div id="new_topic"></div>
12
+
13
+ <table class="index">
14
+ <tr>
15
+ <%= hook :admin_topic_index_header do %>
16
+ <th><%= t("name") %></th>
17
+ <th><%= t("email") %></th>
18
+ <% end %>
19
+ <th>
20
+ <%= hook :admin_topic_index_header_actions %>
21
+ </th>
22
+ </tr>
23
+ <% @topics.each do |topic| %>
24
+ <tr id="dom_id topic">
25
+ <%- locals = {:topic => topic} %>
26
+ <%= hook :admin_topics_index_rows, locals do %>
27
+ <td><%= topic.name %></td>
28
+ <td><%= topic.email %></td>
29
+ <% end %>
30
+ <td class="actions">
31
+ <%= hook :admin_topics_index_rows_actions, locals do %>
32
+ <%= link_to_edit topic %>
33
+ &nbsp;
34
+ <%= link_to_delete topic %>
35
+ <% end %>
36
+ </td>
37
+ </tr>
38
+ <% end %>
39
+ </table>
@@ -0,0 +1,4 @@
1
+ <%= form_for(@topic, :url => collection_url) do |f| %>
2
+ <%= render :partial => 'form', :locals => {:f => f} %>
3
+ <%= render :partial => 'admin/shared/new_resource_links' %>
4
+ <% end %>
@@ -0,0 +1,8 @@
1
+ <%= t('name') %>: <%= @message.name %>
2
+ <%= t('email') %>: <%= @message.email %>
3
+ <%= t('topic') %>: <%= @message.topic.name %>
4
+ <% unless @message.order_number.blank? %>
5
+ <%= t('order') %>: <%= @message.order_number.upcase %> <%= "http://#{Spree::Config[:site_url]}/admin/orders/#{@message.order_number.upcase}"%>
6
+ <% end %>
7
+
8
+ <%= @message.message %>
@@ -0,0 +1,32 @@
1
+ <% @body_id = 'contact_us' %>
2
+ <div id="contact-us">
3
+ <h1><%= t("contact_us") %></h1>
4
+ <%= hook :contact do %>
5
+ <%= render "shared/error_messages", :target => @contact %>
6
+ <%= form_for(@contact, :html => {:honeypot => true}) do |f| %>
7
+ <%= hook :contact_inside_form do %>
8
+ <div class="field">
9
+ <%= f.label :topic_id, t("topic") %>
10
+ <%= f.collection_select :topic_id, @topics, :id, :name %>
11
+ </div>
12
+ <div class="field">
13
+ <%= f.label :name, t("name") %><br />
14
+ <%= f.text_field :name %>
15
+ </div>
16
+ <div class="field">
17
+ <%= f.label :email, t("email") %><br />
18
+ <%= f.text_field :email %>
19
+ </div>
20
+ <div class="field">
21
+ <%= f.label :order_number, t("order_number") %> (<%= t("optionnal") %>)<br />
22
+ <%= f.text_field :order_number %>
23
+ </div>
24
+ <div class="field">
25
+ <%= f.label :message, t("message") %><br />
26
+ <%= f.text_area :message %>
27
+ </div>
28
+ <div class="action"><%= f.submit t("send_message"), :class => "button primary" %></div>
29
+ <% end %>
30
+ <% end %>
31
+ <% end %>
32
+ </div>
@@ -0,0 +1,18 @@
1
+ require 'spree_core'
2
+ require 'honeypot-captcha'
3
+ require 'spree_easy_contact_hooks'
4
+
5
+ module SpreeEasyContact
6
+ class Engine < Rails::Engine
7
+
8
+ config.autoload_paths += %W(#{config.root}/lib)
9
+
10
+ def self.activate
11
+ Dir.glob(File.join(File.dirname(__FILE__), "../app/**/*_decorator*.rb")) do |c|
12
+ Rails.env.production? ? require(c) : load(c)
13
+ end
14
+ end
15
+
16
+ config.to_prepare &method(:activate).to_proc
17
+ end
18
+ end
@@ -0,0 +1,11 @@
1
+ class SpreeEasyContactHooks < Spree::ThemeSupport::HookListener
2
+ # custom hooks go here
3
+ insert_after :admin_tabs do
4
+ %(<%= tab(:contacts) %>)
5
+ end
6
+
7
+ insert_after :admin_configurations_menu do
8
+ "<%= configurations_menu_item(I18n.t('topics'), admin_topics_path, I18n.t('topics_description')) %>"
9
+ end
10
+
11
+ end
@@ -0,0 +1,25 @@
1
+ namespace :spree_easy_contact do
2
+ desc "Copies all migrations and assets (NOTE: This will be obsolete with Rails 3.1)"
3
+ task :install do
4
+ Rake::Task['spree_easy_contact:install:migrations'].invoke
5
+ Rake::Task['spree_easy_contact:install:assets'].invoke
6
+ end
7
+
8
+ namespace :install do
9
+ desc "Copies all migrations (NOTE: This will be obsolete with Rails 3.1)"
10
+ task :migrations do
11
+ source = File.join(File.dirname(__FILE__), '..', '..', 'db')
12
+ destination = File.join(Rails.root, 'db')
13
+ Spree::FileUtilz.mirror_files(source, destination)
14
+ end
15
+
16
+ desc "Copies all assets (NOTE: This will be obsolete with Rails 3.1)"
17
+ task :assets do
18
+ source = File.join(File.dirname(__FILE__), '..', '..', 'public')
19
+ destination = File.join(Rails.root, 'public')
20
+ puts "INFO: Mirroring assets from #{source} to #{destination}"
21
+ Spree::FileUtilz.mirror_files(source, destination)
22
+ end
23
+ end
24
+
25
+ end
@@ -0,0 +1 @@
1
+ # add custom rake tasks here
metadata ADDED
@@ -0,0 +1,119 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: spree_easy_contact
3
+ version: !ruby/object:Gem::Version
4
+ hash: 23
5
+ prerelease: false
6
+ segments:
7
+ - 1
8
+ - 0
9
+ - 0
10
+ version: 1.0.0
11
+ platform: ruby
12
+ authors:
13
+ - Mathias Standaert
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-02-08 00:00:00 +01:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: spree_core
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 191
30
+ segments:
31
+ - 0
32
+ - 40
33
+ - 0
34
+ version: 0.40.0
35
+ type: :runtime
36
+ version_requirements: *id001
37
+ - !ruby/object:Gem::Dependency
38
+ name: honeypot-captcha
39
+ prerelease: false
40
+ requirement: &id002 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ hash: 3
46
+ segments:
47
+ - 0
48
+ version: "0"
49
+ type: :runtime
50
+ version_requirements: *id002
51
+ description:
52
+ email: contact@organicweb.fr
53
+ executables: []
54
+
55
+ extensions: []
56
+
57
+ extra_rdoc_files:
58
+ - README.md
59
+ files:
60
+ - README.md
61
+ - LICENSE
62
+ - lib/spree_easy_contact.rb
63
+ - lib/spree_easy_contact_hooks.rb
64
+ - lib/tasks/install.rake
65
+ - lib/tasks/spree_easy_contact.rake
66
+ - app/controllers/admin/contacts_controller.rb
67
+ - app/controllers/admin/topics_controller.rb
68
+ - app/controllers/contacts_controller.rb
69
+ - app/helpers/admin/contacts_helper.rb
70
+ - app/mailer/contact_mailer.rb
71
+ - app/models/contact.rb
72
+ - app/models/topic.rb
73
+ - app/views/admin/contacts/index.html.erb
74
+ - app/views/admin/contacts/show.html.erb
75
+ - app/views/admin/shared/_contact_tabs.html.erb
76
+ - app/views/admin/topics/_form.html.erb
77
+ - app/views/admin/topics/edit.html.erb
78
+ - app/views/admin/topics/index.html.erb
79
+ - app/views/admin/topics/new.html.erb
80
+ - app/views/contact_mailer/message_email.text.erb
81
+ - app/views/contacts/new.html.erb
82
+ has_rdoc: true
83
+ homepage: https://github.com/organicweb/spree-easy-contact.git
84
+ licenses:
85
+ - BSD
86
+ post_install_message:
87
+ rdoc_options: []
88
+
89
+ require_paths:
90
+ - lib
91
+ required_ruby_version: !ruby/object:Gem::Requirement
92
+ none: false
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ hash: 57
97
+ segments:
98
+ - 1
99
+ - 8
100
+ - 7
101
+ version: 1.8.7
102
+ required_rubygems_version: !ruby/object:Gem::Requirement
103
+ none: false
104
+ requirements:
105
+ - - ">="
106
+ - !ruby/object:Gem::Version
107
+ hash: 3
108
+ segments:
109
+ - 0
110
+ version: "0"
111
+ requirements:
112
+ - none
113
+ rubyforge_project:
114
+ rubygems_version: 1.3.7
115
+ signing_key:
116
+ specification_version: 3
117
+ summary: Add gem summary here
118
+ test_files: []
119
+