hancock_cms_feedback 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (55) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +9 -0
  3. data/.ruby-gemset +1 -0
  4. data/.ruby-version +1 -0
  5. data/.travis.yml +4 -0
  6. data/Gemfile +4 -0
  7. data/LICENSE.txt +21 -0
  8. data/README.md +60 -0
  9. data/Rakefile +1 -0
  10. data/app/assets/javascripts/hancock/feedback.coffee +8 -0
  11. data/app/assets/javascripts/hancock/feedback/form.coffee +77 -0
  12. data/app/assets/javascripts/hancock/feedback/init.coffee +2 -0
  13. data/app/assets/stylesheets/hancock/feedback.sass +0 -0
  14. data/app/controllers/concerns/hancock/feedback/decorators/contacts.rb +84 -0
  15. data/app/controllers/hancock/feedback/contacts_controller.rb +7 -0
  16. data/app/mailers/hancock/feedback/contact_mailer.rb +17 -0
  17. data/app/models/concerns/hancock/feedback/decorators/contact_message.rb +44 -0
  18. data/app/models/hancock/feedback/contact_message.rb +17 -0
  19. data/app/views/hancock/feedback/contact_mailer/new_message_email.html.slim +15 -0
  20. data/app/views/hancock/feedback/contacts/_fields.html.slim +18 -0
  21. data/app/views/hancock/feedback/contacts/_fields_with_settings.html.slim +24 -0
  22. data/app/views/hancock/feedback/contacts/_form.html.slim +37 -0
  23. data/app/views/hancock/feedback/contacts/_form_with_wrapper.html.slim +2 -0
  24. data/app/views/hancock/feedback/contacts/_simple_captcha.html.slim +17 -0
  25. data/app/views/hancock/feedback/contacts/_success.html.slim +4 -0
  26. data/app/views/hancock/feedback/contacts/index.html.slim +8 -0
  27. data/app/views/hancock/feedback/contacts/new.html.slim +8 -0
  28. data/app/views/hancock/feedback/contacts/sent.html.slim +3 -0
  29. data/app/views/hancock/feedback/contacts/update_captcha.html.slim +21 -0
  30. data/bin/console +15 -0
  31. data/bin/setup +7 -0
  32. data/config/locales/hancock.feedback.ru.yml +56 -0
  33. data/config/locales/ru.simple_captcha.yml +3 -0
  34. data/config/locales/ru.simple_form.yml +9 -0
  35. data/hancock_cms_feedback.gemspec +39 -0
  36. data/lib/generators/hancock/feedback/config/config_generator.rb +13 -0
  37. data/lib/generators/hancock/feedback/config/templates/hancock_feedback.erb +19 -0
  38. data/lib/generators/hancock/feedback/controllers/decorators_generator.rb +24 -0
  39. data/lib/generators/hancock/feedback/controllers/templates/contacts.erb +145 -0
  40. data/lib/generators/hancock/feedback/controllers/transfers_generator.rb +39 -0
  41. data/lib/generators/hancock/feedback/migrations/migrations_generator.rb +18 -0
  42. data/lib/generators/hancock/feedback/migrations/templates/migration_contact_messages.erb +17 -0
  43. data/lib/hancock/feedback/admin.rb +6 -0
  44. data/lib/hancock/feedback/admin/contact_message.rb +40 -0
  45. data/lib/hancock/feedback/configuration.rb +51 -0
  46. data/lib/hancock/feedback/controllers/contacts.rb +154 -0
  47. data/lib/hancock/feedback/engine.rb +36 -0
  48. data/lib/hancock/feedback/models/active_record/contact_message.rb +13 -0
  49. data/lib/hancock/feedback/models/contact_message.rb +92 -0
  50. data/lib/hancock/feedback/models/mongoid/contact_message.rb +35 -0
  51. data/lib/hancock/feedback/routes.rb +42 -0
  52. data/lib/hancock/feedback/version.rb +5 -0
  53. data/lib/hancock_cms_feedback.rb +34 -0
  54. data/release.sh +6 -0
  55. metadata +187 -0
