Skip to content

Commit

Permalink
Ported to Spree 1.x.x
Browse files Browse the repository at this point in the history
  • Loading branch information
buddhi-desilva committed Apr 26, 2012
1 parent c1cf73c commit 716d202
Show file tree
Hide file tree
Showing 28 changed files with 115 additions and 80 deletions.
1 change: 1 addition & 0 deletions GEM_VERSION
@@ -0,0 +1 @@
4.0.0
5 changes: 3 additions & 2 deletions Versionfile
@@ -1,4 +1,5 @@
"0.70.x" => { :branch => "master", :version => '3.0.5' }
"1.x.x" => { :branch => "master", :version => '4.0.0' }
"0.70.x" => { :tag => "0.70.x", :version => '3.0.5' }
"0.60.x" => { :tag => "0.60.x", :version => '3.0.4' }
"0.50.x" => { :tag => "0.60.x", :version => '3.0.4' }
"0.40.x" => { :tag => "0.60.x", :version => '3.0.4' }
"0.40.x" => { :tag => "0.60.x", :version => '3.0.4' }
11 changes: 0 additions & 11 deletions app/controllers/admin/contact_topics_controller.rb

This file was deleted.

23 changes: 0 additions & 23 deletions app/controllers/contact_controller.rb

This file was deleted.

13 changes: 13 additions & 0 deletions app/controllers/spree/admin/contact_topics_controller.rb
@@ -0,0 +1,13 @@
module Spree
module Admin
class ContactTopicsController < ResourceController

# create.wants.html { redirect_to collection_path }
# update.wants.html { redirect_to collection_path }
#
# new_action.response do |wants|
# wants.html {render :action => :new, :layout => !request.xhr?}
# end
end
end
end
25 changes: 25 additions & 0 deletions app/controllers/spree/contact_controller.rb
@@ -0,0 +1,25 @@
module Spree
class ContactController < BaseController
before_filter :load_topics

def show
@message = Message.new
end

def create
@message = Message.new(params[:message] || {})
if @message.save
ContactMailer.message_email(@message).deliver
flash[:notice] = t('contact_thank_you')
redirect_to root_path
else
render :action => 'show'
end
end

private
def load_topics
@topics = ContactTopic.all
end
end
end
2 changes: 0 additions & 2 deletions app/helpers/admin/contact_topics_helper.rb

This file was deleted.

2 changes: 0 additions & 2 deletions app/helpers/contact_helper.rb

This file was deleted.

6 changes: 6 additions & 0 deletions app/helpers/spree/admin/contact_topics_helper.rb
@@ -0,0 +1,6 @@
module Spree
module Admin
module ContactTopicsHelper
end
end
end
4 changes: 4 additions & 0 deletions app/helpers/spree/contact_helper.rb
@@ -0,0 +1,4 @@
module Spree
module ContactHelper
end
end
10 changes: 0 additions & 10 deletions app/mailers/contact_mailer.rb

This file was deleted.

12 changes: 12 additions & 0 deletions app/mailers/spree/contact_mailer.rb
@@ -0,0 +1,12 @@
module Spree
class ContactMailer < ActionMailer::Base
helper "spree/base"

def message_email(message)
subject = "#{Spree::Config[:site_name]} - Message from #{message.email}"

@message = message
mail(:to => message.topic.emails, :subject => subject, :reply_to => message.email)
end
end
end
4 changes: 0 additions & 4 deletions app/models/contact_topic.rb

This file was deleted.

8 changes: 0 additions & 8 deletions app/models/message.rb

This file was deleted.

6 changes: 6 additions & 0 deletions app/models/spree/contact_topic.rb
@@ -0,0 +1,6 @@
module Spree
class ContactTopic < ActiveRecord::Base
validates :name, :emails, :presence => true
validates :name, :uniqueness => true
end
end
10 changes: 10 additions & 0 deletions app/models/spree/message.rb
@@ -0,0 +1,10 @@
module Spree
class Message < ActiveRecord::Base
validates :name, :message, :topic_id, :presence => true

validates :email, :format => /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\Z/i
validates :order_number, :format => /(^$)|(^R\d{9}$)/i

