enjoy_cms_feedback 0.4.0.beta3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/.travis.yml +4 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +41 -0
- data/Rakefile +1 -0
- data/app/assets/javascripts/enjoy/feedback/form.coffee +9 -0
- data/app/assets/javascripts/enjoy/feedback/init.coffee +2 -0
- data/app/assets/javascripts/enjoy/feedback.coffee +6 -0
- data/app/assets/stylesheets/enjoy/feedback.sass +0 -0
- data/app/controllers/concerns/enjoy/feedback/decorators/contacts.rb +5 -0
- data/app/controllers/enjoy/feedback/contacts_controller.rb +7 -0
- data/app/mailers/enjoy/feedback/contact_mailer.rb +17 -0
- data/app/models/concerns/enjoy/feedback/decorators/contact_message.rb +5 -0
- data/app/models/enjoy/feedback/contact_message.rb +17 -0
- data/app/views/enjoy/feedback/contact_mailer/new_message_email.html.slim +15 -0
- data/app/views/enjoy/feedback/contacts/_form.html.slim +16 -0
- data/app/views/enjoy/feedback/contacts/_form_with_wrapper.html.slim +2 -0
- data/app/views/enjoy/feedback/contacts/_success.html.slim +3 -0
- data/app/views/enjoy/feedback/contacts/index.html.slim +7 -0
- data/app/views/enjoy/feedback/contacts/new.html.slim +7 -0
- data/app/views/enjoy/feedback/contacts/sent.html.slim +3 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/config/initializers/enjoy_feedback.rb +22 -0
- data/config/locales/enjoy.feedback.ru.yml +28 -0
- data/config/locales/ru.simple_captcha.yml +3 -0
- data/config/locales/ru.simple_form.yml +9 -0
- data/enjoy_cms_feedback.gemspec +38 -0
- data/lib/enjoy/feedback/admin/contact_message.rb +42 -0
- data/lib/enjoy/feedback/admin.rb +4 -0
- data/lib/enjoy/feedback/configuration.rb +44 -0
- data/lib/enjoy/feedback/controllers/contacts.rb +108 -0
- data/lib/enjoy/feedback/engine.rb +32 -0
- data/lib/enjoy/feedback/models/active_record/contact_message.rb +13 -0
- data/lib/enjoy/feedback/models/contact_message.rb +43 -0
- data/lib/enjoy/feedback/models/mongoid/contact_message.rb +19 -0
- data/lib/enjoy/feedback/routes.rb +40 -0
- data/lib/enjoy/feedback/version.rb +5 -0
- data/lib/enjoy_cms_feedback.rb +56 -0
- data/lib/generators/enjoy/feedback/config/install_generator.rb +13 -0
- data/lib/generators/enjoy/feedback/config/templates/enjoy_catalog.erb +16 -0
- data/lib/generators/enjoy/feedback/migration_generator.rb +18 -0
- data/lib/generators/enjoy/feedback/templates/migration_contact_messages.erb +17 -0
- data/release.sh +7 -0
- metadata +175 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: b1907eae5d0ecf42f2d1bc83d56e43317db6bfb6
|
4
|
+
data.tar.gz: 62b4a010c00322533902124a3b51666d16f94623
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: cb59038442b10ed14fdc40f5e919969640f6d8f6f3df4ae80121627d85c990a2be5fc4ab105d8dfb277abf36d171d23cc9ad4aa7dcc5290733b3139390e69776
|
7
|
+
data.tar.gz: 460664c9863be150e1f97fcd53024d7819115631eb4a82028842babc673479667535ec7ed9b3036c134f8133c44ceb0ce76f210a6daae498b52440f08b682eca
|
data/.gitignore
ADDED
data/.ruby-gemset
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
enjoy_cms_feedback
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.3.1
|
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 Alexander Kiseliev
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
# EnjoyCmsFeedback
|
2
|
+
|
3
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/enjoy_cms_feedback`. To experiment with that code, run `bin/console` for an interactive prompt.
|
4
|
+
|
5
|
+
TODO: Delete this and the text above, and describe your gem
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'enjoy_cms_feedback'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install enjoy_cms_feedback
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
TODO: Write usage instructions here
|
26
|
+
|
27
|
+
## Development
|
28
|
+
|
29
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake false` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
30
|
+
|
31
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
32
|
+
|
33
|
+
## Contributing
|
34
|
+
|
35
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/enjoy_cms_feedback.
|
36
|
+
|
37
|
+
|
38
|
+
## License
|
39
|
+
|
40
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
41
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,9 @@
|
|
1
|
+
window.enjoy_cms.feedback.create_ajax_form = (form_selector = "#new_enjoy_feedback_contact_message", wrapper_selector = "#enjoy_feedback_contact_form" )->
|
2
|
+
|
3
|
+
$(document).delegate form_selector, "ajax:complete", (event, xhr, status)->
|
4
|
+
$(event.currentTarget).closest(wrapper_selector).html(xhr.responseText)
|
5
|
+
|
6
|
+
$(document).delegate form_selector + " .input", 'click', (e) ->
|
7
|
+
e.preventDefault()
|
8
|
+
$(e.currentTarget).removeClass("field_with_errors").find('span.error').hide()
|
9
|
+
return false
|
File without changes
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Enjoy::Feedback
|
2
|
+
class ContactMailer < ActionMailer::Base
|
3
|
+
def new_message_email(message)
|
4
|
+
@message = message
|
5
|
+
|
6
|
+
#if message.attachment?
|
7
|
+
# attachments[message.attachment.identifier] = File.read(message.attachment.current_path)
|
8
|
+
#end
|
9
|
+
|
10
|
+
mail(
|
11
|
+
from: Settings.default_email_from(default: 'noreply@enjoycreate.ru'),
|
12
|
+
to: Settings.form_email(default: 'admin@enjoycreate.ru'),
|
13
|
+
subject: "[#{Settings.email_topic(default: 'с сайта')}] #{message.name} #{message.email}"
|
14
|
+
)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Enjoy::Feedback
|
2
|
+
if Enjoy::Feedback.active_record?
|
3
|
+
class ContactMessage < ActiveRecord::Base
|
4
|
+
end
|
5
|
+
end
|
6
|
+
|
7
|
+
class ContactMessage
|
8
|
+
|
9
|
+
include Enjoy::Feedback::Models::ContactMessage
|
10
|
+
|
11
|
+
include Enjoy::Feedback::Decorators::ContactMessage
|
12
|
+
|
13
|
+
rails_admin(&Enjoy::Feedback::Admin::ContactMessage.config(rails_admin_add_fields) { |config|
|
14
|
+
rails_admin_add_config(config)
|
15
|
+
})
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
- excluded_column_names = %w[id c_at u_at created_at updated_at _id _type enabled attachment c_at u_at captcha captcha_key veenjoyion creator_id creator updater_id updater modifier modifier_id]
|
2
|
+
|
3
|
+
h3= "Сообщение из формы связи:"
|
4
|
+
|
5
|
+
table
|
6
|
+
tr
|
7
|
+
th(style='padding: 2px 3px') Поле
|
8
|
+
th(style='padding: 2px 3px') Значение
|
9
|
+
- fields = (Enjoy::Feedback.mongoid? ? Enjoy::Feedback::ContactMessage.fields.keys : Enjoy::Feedback::ContactMessage.columns.map(&:name))
|
10
|
+
- fields.reject{|c| excluded_column_names.include?(c) }.each do |c|
|
11
|
+
tr
|
12
|
+
td(style='padding: 2px 3px')
|
13
|
+
= Enjoy::Feedback::ContactMessage.human_attribute_name(c)
|
14
|
+
td(style='padding: 2px 3px')
|
15
|
+
= @message.send(c.to_sym)
|
@@ -0,0 +1,16 @@
|
|
1
|
+
/ = simple_form_for @contact_message, url: enjoy_feedback_contacts_path do |f|
|
2
|
+
= simple_form_for @contact_message, url: enjoy_feedback_contacts_path, html: {data: {remote: true }} do |f|
|
3
|
+
= f.input :name
|
4
|
+
= f.input :email
|
5
|
+
= f.input :phone
|
6
|
+
= f.input :content, as: :text
|
7
|
+
- if Enjoy::Feedback.config.captcha
|
8
|
+
- if Enjoy::Feedback.config.recaptcha_support
|
9
|
+
.input
|
10
|
+
- if @recaptcha_error
|
11
|
+
span.error.recaptcha_error= @recaptcha_error
|
12
|
+
= recaptcha_tags
|
13
|
+
- elsif Enjoy::Feedback.config.simple_captcha_support
|
14
|
+
= f.input :captcha, as: :simple_captcha, label: false
|
15
|
+
|
16
|
+
= f.submit t('enjoy.send')
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "enjoy_cms_feedback"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Enjoy.rails_admin_configure do |config|
|
2
|
+
if defined?(RailsAdminComments)
|
3
|
+
config.action_visible_for :comments, 'Enjoy::Feedback::ContactMessage'
|
4
|
+
config.action_visible_for :model_comments, 'Enjoy::Feedback::ContactMessage'
|
5
|
+
end
|
6
|
+
end
|
7
|
+
|
8
|
+
Enjoy.configure do |config|
|
9
|
+
config.ability_manager_config ||= []
|
10
|
+
config.ability_manager_config << {
|
11
|
+
method: :can,
|
12
|
+
model: Enjoy::Feedback::ContactMessage,
|
13
|
+
actions: [:read]
|
14
|
+
}
|
15
|
+
|
16
|
+
config.ability_admin_config ||= []
|
17
|
+
config.ability_admin_config << {
|
18
|
+
method: :can,
|
19
|
+
model: Enjoy::Feedback::ContactMessage,
|
20
|
+
actions: :manage
|
21
|
+
}
|
22
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
ru:
|
2
|
+
enjoy:
|
3
|
+
feedback: Обратная связь
|
4
|
+
breadcrumbs:
|
5
|
+
feedback: Обратная связь
|
6
|
+
contacts: Контакты
|
7
|
+
errors:
|
8
|
+
feedback:
|
9
|
+
recaptcha: Вы робот?
|
10
|
+
|
11
|
+
mongoid: &mongoid
|
12
|
+
models:
|
13
|
+
enjoy/feedback/contact_message: Сообщение
|
14
|
+
attributes:
|
15
|
+
enjoy/feedback/contact_message:
|
16
|
+
name: Ваше имя
|
17
|
+
email: Ваш е-мейл
|
18
|
+
phone: Ваш телефон
|
19
|
+
content: Ваше сообщение
|
20
|
+
|
21
|
+
errors:
|
22
|
+
models:
|
23
|
+
enjoy/feedback/contact_message:
|
24
|
+
attributes:
|
25
|
+
email:
|
26
|
+
invalid_email_address: "^Неверный e-mail"
|
27
|
+
activerecord:
|
28
|
+
<<: *mongoid
|
@@ -0,0 +1,38 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'enjoy/feedback/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "enjoy_cms_feedback"
|
8
|
+
spec.version = Enjoy::Feedback::VERSION
|
9
|
+
spec.authors = ["Alexander Kiseliev"]
|
10
|
+
spec.email = ["dev@enjoycreate.ru"]
|
11
|
+
|
12
|
+
spec.description = %q{enjoy_cms_feedback }
|
13
|
+
spec.summary = %q{enjoy_cms_feedback}
|
14
|
+
spec.homepage = 'https://github.com/enjoycreative/enjoy_cms_feedback'
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
# Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
|
18
|
+
# delete this section to allow pushing this gem to any host.
|
19
|
+
# if spec.respond_to?(:metadata)
|
20
|
+
# spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'"
|
21
|
+
# else
|
22
|
+
# raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
|
23
|
+
# end
|
24
|
+
|
25
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
26
|
+
spec.bindir = "exe"
|
27
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
28
|
+
spec.require_paths = ["lib"]
|
29
|
+
|
30
|
+
spec.add_development_dependency "bundler", "~> 1.10"
|
31
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
32
|
+
|
33
|
+
spec.add_dependency 'enjoy_cms', "~> 0.4.0.beta3"
|
34
|
+
|
35
|
+
spec.add_dependency 'addressable'
|
36
|
+
spec.add_dependency 'x-real-ip'
|
37
|
+
spec.add_dependency 'validates_email_format_of'
|
38
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
module Enjoy::Feedback
|
2
|
+
module Admin
|
3
|
+
module ContactMessage
|
4
|
+
def self.config(fields = {})
|
5
|
+
Proc.new {
|
6
|
+
navigation_label I18n.t('enjoy.feedback')
|
7
|
+
field :c_at do
|
8
|
+
read_only true
|
9
|
+
end
|
10
|
+
field :name do
|
11
|
+
searchable true
|
12
|
+
end
|
13
|
+
field :content, :text do
|
14
|
+
searchable true
|
15
|
+
end
|
16
|
+
field :email do
|
17
|
+
searchable true
|
18
|
+
end
|
19
|
+
field :phone do
|
20
|
+
searchable true
|
21
|
+
end
|
22
|
+
|
23
|
+
Enjoy::Feedback.config.fields.each_pair do |fn, ft|
|
24
|
+
next if ft.nil?
|
25
|
+
if ft.is_a?(Array)
|
26
|
+
field fn, ft[1].to_sym
|
27
|
+
else
|
28
|
+
field fn
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
Enjoy::RailsAdminGroupPatch::enjoy_cms_group(self, fields)
|
33
|
+
|
34
|
+
if block_given?
|
35
|
+
yield self
|
36
|
+
end
|
37
|
+
|
38
|
+
}
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
module Enjoy::Feedback
|
2
|
+
def self.configuration
|
3
|
+
@configuration ||= Configuration.new
|
4
|
+
end
|
5
|
+
def self.config
|
6
|
+
@configuration ||= Configuration.new
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.configure
|
10
|
+
yield configuration
|
11
|
+
end
|
12
|
+
|
13
|
+
class Configuration
|
14
|
+
attr_accessor :captcha
|
15
|
+
attr_accessor :fields
|
16
|
+
attr_accessor :message_required
|
17
|
+
|
18
|
+
attr_accessor :captcha_error_message
|
19
|
+
attr_accessor :no_contact_info_error_message
|
20
|
+
|
21
|
+
attr_accessor :recreate_contact_message_action
|
22
|
+
|
23
|
+
attr_accessor :breadcrumbs_on_rails_support
|
24
|
+
|
25
|
+
attr_accessor :recaptcha_support
|
26
|
+
attr_accessor :simple_captcha_support
|
27
|
+
|
28
|
+
def initialize
|
29
|
+
@captcha = false
|
30
|
+
@fields = {}
|
31
|
+
@message_required = true
|
32
|
+
|
33
|
+
@captcha_error_message = "Код проверки введен неверно"
|
34
|
+
@no_contact_info_error_message = "Пожалуйста введите Ваш e-mail или телефон, чтобы мы могли связаться с вами."
|
35
|
+
|
36
|
+
@recreate_contact_message_action = "new"
|
37
|
+
|
38
|
+
@breadcrumbs_on_rails_support = defined?(BreadcrumbsOnRails)
|
39
|
+
|
40
|
+
@recaptcha_support = defined?(Recaptcha)
|
41
|
+
@simple_captcha_support = defined?(SimpleCaptcha)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,108 @@
|
|
1
|
+
module Enjoy::Feedback
|
2
|
+
module Controllers
|
3
|
+
module Contacts
|
4
|
+
extend ActiveSupport::Concern
|
5
|
+
|
6
|
+
included do
|
7
|
+
if Enjoy::Feedback.config.breadcrumbs_on_rails_support
|
8
|
+
add_breadcrumb I18n.t('enjoy.breadcrumbs.contacts'), :enjoy_feedback_contacts_path
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
def index
|
13
|
+
@contact_message = model.new
|
14
|
+
after_initialize
|
15
|
+
xhr_checker
|
16
|
+
end
|
17
|
+
|
18
|
+
def new
|
19
|
+
@contact_message = model.new
|
20
|
+
after_initialize
|
21
|
+
xhr_checker
|
22
|
+
end
|
23
|
+
|
24
|
+
def create
|
25
|
+
@contact_message = model.new(message_params)
|
26
|
+
after_initialize
|
27
|
+
|
28
|
+
if Enjoy::Feedback.config.captcha
|
29
|
+
if Enjoy::Feedback.config.recaptcha_support
|
30
|
+
if verify_recaptcha
|
31
|
+
meth = :save
|
32
|
+
else
|
33
|
+
meth = :valid?
|
34
|
+
@recaptcha_error = I18n.t('enjoy.errors.feedback.recaptcha')
|
35
|
+
end
|
36
|
+
|
37
|
+
elsif Enjoy::Feedback.config.simple_captcha_support
|
38
|
+
meth = :save_with_captcha
|
39
|
+
|
40
|
+
else
|
41
|
+
meth = :save
|
42
|
+
end
|
43
|
+
else
|
44
|
+
meth = :save
|
45
|
+
end
|
46
|
+
|
47
|
+
if @contact_message.send(meth)
|
48
|
+
after_create
|
49
|
+
if request.xhr? && process_ajax
|
50
|
+
ajax_success
|
51
|
+
else
|
52
|
+
redirect_after_done
|
53
|
+
end
|
54
|
+
else
|
55
|
+
render_contacts_error
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
def sent
|
60
|
+
end
|
61
|
+
|
62
|
+
private
|
63
|
+
def render_contacts_error
|
64
|
+
if request.xhr? && process_ajax
|
65
|
+
render partial: form_partial, status: 422
|
66
|
+
# render json: {errors: @contact_message.errors}, status: 422
|
67
|
+
else
|
68
|
+
flash.now[:alert] = @contact_message.errors.full_messages.join("\n")
|
69
|
+
render action: Enjoy::Feedback.configuration.recreate_contact_message_action, status: 422
|
70
|
+
end
|
71
|
+
end
|
72
|
+
def process_ajax
|
73
|
+
true
|
74
|
+
end
|
75
|
+
def ajax_success
|
76
|
+
render partial: success_partial
|
77
|
+
# render json: {ok: true}
|
78
|
+
end
|
79
|
+
def redirect_after_done
|
80
|
+
redirect_to action: :sent
|
81
|
+
end
|
82
|
+
def xhr_checker
|
83
|
+
if request.xhr?
|
84
|
+
render layout: false
|
85
|
+
end
|
86
|
+
end
|
87
|
+
def after_initialize
|
88
|
+
end
|
89
|
+
def after_create
|
90
|
+
# overrideable hook for updating message
|
91
|
+
end
|
92
|
+
def form_partial
|
93
|
+
"enjoy/feedback/contacts/form"
|
94
|
+
end
|
95
|
+
def success_partial
|
96
|
+
"enjoy/feedback/contacts/success"
|
97
|
+
end
|
98
|
+
def model
|
99
|
+
Enjoy::Feedback::ContactMessage
|
100
|
+
end
|
101
|
+
def message_params
|
102
|
+
params.require(model.to_param.gsub("::", "").underscore).permit(
|
103
|
+
Enjoy::Feedback.config.fields.keys + [:name, :email, :phone, :content, :captcha, :captcha_key]
|
104
|
+
)
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module Enjoy::Feedback
|
2
|
+
class Engine < ::Rails::Engine
|
3
|
+
# isolate_namespace Enjoy::Feedback
|
4
|
+
|
5
|
+
# rake_tasks do
|
6
|
+
# require File.expand_path('../tasks', __FILE__)
|
7
|
+
# end
|
8
|
+
|
9
|
+
initializer "enjoy_cms_feedback.email_defaults" do
|
10
|
+
# Write default email settings to DB so they can be changed.
|
11
|
+
|
12
|
+
#temp
|
13
|
+
begin
|
14
|
+
if Settings and Settings.table_exists?
|
15
|
+
Settings.default_email_from(default: 'noreply@site.domain')
|
16
|
+
Settings.form_email(default: 'admin@site.domain')
|
17
|
+
Settings.email_topic(default: 'с сайта')
|
18
|
+
end
|
19
|
+
rescue
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
config.after_initialize do
|
24
|
+
# Write default email settings to DB so they can be changed.
|
25
|
+
if Settings and Settings.table_exists?
|
26
|
+
Settings.default_email_from(default: 'noreply@site.domain')
|
27
|
+
Settings.form_email(default: 'admin@site.domain')
|
28
|
+
Settings.email_topic(default: 'с сайта')
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
module Enjoy::Feedback
|
2
|
+
module Models
|
3
|
+
module ContactMessage
|
4
|
+
extend ActiveSupport::Concern
|
5
|
+
include Enjoy::Model
|
6
|
+
|
7
|
+
include Enjoy::Feedback.orm_specific('ContactMessage')
|
8
|
+
|
9
|
+
included do
|
10
|
+
if Enjoy::Feedback.config.simple_captcha_support
|
11
|
+
include SimpleCaptcha::ModelHelpers
|
12
|
+
apply_simple_captcha message: Enjoy::Feedback.configuration.captcha_error_message
|
13
|
+
end
|
14
|
+
|
15
|
+
validates_email_format_of :email, unless: 'email.blank?'
|
16
|
+
if Enjoy::Feedback.config.message_required
|
17
|
+
validates_presence_of :content
|
18
|
+
end
|
19
|
+
validate do
|
20
|
+
if email.blank? && phone.blank?
|
21
|
+
errors.add(:email, Enjoy::Feedback.configuration.no_contact_info_error_message)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
after_create do
|
26
|
+
mailer_class.send(mailer_method, self).deliver_now if send_emails?
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def send_emails?
|
31
|
+
true
|
32
|
+
end
|
33
|
+
|
34
|
+
def mailer_class
|
35
|
+
Enjoy::Feedback::ContactMailer
|
36
|
+
end
|
37
|
+
|
38
|
+
def mailer_method
|
39
|
+
:new_message_email
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Enjoy::Feedback
|
2
|
+
module Models
|
3
|
+
module Mongoid
|
4
|
+
module ContactMessage
|
5
|
+
extend ActiveSupport::Concern
|
6
|
+
included do
|
7
|
+
field :name, type: String
|
8
|
+
field :email, type: String
|
9
|
+
field :phone, type: String
|
10
|
+
field :content, type: String
|
11
|
+
Enjoy::Feedback.config.fields.each_pair do |fn, ft|
|
12
|
+
next if ft.nil?
|
13
|
+
field fn, type: ft
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
module ActionDispatch::Routing
|
2
|
+
class Mapper
|
3
|
+
|
4
|
+
def enjoy_cms_feedback_routes(config = {})
|
5
|
+
routes_config = {
|
6
|
+
use_contacts_path: true,
|
7
|
+
contacts_path: 'contacts',
|
8
|
+
classes: {
|
9
|
+
contacts: :contacts
|
10
|
+
}
|
11
|
+
}
|
12
|
+
routes_config.deep_merge!(config)
|
13
|
+
|
14
|
+
generate_enjoy_feedback_user_routes(routes_config)
|
15
|
+
generate_enjoy_feedback_cms_routes(routes_config)
|
16
|
+
end
|
17
|
+
|
18
|
+
|
19
|
+
private
|
20
|
+
def generate_enjoy_feedback_user_routes(routes_config)
|
21
|
+
if !routes_config[:use_contacts_path] and !routes_config[:classes][:contacts].nil?
|
22
|
+
get "#{routes_config[:contacts_path]}" => "#{routes_config[:classes][:contacts]}#new"
|
23
|
+
post "#{routes_config[:contacts_path]}" => "#{routes_config[:classes][:contacts]}#create"
|
24
|
+
get "#{routes_config[:contacts_path]}/sent" => "#{routes_config[:classes][:contacts]}#sent"
|
25
|
+
end
|
26
|
+
end
|
27
|
+
def generate_enjoy_feedback_cms_routes(routes_config)
|
28
|
+
scope module: 'enjoy' do
|
29
|
+
scope module: 'feedback' do
|
30
|
+
if routes_config[:use_contacts_path]
|
31
|
+
get "#{routes_config[:contacts_path]}" => "#{routes_config[:classes][:contacts]}#new", as: :enjoy_feedback_contacts
|
32
|
+
post "#{routes_config[:contacts_path]}" => "#{routes_config[:classes][:contacts]}#create", as: :create_enjoy_feedback_contacts
|
33
|
+
get "#{routes_config[:contacts_path]}/sent" => "#{routes_config[:classes][:contacts]}#sent", as: :enjoy_feedback_contacts_sent
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
unless defined?(Enjoy) && Enjoy.respond_to?(:orm) && [:active_record, :mongoid].include?(Enjoy.orm)
|
2
|
+
puts "please use enjoy_cms_mongoid or enjoy_cms_activerecord"
|
3
|
+
puts "also: please use enjoy_cms_news_mongoid or enjoy_cms_news_activerecord and not enjoy_cms_news directly"
|
4
|
+
exit 1
|
5
|
+
end
|
6
|
+
|
7
|
+
require "enjoy/feedback/version"
|
8
|
+
|
9
|
+
require 'enjoy/feedback/configuration'
|
10
|
+
require 'enjoy/feedback/engine'
|
11
|
+
require 'enjoy/feedback/routes'
|
12
|
+
|
13
|
+
require 'addressable/uri'
|
14
|
+
require 'validates_email_format_of'
|
15
|
+
require 'x-real-ip'
|
16
|
+
|
17
|
+
module Enjoy::Feedback
|
18
|
+
class << self
|
19
|
+
def orm
|
20
|
+
Enjoy.orm
|
21
|
+
end
|
22
|
+
def mongoid?
|
23
|
+
Enjoy::Feedback.orm == :mongoid
|
24
|
+
end
|
25
|
+
def active_record?
|
26
|
+
Enjoy::Feedback.orm == :active_record
|
27
|
+
end
|
28
|
+
def model_namespace
|
29
|
+
"Enjoy::Feedback::Models::#{Enjoy::Feedback.orm.to_s.camelize}"
|
30
|
+
end
|
31
|
+
def orm_specific(name)
|
32
|
+
"#{model_namespace}::#{name}".constantize
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
autoload :Admin, 'enjoy/feedback/admin'
|
37
|
+
module Admin
|
38
|
+
autoload :ContactMessage, 'enjoy/feedback/admin/contact_message'
|
39
|
+
end
|
40
|
+
|
41
|
+
module Models
|
42
|
+
autoload :ContactMessage, 'enjoy/feedback/models/contact_message'
|
43
|
+
|
44
|
+
module Mongoid
|
45
|
+
autoload :ContactMessage, 'enjoy/feedback/models/mongoid/contact_message'
|
46
|
+
end
|
47
|
+
module ActiveRecord
|
48
|
+
autoload :ContactMessage, 'enjoy/feedback/models/active_record/contact_message'
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
module Controllers
|
53
|
+
autoload :Contacts, 'enjoy/feedback/controllers/contacts'
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'rails/generators'
|
2
|
+
|
3
|
+
module Enjoy::Feedback
|
4
|
+
class ConfigGenerator < Rails::Generators::Base
|
5
|
+
source_root File.expand_path('../templates', __FILE__)
|
6
|
+
|
7
|
+
desc 'Enjoy::Feedback Config generator'
|
8
|
+
def config
|
9
|
+
template 'enjoy_feedback.erb', "config/initializers/enjoy_feedback.rb"
|
10
|
+
end
|
11
|
+
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
Enjoy::Feedback.configure do |config|
|
2
|
+
##### defaults #####
|
3
|
+
# config.captcha = false
|
4
|
+
# config.fields = {}
|
5
|
+
# config.message_required = true
|
6
|
+
|
7
|
+
# config.captcha_error_message = "Код проверки введен неверно"
|
8
|
+
# config.no_contact_info_error_message = "Пожалуйста введите Ваш e-mail или телефон, чтобы мы могли связаться с вами."
|
9
|
+
|
10
|
+
# config.recreate_contact_message_action = "new"
|
11
|
+
|
12
|
+
# config.breadcrumbs_on_rails_support = defined?(BreadcrumbsOnRails)
|
13
|
+
|
14
|
+
# config.recaptcha_support = defined?(Recaptcha)
|
15
|
+
# config.simple_captcha_support = defined?(SimpleCaptcha)
|
16
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'rails/generators'
|
2
|
+
require 'rails/generators/active_record'
|
3
|
+
|
4
|
+
module Enjoy::Feedback
|
5
|
+
class MigrationGenerator < Rails::Generators::Base
|
6
|
+
include ActiveRecord::Generators::Migration
|
7
|
+
source_root File.expand_path('../templates', __FILE__)
|
8
|
+
|
9
|
+
desc 'Enjoy Feedback migration generator'
|
10
|
+
def install
|
11
|
+
if Enjoy::Feedback.active_record?
|
12
|
+
%w(contact_messages).each do |table_name|
|
13
|
+
migration_template "migration_#{table_name}.rb", "db/migrate/enjoy_feedback_create_#{table_name}.rb"
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
class EnjoyFeedbackCreateContactMessages < ActiveRecord::Migration
|
2
|
+
def change
|
3
|
+
create_table :enjoy_feedback_contact_messages do |t|
|
4
|
+
t.string :name
|
5
|
+
t.string :email
|
6
|
+
t.string :phone
|
7
|
+
t.text :content
|
8
|
+
<% Enjoy::Feedback.config.fields.each_pair do |name, type| %>
|
9
|
+
t.<%= type %> :<%= name %>
|
10
|
+
<% end %>
|
11
|
+
t.timestamps
|
12
|
+
end
|
13
|
+
|
14
|
+
add_index :enjoy_feedback_contact_messages, :created_at
|
15
|
+
add_index :enjoy_feedback_contact_messages, :updated_at
|
16
|
+
end
|
17
|
+
end
|
data/release.sh
ADDED
metadata
ADDED
@@ -0,0 +1,175 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: enjoy_cms_feedback
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.4.0.beta3
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Alexander Kiseliev
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-07-04 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.10'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.10'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: enjoy_cms
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 0.4.0.beta3
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 0.4.0.beta3
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: addressable
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: x-real-ip
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: validates_email_format_of
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
description: 'enjoy_cms_feedback '
|
98
|
+
email:
|
99
|
+
- dev@enjoycreate.ru
|
100
|
+
executables: []
|
101
|
+
extensions: []
|
102
|
+
extra_rdoc_files: []
|
103
|
+
files:
|
104
|
+
- ".gitignore"
|
105
|
+
- ".ruby-gemset"
|
106
|
+
- ".ruby-version"
|
107
|
+
- ".travis.yml"
|
108
|
+
- Gemfile
|
109
|
+
- LICENSE.txt
|
110
|
+
- README.md
|
111
|
+
- Rakefile
|
112
|
+
- app/assets/javascripts/enjoy/feedback.coffee
|
113
|
+
- app/assets/javascripts/enjoy/feedback/form.coffee
|
114
|
+
- app/assets/javascripts/enjoy/feedback/init.coffee
|
115
|
+
- app/assets/stylesheets/enjoy/feedback.sass
|
116
|
+
- app/controllers/concerns/enjoy/feedback/decorators/contacts.rb
|
117
|
+
- app/controllers/enjoy/feedback/contacts_controller.rb
|
118
|
+
- app/mailers/enjoy/feedback/contact_mailer.rb
|
119
|
+
- app/models/concerns/enjoy/feedback/decorators/contact_message.rb
|
120
|
+
- app/models/enjoy/feedback/contact_message.rb
|
121
|
+
- app/views/enjoy/feedback/contact_mailer/new_message_email.html.slim
|
122
|
+
- app/views/enjoy/feedback/contacts/_form.html.slim
|
123
|
+
- app/views/enjoy/feedback/contacts/_form_with_wrapper.html.slim
|
124
|
+
- app/views/enjoy/feedback/contacts/_success.html.slim
|
125
|
+
- app/views/enjoy/feedback/contacts/index.html.slim
|
126
|
+
- app/views/enjoy/feedback/contacts/new.html.slim
|
127
|
+
- app/views/enjoy/feedback/contacts/sent.html.slim
|
128
|
+
- bin/console
|
129
|
+
- bin/setup
|
130
|
+
- config/initializers/enjoy_feedback.rb
|
131
|
+
- config/locales/enjoy.feedback.ru.yml
|
132
|
+
- config/locales/ru.simple_captcha.yml
|
133
|
+
- config/locales/ru.simple_form.yml
|
134
|
+
- enjoy_cms_feedback.gemspec
|
135
|
+
- lib/enjoy/feedback/admin.rb
|
136
|
+
- lib/enjoy/feedback/admin/contact_message.rb
|
137
|
+
- lib/enjoy/feedback/configuration.rb
|
138
|
+
- lib/enjoy/feedback/controllers/contacts.rb
|
139
|
+
- lib/enjoy/feedback/engine.rb
|
140
|
+
- lib/enjoy/feedback/models/active_record/contact_message.rb
|
141
|
+
- lib/enjoy/feedback/models/contact_message.rb
|
142
|
+
- lib/enjoy/feedback/models/mongoid/contact_message.rb
|
143
|
+
- lib/enjoy/feedback/routes.rb
|
144
|
+
- lib/enjoy/feedback/version.rb
|
145
|
+
- lib/enjoy_cms_feedback.rb
|
146
|
+
- lib/generators/enjoy/feedback/config/install_generator.rb
|
147
|
+
- lib/generators/enjoy/feedback/config/templates/enjoy_catalog.erb
|
148
|
+
- lib/generators/enjoy/feedback/migration_generator.rb
|
149
|
+
- lib/generators/enjoy/feedback/templates/migration_contact_messages.erb
|
150
|
+
- release.sh
|
151
|
+
homepage: https://github.com/enjoycreative/enjoy_cms_feedback
|
152
|
+
licenses:
|
153
|
+
- MIT
|
154
|
+
metadata: {}
|
155
|
+
post_install_message:
|
156
|
+
rdoc_options: []
|
157
|
+
require_paths:
|
158
|
+
- lib
|
159
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
160
|
+
requirements:
|
161
|
+
- - ">="
|
162
|
+
- !ruby/object:Gem::Version
|
163
|
+
version: '0'
|
164
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
165
|
+
requirements:
|
166
|
+
- - ">"
|
167
|
+
- !ruby/object:Gem::Version
|
168
|
+
version: 1.3.1
|
169
|
+
requirements: []
|
170
|
+
rubyforge_project:
|
171
|
+
rubygems_version: 2.5.1
|
172
|
+
signing_key:
|
173
|
+
specification_version: 4
|
174
|
+
summary: enjoy_cms_feedback
|
175
|
+
test_files: []
|