@@ -0,0 +1,37 @@
1
+ ruby:
2
+ is_cache_fields ||= ['new', 'index'].include? action_name
3
+ cache_key ||= 'hancock_feedback_contacts_fields'.freeze
4
+ if Hancock::Feedback.config.model_settings_support
5
+ settings_scope ||= Hancock::Feedback::ContactMessage.settings
6
+ elsif defined?(Settings)
7
+ settings_scope ||= Settings.ns('feedback')
8
+ end
9
+ fields_partial ||= "hancock/feedback/contacts/#{(Hancock::Feedback.config.model_settings_support ? 'fields_with_settings' : 'fields')}".freeze
10
+ recaptcha_options ||= {}
11
+ _cache_helper = (Hancock::Feedback.config.cache_support ? :hancock_cache : :cache)
12
+ autofocus_field ||= :name
13
+ @contact_message ||= Hancock::Feedback::ContactMessage.new
14
+
15
+ / = simple_form_for @contact_message, url: hancock_feedback_contacts_path do |f|
16
+ = simple_form_for @contact_message, url: hancock_feedback_contacts_path, html: {data: {remote: true }} do |f|
17
+ - if is_cache_fields
18
+ - send _cache_helper, cache_key do
19
+ = render partial: fields_partial, locals: {f: f, cache_key: "views/#{cache_key}", settings_scope: settings_scope, autofocus_field: autofocus_field}
20
+ - else
21
+ = render partial: fields_partial, locals: {f: f, settings_scope: settings_scope, autofocus_field: autofocus_field}
22
+
23
+ - if Hancock::Feedback.config.captcha
24
+ - if Hancock::Feedback.config.recaptcha_support
25
+ .input
26
+ - if @recaptcha_error
27
+ span.error.recaptcha_error= @recaptcha_error
28
+ = recaptcha_tags(recaptcha_options)
29
+ - elsif Hancock::Feedback.config.simple_captcha_support
30
+ = render partial: "hancock/feedback/contacts/simple_captcha", locals: {f: f, settings_scope: settings_scope}
31
+
32
+ - if Hancock::Feedback.config.model_settings_support
33
+ - label = settings_scope.submit_label(default: t('hancock.send'), label: "Текст на кнопке отправки")
34
+ - else
35
+ - label = t('hancock.send')
36
+ .submit_button_wrapper
37
+ = f.submit label, class: 'submit_button'
@@ -0,0 +1,2 @@
1
+ #hancock_cms_feedback_form
2
+ = render partial: "hancock/feedback/contacts/form"
@@ -0,0 +1,17 @@
1
+ ruby:
2
+ if Hancock::Feedback.config.model_settings_support
3
+ settings_scope ||= Hancock::Feedback::ContactMessage.settings
4
+ elsif defined?(Settings)
5
+ settings_scope ||= Settings.ns('feedback')
6
+ end
7
+
8
+ - label = t('hancock.feedback_plugin.fields.captcha.label')
9
+ - placeholder = t('hancock.feedback_plugin.fields.captcha.placeholder')
10
+ - update_captcha_text = t('hancock.feedback_plugin.fields.captcha.update')
11
+ - update_captcha = link_to update_captcha_text, hancock_feedback_update_captcha_path, class: 'update_captcha_link'
12
+ - if Hancock::Feedback.config.model_settings_support
13
+ - label = settings_scope.simple_captcha_label(default: label, label: "Заголовок поля Код проверки")
14
+ - placeholder = settings_scope.simple_captcha_placeholder(default: placeholder, label: "Placeholder поля Код проверки")
15
+ = f.input :captcha, as: :simple_captcha, label: label, input_html: {placeholder: placeholder, update_captcha: update_captcha}, required: true
16
+ - else
17
+ = f.input :captcha, as: :simple_captcha, label: label, input_html: {placeholder: placeholder, update_captcha: update_captcha}, required: true
@@ -0,0 +1,4 @@
1
+ #hancock_cms_feedback_success
2
+ h2 Ваше сообщение отправлено
3
+ div Если оно требует ответа, мы постараемся ответить в ближайшее время
4
+ div= link_to 'Оставить еще одно сообщение', hancock_feedback_contacts_path, class: 'reload_feedback_form_link'
@@ -0,0 +1,8 @@
1
+ / - if Hancock::Feedback.config.breadcrumbs_on_rails_support
2
+ / = render partial: "blocks/breadcrumbs"
3
+
4
+ - _partial_path = (Hancock::Feedback.config.seo_support ? 'shared/obj_with_seo' : 'shared/obj')
5
+ = render _partial_path, obj: (@seo_page || @seo_parent_page)
6
+
7
+ #hancock_feedback_contact_form
8
+ = render partial: "hancock/feedback/contacts/form"
@@ -0,0 +1,8 @@
1
+ / - if Hancock::Feedback.config.breadcrumbs_on_rails_support
2
+ / = render partial: "blocks/breadcrumbs"
3
+
4
+ - _partial_path = (Hancock::Feedback.config.seo_support ? 'shared/obj_with_seo' : 'shared/obj')
5
+ = render _partial_path, obj: (@seo_page || @seo_parent_page)
6
+
7
+ #hancock_feedback_contact_form
8
+ = render partial: "hancock/feedback/contacts/form"
@@ -0,0 +1,3 @@
1
+ #hancock_cms_feedback_sent
2
+ h1 Обратная связь
3
+ = render partial: "hancock/feedback/contacts/success"
@@ -0,0 +1,21 @@
1
+ .input.simple_captcha.required.hancock_feedback_contact_message_captcha
2
+ - if Hancock::Feedback.config.captcha and Hancock::Feedback.config.simple_captcha_support
3
+ ruby:
4
+ if Hancock::Feedback.config.model_settings_support
5
+ settings_scope ||= Hancock::Feedback::ContactMessage.settings
6
+ elsif defined?(Settings)
7
+ settings_scope ||= Settings.ns('feedback')
8
+ end
9
+ options = {
10
+ label: t('hancock.feedback_plugin.fields.captcha.label'),
11
+ placeholder: t('hancock.feedback_plugin.fields.captcha.placeholder'),
12
+ update_captcha: link_to(' (обн)', hancock_feedback_update_captcha_path, class: 'update_captcha_link'),
13
+ object: Hancock::Feedback::ContactMessage.new
14
+ }
15
+
16
+ - if Hancock::Feedback.config.model_settings_support
17
+ - options[:label] = settings_scope.simple_captcha_label(default: options[:label], label: "Заголовок поля Код проверки")
18
+ - options[:placeholder] = settings_scope.simple_captcha_placeholder(default: options[:placeholder], label: "Placeholder поля Код проверки")
19
+ = show_simple_captcha options
20
+ - else
21
+ = show_simple_captcha options
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "hancock
5
+ _cms_feedback"
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require "pry"
12
+ # Pry.start
13
+
14
+ require "irb"
15
+ IRB.start
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,56 @@
1
+ ru:
2
+ hancock:
3
+ feedback: Обратная связь
4
+ breadcrumbs:
5
+ feedback: Обратная связь
6
+ contacts: Контакты
7
+ errors:
8
+ feedback:
9
+ recaptcha: Вы робот?
10
+
11
+ feedback_plugin:
12
+ fields:
13
+ name:
14
+ label: 'ФИО'
15
+ placeholder: 'ФИО'
16
+ email:
17
+ label: E-mail
18
+ placeholder: E-mail
19
+ phone:
20
+ label: Телефон
21
+ placeholder: Телефон
22
+ content:
23
+ label: Сообщение
24
+ placeholder: Сообщение
25
+ captcha:
26
+ label: "Введите код с картинки"
27
+ placeholder: "Введите код с картинки"
28
+ update: ""
29
+
30
+
31
+ mongoid: &mongoid
32
+ models:
33
+ hancock/feedback/contact_message: Сообщение
34
+ attributes:
35
+ hancock/feedback/contact_message:
36
+ c_at: Время создания
37
+ name: Ваше имя
38
+ email: Ваш е-мейл
39
+ phone: Ваш телефон
40
+ content: Ваше сообщение
41
+
42
+ errors:
43
+ models:
44
+ hancock/feedback/contact_message:
45
+ attributes:
46
+ email:
47
+ invalid_email_address: "^Неверный e-mail"
48
+ activerecord:
49
+ <<: *mongoid
50
+
51
+
52
+
53
+ admin:
54
+ scopes:
55
+ rails_admin_settings~setting:
56
+ ns_rails_admin_model_settings_hancock_feedback_contact_message: 'Обратная связь'
@@ -0,0 +1,3 @@
1
+ ru:
2
+ simple_captcha:
3
+ label: "Введите код с картинки"
@@ -0,0 +1,9 @@
1
+ ru:
2
+ simple_form:
3
+ "yes": 'Да'
4
+ "no": 'Нет'
5
+ required:
6
+ text: 'Обязательное поле'
7
+ mark: '*'
8
+ error_notification:
9
+ default_message: "Пожалуйста, исправьте неточности в заполнении полей"
@@ -0,0 +1,39 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'hancock/feedback/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "hancock_cms_feedback"
8
+ spec.version = Hancock::Feedback::VERSION
9
+ spec.authors = ["Alexander Kiseliev"]
10
+ spec.email = ["dev@redrocks.pro"]
11
+
12
+ spec.description = %q{hancock_cms_feedback }
13
+ spec.summary = %q{hancock_cms_feedback}
14
+ spec.homepage = 'https://github.com/red-rocks/hancock_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 'hancock_cms', [">=1.0.2", "<2.1.x"]
34
+ # spec.add_dependency 'hancock_cms', ["~> 1.0.2", "~> 2.0"]
35
+
36
+ spec.add_dependency 'addressable'
37
+ spec.add_dependency 'x-real-ip'
38
+ spec.add_dependency 'validates_email_format_of'
39
+ end
@@ -0,0 +1,13 @@
1
+ require 'rails/generators'
2
+
3
+ module Hancock::Feedback
4
+ class ConfigGenerator < Rails::Generators::Base
5
+ source_root File.expand_path('../templates', __FILE__)
6
+
7
+ desc 'Hancock::Feedback Config generator'
8
+ def config
9
+ template 'hancock_feedback.erb', "config/initializers/hancock_feedback.rb"
10
+ end
11
+
12
+ end
13
+ end
@@ -0,0 +1,19 @@
1
+ Hancock::Feedback.configure do |config|
2
+ ##### defaults #####
3
+ # config.recaptcha_support = !!defined?(Recaptcha)
4
+ # config.simple_captcha_support = !!defined?(SimpleCaptcha)
5
+ #
6
+ # config.captcha = # config.recaptcha_support || # config.simple_captcha_support
7
+ # config.message_required = true
8
+ #
9
+ # config.captcha_error_message = "Код проверки введен неверно"
10
+ # config.no_contact_info_error_message = "Пожалуйста введите Ваш e-mail или телефон, чтобы мы могли связаться с вами."
11
+ #
12
+ # config.recreate_contact_message_action = "new"
13
+ #
14
+ # config.breadcrumbs_on_rails_support = !!defined?(BreadcrumbsOnRails)
15
+ #
16
+ # config.model_settings_support = !!defined?(RailsAdminModelSettings)
17
+ # config.user_abilities_support = !!defined?(RailsAdminUserAbilities)
18
+ # config.ra_comments_support = !!defined?(RailsAdminComments)
19
+ end
@@ -0,0 +1,24 @@
1
+ require 'rails/generators'
2
+
3
+ module Hancock::Feedback::Controllers
4
+ class DecoratorsGenerator < Rails::Generators::Base
5
+ source_root File.expand_path('../../../../../../app/controllers/concerns/hancock/feedback/decorators', __FILE__)
6
+ argument :controllers, type: :array, default: []
7
+
8
+ desc 'Hancock::Feedback Controllers decorators generator'
9
+ def decorators
10
+ copied = false
11
+ (controllers == ['all'] ? permitted_controllers : controllers & permitted_controllers).each do |m|
12
+ copied = true
13
+ copy_file "#{m}.rb", "app/controllers/concerns/hancock/feedback/decorators/#{m}.rb"
14
+ end
15
+ puts "U need to set controllers`s name. One of this: #{permitted_controllers.join(", ")}." unless copied
16
+ end
17
+
18
+ private
19
+ def permitted_controllers
20
+ ['contacts']
21
+ end
22
+
23
+ end
24
+ end
@@ -0,0 +1,145 @@
1
+ class <%= camelcased_class_name %> < Hancock::Feddback::ContactsController
2
+
3
+ # # if Hancock::Feedback.config.breadcrumbs_on_rails_support
4
+ # # add_breadcrumb I18n.t('hancock.breadcrumbs.contacts'), :hancock_feedback_contacts_path
5
+ # # end
6
+ #
7
+ # def index
8
+ # @contact_message = model.new
9
+ # after_initialize
10
+ # render locals: locals unless xhr_checker
11
+ # end
12
+ #
13
+ # def new
14
+ # @contact_message = model.new
15
+ # after_initialize
16
+ # render locals: locals unless xhr_checker
17
+ # end
18
+ #
19
+ # def create
20
+ # @contact_message = model.new(message_params)
21
+ # after_initialize
22
+ #
23
+ # if Hancock::Feedback.config.captcha
24
+ # if Hancock::Feedback.config.recaptcha_support
25
+ # if verify_recaptcha
26
+ # meth = :save
27
+ # else
28
+ # meth = :valid?
29
+ # @recaptcha_error = I18n.t('hancock.errors.feedback.recaptcha')
30
+ # end
31
+ #
32
+ # elsif Hancock::Feedback.config.simple_captcha_support
33
+ # meth = :save_with_captcha
34
+ #
35
+ # else
36
+ # meth = :save
37
+ # end
38
+ # else
39
+ # meth = :save
40
+ # end
41
+ #
42
+ # if @contact_message.send(meth) and @recaptcha_error.blank?
43
+ # after_create
44
+ # if request.xhr? && process_ajax
45
+ # ajax_success
46
+ # else
47
+ # redirect_after_done
48
+ # end
49
+ # else
50
+ # render_contacts_error
51
+ # end
52
+ # end
53
+ #
54
+ # def sent
55
+ # end
56
+ #
57
+ # def update_captcha
58
+ # render layout: false
59
+ # end
60
+ #
61
+ #
62
+ # def hancock_feedback_update_captcha_path
63
+ # url_for(action: :update_captcha, time: Time.new.to_i, only_path: true)
64
+ # end
65
+ # def is_cache_fields
66
+ # cache_fields?
67
+ # end
68
+ # def cache_fields?
69
+ # ['new', 'index'].include? action_name
70
+ # end
71
+ # def cache_key
72
+ # 'hancock_feedback_contacts_fields'.freeze
73
+ # end
74
+ # def fields_partial
75
+ # "hancock/feedback/contacts/#{(Hancock::Feedback.config.model_settings_support ? 'fields_with_settings' : 'fields')}".freeze
76
+ # end
77
+ # def settings_scope
78
+ # if Hancock::Feedback.config.model_settings_support
79
+ # model.settings
80
+ # elsif defined?(Settings)
81
+ # Settings.ns('feedback')
82
+ # else
83
+ # nil
84
+ # end
85
+ # end
86
+ # def recaptcha_options
87
+ # {}
88
+ # end
89
+ # def locals
90
+ # {
91
+ # is_cache_fields: is_cache_fields,
92
+ # cache_key: cache_key,
93
+ # fields_partial: fields_partial,
94
+ # settings_scope: settings_scope,
95
+ # recaptcha_options: recaptcha_options
96
+ # }
97
+ # end
98
+ #
99
+ # private
100
+ # def render_contacts_error
101
+ # if request.xhr? && process_ajax
102
+ # render partial: form_partial, status: 422
103
+ # # render json: {errors: @contact_message.errors}, status: 422
104
+ # else
105
+ # flash.now[:alert] = @contact_message.errors.full_messages.join("\n")
106
+ # render action: Hancock::Feedback.configuration.recreate_contact_message_action, status: 422
107
+ # end
108
+ # end
109
+ # def process_ajax
110
+ # true
111
+ # end
112
+ # def ajax_success
113
+ # render partial: success_partial
114
+ # # render json: {ok: true}
115
+ # end
116
+ # def redirect_after_done
117
+ # redirect_to action: :sent
118
+ # end
119
+ # def xhr_checker
120
+ # if request.xhr?
121
+ # render layout: false, locals: locals
122
+ # return true
123
+ # end
124
+ # end
125
+ # def after_initialize
126
+ # end
127
+ # def after_create
128
+ # # overrideable hook for updating message
129
+ # end
130
+ # def form_partial
131
+ # "hancock/feedback/contacts/form"
132
+ # end
133
+ # def success_partial
134
+ # "hancock/feedback/contacts/success"
135
+ # end
136
+ # def model
137
+ # Hancock::Feedback::ContactMessage
138
+ # end
139
+ # def message_params
140
+ # params.require(model.to_param.gsub("::", "").underscore).permit(
141
+ # model.permitted_fields + [:name, :email, :phone, :content, :captcha, :captcha_key]
142
+ # )
143
+ # end
144
+
145
+ end