spree_contact_form 3.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +13 -0
- data/app/controllers/admin/contact_topics_controller.rb +11 -0
- data/app/controllers/contact_controller.rb +23 -0
- data/app/helpers/admin/contact_topics_helper.rb +2 -0
- data/app/helpers/contact_helper.rb +2 -0
- data/app/mailers/contact_mailer.rb +10 -0
- data/app/models/contact_topic.rb +4 -0
- data/app/models/message.rb +21 -0
- data/app/views/admin/contact_topics/_form.html.erb +19 -0
- data/app/views/admin/contact_topics/edit.html.erb +4 -0
- data/app/views/admin/contact_topics/index.html.erb +42 -0
- data/app/views/admin/contact_topics/new.html.erb +4 -0
- data/app/views/contact/show.html.erb +48 -0
- data/app/views/contact_mailer/message_email.text.erb +8 -0
- data/config/routes.rb +7 -0
- data/lib/generators/spree_contact_form/install_generator.rb +13 -0
- data/lib/generators/templates/db/migrate/20101122153512_create_contact_topics.rb +14 -0
- data/lib/spree_contact_form/engine.rb +12 -0
- data/lib/spree_contact_form.rb +3 -0
- data/lib/spree_contact_form_hooks.rb +7 -0
- metadata +103 -0
data/README.md
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
class Admin::ContactTopicsController < 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,23 @@
|
|
1
|
+
class ContactController < Spree::BaseController
|
2
|
+
before_filter :load_topics
|
3
|
+
|
4
|
+
def show
|
5
|
+
@message = Message.new
|
6
|
+
end
|
7
|
+
|
8
|
+
def create
|
9
|
+
@message = Message.new(params[:message] || {})
|
10
|
+
if @message.valid?
|
11
|
+
ContactMailer.message_email(@message).deliver
|
12
|
+
flash[:notice] = t('contact_thank_you')
|
13
|
+
redirect_to root_path
|
14
|
+
else
|
15
|
+
render :action => 'show'
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
def load_topics
|
21
|
+
@topics = ContactTopic.all
|
22
|
+
end
|
23
|
+
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.emails, :subject => subject, :reply_to => message.email)
|
9
|
+
end
|
10
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
class Message
|
2
|
+
include ActiveModel::Validations
|
3
|
+
|
4
|
+
attr_accessor :name, :email, :message, :topic_id, :order_number
|
5
|
+
|
6
|
+
validates_presence_of :name, :message, :topic_id
|
7
|
+
|
8
|
+
validates_format_of :email, :with => /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\Z/i
|
9
|
+
validates_format_of :order_number, :with => /(^$)|(^R\d{9}$)/i, :message => I18n.t("invalid_order_number")
|
10
|
+
|
11
|
+
|
12
|
+
def initialize(attributes={})
|
13
|
+
attributes.each do |attr, val|
|
14
|
+
send("#{attr}=", val)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def topic
|
19
|
+
@topic ||= ContactTopic.find(topic_id)
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
<%- locals = {:f => f} %>
|
2
|
+
|
3
|
+
<%= render "shared/error_messages", :target => f.object %>
|
4
|
+
|
5
|
+
<%= hook :admin_contact_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 :emails do %>
|
14
|
+
<%= f.label :emails, t("emails") %> (<%= t('comma_delimited') %>) <span class="required">*</span><br />
|
15
|
+
<%= f.text_field :emails, :class => 'fullwidth title' %>
|
16
|
+
<%= f.error_message_on :emails %>
|
17
|
+
<% end %>
|
18
|
+
|
19
|
+
<% end %>
|
@@ -0,0 +1,42 @@
|
|
1
|
+
<div class='toolbar'>
|
2
|
+
<ul class='actions'>
|
3
|
+
<li id="new_contact_topic_link">
|
4
|
+
<%= button_link_to t("new_contact_topic"), new_object_url, {:remote => true, :icon => 'add'} %>
|
5
|
+
</li>
|
6
|
+
</ul>
|
7
|
+
<br class='clear' />
|
8
|
+
</div>
|
9
|
+
|
10
|
+
<h1><%= t("contact_topics")%></h1>
|
11
|
+
|
12
|
+
<div id="new_contact_topic"></div>
|
13
|
+
|
14
|
+
<table class="index">
|
15
|
+
<tr>
|
16
|
+
<%= hook :admin_contact_topic_index_headers do %>
|
17
|
+
<th><%= t("name") %></th>
|
18
|
+
<th><%= t("emails") %></th>
|
19
|
+
<% end %>
|
20
|
+
<th>
|
21
|
+
<%= hook :admin_contact_topic_index_header_actions %>
|
22
|
+
</th>
|
23
|
+
</tr>
|
24
|
+
<% @contact_topics.each do |topic| %>
|
25
|
+
<tr id="<%= dom_id topic %>">
|
26
|
+
<%- locals = {:topic => topic} %>
|
27
|
+
<%= hook :admin_contact_topics_index_rows, locals do %>
|
28
|
+
<td><%= topic.name %></td>
|
29
|
+
<td><%= topic.emails %></td>
|
30
|
+
<% end %>
|
31
|
+
<td class="actions">
|
32
|
+
<%= hook :admin_contact_topics_index_row_actions, locals do %>
|
33
|
+
<%= link_to_edit topic %>
|
34
|
+
|
35
|
+
<%= link_to_delete topic %>
|
36
|
+
<% end %>
|
37
|
+
</td>
|
38
|
+
</tr>
|
39
|
+
<% end %>
|
40
|
+
</table>
|
41
|
+
|
42
|
+
|
@@ -0,0 +1,48 @@
|
|
1
|
+
<% @body_id = 'contact_us' %>
|
2
|
+
|
3
|
+
|
4
|
+
<div id="contact-us">
|
5
|
+
<h1><%= t("contact_us") %></h1>
|
6
|
+
|
7
|
+
<%= hook :contact do %>
|
8
|
+
|
9
|
+
<%= render "shared/error_messages", :target => @message %>
|
10
|
+
|
11
|
+
<%= form_for(:message, @message, :url => contact_path) do |f| %>
|
12
|
+
|
13
|
+
<%= hook :contact_inside_form do %>
|
14
|
+
|
15
|
+
<p>
|
16
|
+
<%= f.label :topic_id, t("subject") %><br />
|
17
|
+
<%= f.collection_select :topic_id, @topics, :id, :name %>
|
18
|
+
</p>
|
19
|
+
|
20
|
+
<p>
|
21
|
+
<%= f.label :name, t("name") %><br />
|
22
|
+
<%= f.text_field :name %>
|
23
|
+
</p>
|
24
|
+
|
25
|
+
<p>
|
26
|
+
<%= f.label :email, t("email") %><br />
|
27
|
+
<%= f.text_field :email %>
|
28
|
+
</p>
|
29
|
+
|
30
|
+
<p>
|
31
|
+
<%= f.label :order_number, t("order_number") %> (<%= t('optional') %>)<br />
|
32
|
+
<%= f.text_field :order_number %>
|
33
|
+
</p>
|
34
|
+
|
35
|
+
<p>
|
36
|
+
<%= f.label :message, t("message") %><br />
|
37
|
+
<%= f.text_area :message, :rows => 10 %>
|
38
|
+
</p>
|
39
|
+
|
40
|
+
<p><%= submit_tag t("send_message"), :class => 'button primary' %></p>
|
41
|
+
<% end %>
|
42
|
+
|
43
|
+
<% end %>
|
44
|
+
|
45
|
+
<% end %>
|
46
|
+
|
47
|
+
</div>
|
48
|
+
|
@@ -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 %>
|
data/config/routes.rb
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
module SpreeContactForm
|
2
|
+
module Generators
|
3
|
+
class InstallGenerator < Rails::Generators::Base
|
4
|
+
source_root File.expand_path("../../templates", __FILE__)
|
5
|
+
|
6
|
+
desc "Configures your Rails application for use with spree_contact_form"
|
7
|
+
def copy_migrations
|
8
|
+
directory "db"
|
9
|
+
end
|
10
|
+
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
metadata
ADDED
@@ -0,0 +1,103 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: spree_contact_form
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 3
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 3
|
8
|
+
- 0
|
9
|
+
- 2
|
10
|
+
version: 3.0.2
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Josh Nussbaum
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2011-01-06 00:00:00 -05: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: 101
|
30
|
+
segments:
|
31
|
+
- 0
|
32
|
+
- 30
|
33
|
+
- 1
|
34
|
+
version: 0.30.1
|
35
|
+
type: :runtime
|
36
|
+
version_requirements: *id001
|
37
|
+
description: Add a contact form for your spree website, you can setup topics and when the user submits the form, it is emailed to the site admin
|
38
|
+
email: joshnuss@gmail.com
|
39
|
+
executables: []
|
40
|
+
|
41
|
+
extensions: []
|
42
|
+
|
43
|
+
extra_rdoc_files: []
|
44
|
+
|
45
|
+
files:
|
46
|
+
- README.md
|
47
|
+
- lib/spree_contact_form_hooks.rb
|
48
|
+
- lib/spree_contact_form.rb
|
49
|
+
- lib/spree_contact_form/engine.rb
|
50
|
+
- lib/generators/spree_contact_form/install_generator.rb
|
51
|
+
- lib/generators/templates/db/migrate/20101122153512_create_contact_topics.rb
|
52
|
+
- app/views/contact_mailer/message_email.text.erb
|
53
|
+
- app/views/contact/show.html.erb
|
54
|
+
- app/views/admin/contact_topics/edit.html.erb
|
55
|
+
- app/views/admin/contact_topics/new.html.erb
|
56
|
+
- app/views/admin/contact_topics/_form.html.erb
|
57
|
+
- app/views/admin/contact_topics/index.html.erb
|
58
|
+
- app/helpers/contact_helper.rb
|
59
|
+
- app/helpers/admin/contact_topics_helper.rb
|
60
|
+
- app/controllers/contact_controller.rb
|
61
|
+
- app/controllers/admin/contact_topics_controller.rb
|
62
|
+
- app/mailers/contact_mailer.rb
|
63
|
+
- app/models/contact_topic.rb
|
64
|
+
- app/models/message.rb
|
65
|
+
- config/routes.rb
|
66
|
+
has_rdoc: true
|
67
|
+
homepage: http://spreecommerce.com
|
68
|
+
licenses: []
|
69
|
+
|
70
|
+
post_install_message:
|
71
|
+
rdoc_options: []
|
72
|
+
|
73
|
+
require_paths:
|
74
|
+
- lib
|
75
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
76
|
+
none: false
|
77
|
+
requirements:
|
78
|
+
- - ">="
|
79
|
+
- !ruby/object:Gem::Version
|
80
|
+
hash: 57
|
81
|
+
segments:
|
82
|
+
- 1
|
83
|
+
- 8
|
84
|
+
- 7
|
85
|
+
version: 1.8.7
|
86
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
87
|
+
none: false
|
88
|
+
requirements:
|
89
|
+
- - ">="
|
90
|
+
- !ruby/object:Gem::Version
|
91
|
+
hash: 3
|
92
|
+
segments:
|
93
|
+
- 0
|
94
|
+
version: "0"
|
95
|
+
requirements:
|
96
|
+
- none
|
97
|
+
rubyforge_project: spree_contact_form
|
98
|
+
rubygems_version: 1.3.7
|
99
|
+
signing_key:
|
100
|
+
specification_version: 3
|
101
|
+
summary: Adds a contact form for your spree site
|
102
|
+
test_files: []
|
103
|
+
|