belongs_to :topic, :class_name => 'ContactTopic'
end
end
9 changes: 8 additions & 1 deletion app/overrides/admin.rb
@@ -1,5 +1,12 @@
Deface::Override.new(:virtual_path => "admin/configurations/index",
Deface::Override.new(:virtual_path => "spree/admin/configurations/index",
:name => "converted_admin_configurations_menu_394888068",
:insert_after => "[data-hook='admin_configurations_menu'], #admin_configurations_menu[data-hook]",
# :insert_bottom => "[data-hook='admin_tabs'], #admin_tabs[data-hook]",
:text => "<%= configurations_menu_item(I18n.t('contact_topics'), admin_contact_topics_path, I18n.t('contact_topics_description')) %>",
:disabled => false)

# Deface::Override.new(:virtual_path => "spree/layouts/admin",
# :name => "promo_admin_tabs",
# :insert_bottom => "[data-hook='admin_tabs'], #admin_tabs[data-hook]",
# :text => "<%= tab(:promotions, :url => spree.admin_promotions_path) %>",
# :disabled => false)
@@ -1,6 +1,6 @@
<%- locals = {:f => f} %>
<%= render "shared/error_messages", :target => f.object %>
<%= render "spree/shared/error_messages", :target => f.object %>

<div data-hook="admin_contact_topic_form">

Expand All @@ -12,7 +12,7 @@
<%= f.field_container :emails do %>
<%= f.label :emails, t("emails") %> (<%= t('comma_delimited') %>) <span class="required">*</span><br />
<%= f.text_field :emails, :class => 'fullwidth title' %>
<%= f.text_field :emails, :class => 'fullwidth title' %>
<%= f.error_message_on :emails %>
<% end %>

Expand Down
@@ -1,7 +1,7 @@
<div class='toolbar'>
<ul class='actions'>
<li id="new_contact_topic_link">
<%= button_link_to t("new_contact_topic"), new_object_url, {:remote => true, :icon => 'add'} %>
<p><%= button_link_to t(:new_contact_topic), new_object_url, :icon => 'add' %></p>
</li>
</ul>
<br class='clear' />
Expand Down
@@ -1,4 +1,9 @@
<h1><%= t(:topic) %></h1>

<%= form_for(@contact_topic, :url => collection_url) do |f| %>
<%= render :partial => 'form', :locals => {:f => f} %>
<%= render :partial => 'admin/shared/new_resource_links' %>
<%= render :partial => 'spree/admin/shared/new_resource_links' %>
<% end %>



Expand Up @@ -5,7 +5,8 @@
<h1><%= t("contact_us") %></h1>

<div data-hook='contact'>
<%= render "shared/error_messages", :target => @message %>
<%= render "spree/shared/error_messages", :target => @message %>
<br/>

<%= form_for(:message, :url => contact_path) do |f| %>

Expand All @@ -26,7 +27,7 @@
</p>

<p>
<%= f.label :order_number, t("order_number") %> (<%= t('optional') %>)<br />
<%= f.label :order_number, t(:order_number) %> (<%= t('optional') %>)<br />
<%= f.text_field :order_number %>
</p>

Expand Down
3 changes: 2 additions & 1 deletion config/locales/en.yml
@@ -1,9 +1,10 @@
en:
contact_us: Contact Us
contact_us: Contact us
send_message: Send Message
subject: Subject
optional: optional
message: Message
order_number: Order number (if you are contacting regarding an order)
topic: Topic
invalid_order_number: "should start with letter 'R' followed by 9 numbers (e.g. R123123213)"
contact_thank_you: "Thank you! Your message has been sent successfully, we will be contacting you shortly"
Expand Down
6 changes: 3 additions & 3 deletions config/routes.rb
@@ -1,7 +1,7 @@
Rails.application.routes.draw do
Spree::Core::Engine.routes.prepend do
resource :contact, :controller => 'contact'

namespace :admin do
resources :contact_topics
end
end
end
end
4 changes: 2 additions & 2 deletions db/migrate/20101122153512_create_contact_topics.rb
@@ -1,6 +1,6 @@
class CreateContactTopics < ActiveRecord::Migration
def self.up
create_table :contact_topics do |t|
create_table :spree_contact_topics do |t|
t.string :name
t.string :emails

Expand All @@ -9,6 +9,6 @@ def self.up
end

def self.down
drop_table :contact_topics
drop_table :spree_contact_topics
end
end
4 changes: 2 additions & 2 deletions db/migrate/20101122153513_create_messages.rb
@@ -1,6 +1,6 @@
class CreateMessages < ActiveRecord::Migration
def self.up
create_table :messages do |t|
create_table :spree_messages do |t|
t.belongs_to :topic
t.string :name, :null => false
t.string :email, :null => false
Expand All @@ -12,6 +12,6 @@ def self.up
end

def self.down
drop_table :messages
drop_table :spree_messages
end
end
9 changes: 6 additions & 3 deletions spree_contact_form.gemspec
@@ -1,10 +1,13 @@
# encoding: UTF-8
version = File.read(File.expand_path("../GEM_VERSION",__FILE__)).strip

Gem::Specification.new do |s|
s.platform = Gem::Platform::RUBY
s.name = 'spree_contact_form'
s.version = '3.0.7'
s.version = version
s.summary = 'Adds a contact form for your spree site'
s.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'
s.required_ruby_version = '>= 1.8.7'
s.required_ruby_version = '>= 1.9.3'

s.author = 'Josh Nussbaum'
s.email = 'joshnuss@gmail.com'
Expand All @@ -17,6 +20,6 @@ Gem::Specification.new do |s|

s.has_rdoc = false

s.add_dependency('spree_core', '>= 0.70.RC1')
s.add_dependency('spree_core', '>= 1.0.0')
end

0 comments on commit 716d202

Please sign in to comment.