hancock_cms_feedback 1.0.2

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.
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,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: f8635187bd7c69d51f2f3305d273bf3ca8354928
4
+ data.tar.gz: 40fba26ea9789aab51e457074edb5b370a22e3e0
5
+ SHA512:
6
+ metadata.gz: 8b202af443da4c572ccb53daa0358680a9d6ea2fab244e2cf7052e769a944120bfc2fce94f06e510424241e06babe818a094ef94e0a18baa4df5f295eee12351
7
+ data.tar.gz: 4ccdfb30f6c59b0ca679bfaebf38ddf400d0f91f0212114ebaeba36709979d547ff13fd59469fccbecf88d3a4db643a33edafa0b9800aafbc555b30c20a53f37
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
@@ -0,0 +1 @@
1
+ hancock_cms_feedback
@@ -0,0 +1 @@
1
+ 2.3.1
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.3
4
+ before_install: gem install bundler -v 1.10.6
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in enjoy_cms_feedback.gemspec
4
+ gemspec
@@ -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.
@@ -0,0 +1,60 @@
1
+ # HancockCmsFeedback
2
+
3
+ ### Remaded from [EnjoyCMSFeedback](https://github.com/enjoycreative/enjoy_cms_feedback)
4
+
5
+ Feedback system for [HancockCMS](https://github.com/red-rocks/hancock_cms).
6
+ Feedback form, AJAX, Mailer, custom fields, captcha support
7
+
8
+ ## Installation
9
+
10
+ Add this line to your application's Gemfile:
11
+
12
+ ```ruby
13
+ gem 'hancock_cms_feedback'
14
+ ```
15
+
16
+ Then add this
17
+ ```ruby
18
+ gem "recaptcha", require: "recaptcha/rails" # Recaptcha
19
+ ```
20
+ or this
21
+ ```ruby
22
+ gem "glebtv-simple_captcha" # simple_captcha
23
+ ```
24
+ before it for captcha you need. And configure it.
25
+
26
+ And then execute:
27
+
28
+ $ bundle
29
+
30
+ Or install it yourself as:
31
+
32
+ $ gem install hancock_cms_feedback
33
+
34
+ ## Usage
35
+
36
+ Add in config/routes.rb
37
+
38
+ ```ruby
39
+ hancock_cms_feedback_routes
40
+ ```
41
+ Then execute
42
+
43
+ $ rails g hancock:feedback:config
44
+
45
+ and now you can edit config/initializers/hancock_feedback.rb
46
+
47
+ ## Development
48
+
49
+ 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.
50
+
51
+ 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).
52
+
53
+ ## Contributing
54
+
55
+ Bug reports and pull requests are welcome on GitHub at https://github.com/red-rocks/hancock_cms_feedback.
56
+
57
+
58
+ ## License
59
+
60
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,8 @@
1
+ #= require ./feedback/init
2
+ #= require ./feedback/form
3
+
4
+ #= require_self
5
+
6
+ window.hancock_cms.feedback.create_ajax_form()
7
+ window.hancock_cms.feedback.set_update_captcha()
8
+ window.hancock_cms.feedback.set_feedback_form_reloader()
@@ -0,0 +1,77 @@
1
+ window.hancock_cms.feedback.create_ajax_form = (form_selector = "#new_hancock_feedback_contact_message",
2
+ wrapper_selector = "#hancock_feedback_contact_form",
3
+ animate = true)->
4
+
5
+ if animate
6
+ $(document).delegate form_selector, "ajax:send", ()->
7
+ $(form_selector).closest(wrapper_selector).animate(opacity: 0.01, 100)
8
+
9
+ $(document).delegate form_selector, "ajax:complete", (event, xhr, status)->
10
+ data = xhr.responseText
11
+ if $(data).find('img').length > 0
12
+ $(data).find('img').load ->
13
+ $(form_selector).closest(wrapper_selector).stop().css(opacity: 0.01).html(data).css(opacity: "")
14
+ else
15
+ $(form_selector).closest(wrapper_selector).stop().css(opacity: 0.01).html(data).css(opacity: "")
16
+
17
+ else
18
+ $(document).delegate form_selector, "ajax:complete", (event, xhr, status)->
19
+ $(form_selector).closest(wrapper_selector).html(xhr.responseText)
20
+
21
+
22
+ $(document).delegate form_selector + " .input", 'click', (e) ->
23
+ e.preventDefault()
24
+ $(e.currentTarget).removeClass("field_with_errors").find('span.error').hide()
25
+ return false
26
+
27
+
28
+ window.hancock_cms.feedback.set_update_captcha = (link_selector = "#new_hancock_feedback_contact_message .update_captcha_link",
29
+ captcha_selector = "#new_hancock_feedback_contact_message .simple_captcha",
30
+ animate = true) ->
31
+ if animate
32
+ $(document).delegate link_selector, 'click', (e) ->
33
+ e.preventDefault()
34
+ $(captcha_selector).animate(opacity: 0.01, 100)
35
+ $.get e.currentTarget.href, (data)->
36
+ $(data).find('img').load ->
37
+ $(captcha_selector).stop().css(opacity: 0.01).replaceWith(data).find('input[type=text]').focus()
38
+
39
+ else
40
+ $(document).delegate link_selector, 'click', (e) ->
41
+ e.preventDefault()
42
+ $.get e.currentTarget.href, (data)->
43
+ $(captcha_selector).replaceWith(data).find('input[type=text]').focus()
44
+
45
+ $(document).delegate captcha_selector + " img", 'dblclick', (e)->
46
+ e.preventDefault()
47
+ $(link_selector).trigger 'click'
48
+ return false
49
+
50
+
51
+
52
+ window.hancock_cms.feedback.set_feedback_form_reloader = (link_selector = "#hancock_cms_feedback_success .reload_feedback_form_link",
53
+ wrapper_selector = '#hancock_cms_feedback_success',
54
+ wrapper_form = $("<div id='hancock_cms_feedback_success'></div>"),
55
+ animate = true) ->
56
+
57
+ if animate
58
+ $(document).delegate link_selector, 'click', (e) ->
59
+ e.preventDefault()
60
+ $(wrapper_selector).animate(opacity: 0.01, 100)
61
+ $.get e.currentTarget.href, (data)->
62
+ data = wrapper_form.html(data)[0].outerHTML if wrapper_form.length > 0
63
+ if $(data).find('img').length > 0
64
+ $(data).find('img').load ->
65
+ $(wrapper_selector).stop().css(opacity: 0.01).replaceWith(data).find('input[type=text]').focus()
66
+ else
67
+ $(wrapper_selector).stop().css(opacity: 0.01).replaceWith(data).find('input[type=text]').focus()
68
+ else
69
+ $(document).delegate link_selector, 'click', (e) ->
70
+ e.preventDefault()
71
+ $.get e.currentTarget.href, (data)->
72
+ data = wrapper_form.html(data)[0].outerHTML if wrapper_form.length > 0
73
+ if $(data).find('img').length > 0
74
+ $(data).find('img').load ->
75
+ $(wrapper_selector).replaceWith(data).find('input[type=text]').focus()
76
+ else
77
+ $(wrapper_selector).replaceWith(data).find('input[type=text]').focus()
@@ -0,0 +1,2 @@
1
+ window.hancock_cms ||= {}
2
+ window.hancock_cms.feedback ||= {}
@@ -0,0 +1,84 @@
1
+ module Hancock::Feedback::Decorators
2
+ module Contacts
3
+ extend ActiveSupport::Concern
4
+
5
+ # included do
6
+ #
7
+ # def hancock_feedback_update_captcha_path
8
+ # url_for(action: :update_captcha, time: Time.new.to_i, only_path: true)
9
+ # end
10
+ # def is_cache_fields
11
+ # cache_fields?
12
+ # end
13
+ # def cache_fields?
14
+ # ['new', 'index'].include? action_name
15
+ # end
16
+ # def cache_key
17
+ # 'hancock_feedback_contacts_fields'.freeze
18
+ # end
19
+ # def fields_partial
20
+ # "hancock/feedback/contacts/#{(Hancock::Feedback.config.model_settings_support ? 'fields_with_settings' : 'fields')}".freeze
21
+ # end
22
+ # def settings_scope
23
+ # if Hancock::Feedback.config.model_settings_support
24
+ # model.settings
25
+ # elsif defined?(Settings)
26
+ # Settings.ns('feedback')
27
+ # else
28
+ # nil
29
+ # end
30
+ # end
31
+ # def recaptcha_options
32
+ # {}
33
+ # end
34
+ #
35
+ #
36
+ # def render_contacts_error
37
+ # if request.xhr? && process_ajax
38
+ # render partial: form_partial, status: 422
39
+ # # render json: {errors: @contact_message.errors}, status: 422
40
+ # else
41
+ # flash.now[:alert] = @contact_message.errors.full_messages.join("\n")
42
+ # render action: Hancock::Feedback.configuration.recreate_contact_message_action, status: 422
43
+ # end
44
+ # end
45
+ # def process_ajax
46
+ # true
47
+ # end
48
+ # def ajax_success
49
+ # render partial: success_partial
50
+ # # render json: {ok: true}
51
+ # end
52
+ # def redirect_after_done
53
+ # redirect_to action: :sent
54
+ # end
55
+ # def xhr_checker
56
+ # if request.xhr?
57
+ # render layout: false
58
+ # end
59
+ # end
60
+ # def after_initialize
61
+ # end
62
+ # def after_create
63
+ # # overrideable hook for updating message
64
+ # end
65
+ # def form_partial
66
+ # "hancock/feedback/contacts/form"
67
+ # end
68
+ # def success_partial
69
+ # "hancock/feedback/contacts/success"
70
+ # end
71
+ # def model
72
+ # Hancock::Feedback::ContactMessage
73
+ # end
74
+ # def message_params
75
+ # params.require(model.to_param.gsub("::", "").underscore).permit(
76
+ # model.permitted_fields + [:name, :email, :phone, :content, :captcha, :captcha_key]
77
+ # )
78
+ # end
79
+ #
80
+ # end
81
+
82
+
83
+ end
84
+ end
@@ -0,0 +1,7 @@
1
+ module Hancock::Feedback
2
+ class ContactsController < ApplicationController
3
+ include Hancock::Feedback::Controllers::Contacts
4
+
5
+ include Hancock::Feedback::Decorators::Contacts
6
+ end
7
+ end
@@ -0,0 +1,17 @@
1
+ module Hancock::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@redrocks.pro'),
12
+ to: Settings.form_email(default: 'admin@redrocks.pro'),
13
+ subject: "[#{Settings.email_topic(default: 'с сайта')}] #{message.name} #{message.email}"
14
+ )
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,44 @@
1
+ module Hancock::Feedback::Decorators
2
+ module ContactMessage
3
+ extend ActiveSupport::Concern
4
+
5
+ included do
6
+
7
+ # def self.permitted_fields
8
+ # []
9
+ # end
10
+ #
11
+ # def self.default_cache_keys
12
+ # []
13
+ # end
14
+ #
15
+ # ############# rails_admin ##############
16
+ # def self.rails_admin_add_fields
17
+ # {}
18
+ # end
19
+ #
20
+ # def self.rails_admin_add_config(config)
21
+ # end
22
+ #
23
+ # def self.admin_can_user_defined_actions
24
+ # [].freeze
25
+ # end
26
+ # def self.admin_cannot_user_defined_actions
27
+ # [].freeze
28
+ # end
29
+ # def self.manager_can_user_defined_actions
30
+ # [].freeze
31
+ # end
32
+ # def self.manager_cannot_user_defined_actions
33
+ # [].freeze
34
+ # end
35
+ # def self.rails_admin_user_defined_visible_actions
36
+ # [].freeze
37
+ # end
38
+
39
+
40
+
41
+ end
42
+
43
+ end
44
+ end
@@ -0,0 +1,17 @@
1
+ module Hancock::Feedback
2
+ if Hancock::Feedback.active_record?
3
+ class ContactMessage < ActiveRecord::Base
4
+ end
5
+ end
6
+
7
+ class ContactMessage
8
+
9
+ include Hancock::Feedback::Models::ContactMessage
10
+
11
+ include Hancock::Feedback::Decorators::ContactMessage
12
+
13
+ rails_admin(&Hancock::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 version 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 = (Hancock::Feedback.mongoid? ? Hancock::Feedback::ContactMessage.fields.keys : Hancock::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
+ = Hancock::Feedback::ContactMessage.human_attribute_name(c)
14
+ td(style='padding: 2px 3px')
15
+ = @message.send(c.to_sym)
@@ -0,0 +1,18 @@
1
+ ruby:
2
+ autofocus_field ||= :name
3
+
4
+ - label = t('hancock.feedback_plugin.fields.name.label')
5
+ - placeholder = t('hancock.feedback_plugin.fields.name.placeholder')
6
+ = f.input :name, label: label, input_html: {placeholder: placeholder, autofocus: autofocus_field == :name}
7
+
8
+ - label = t('hancock.feedback_plugin.fields.email.label')
9
+ - placeholder = t('hancock.feedback_plugin.fields.email.placeholder')
10
+ = f.input :email, label: label, input_html: {placeholder: placeholder, autofocus: autofocus_field == :email}
11
+
12
+ - label = t('hancock.feedback_plugin.fields.phone.label')
13
+ - placeholder = t('hancock.feedback_plugin.fields.phone.placeholder')
14
+ = f.input :phone, label: label, input_html: {placeholder: placeholder, autofocus: autofocus_field == :phone}
15
+
16
+ - label = t('hancock.feedback_plugin.fields.content.label')
17
+ - placeholder = t('hancock.feedback_plugin.fields.content.placeholder')
18
+ = f.input :content, as: :text, label: label, input_html: {placeholder: placeholder, autofocus: autofocus_field == :content}
@@ -0,0 +1,24 @@
1
+ ruby:
2
+ cache_key ||= 'views/hancock_feedback_contacts_fields'.freeze
3
+ if Hancock::Feedback.config.model_settings_support
4
+ settings_scope ||= Hancock::Feedback::ContactMessage.settings
5
+ elsif defined?(Settings)
6
+ settings_scope ||= Settings.ns('feedback')
7
+ end
8
+ autofocus_field ||= :name
9
+
10
+ - label = settings_scope.name_label(default: t('hancock.feedback_plugin.fields.name.label'), label: "Заголовок поля ФИО", cache_keys: cache_key)
11
+ - placeholder = settings_scope.name_placeholder(default: t('hancock.feedback_plugin.fields.name.placeholder'), label: "Placeholder поля ФИО", cache_keys: cache_key)
12
+ = f.input :name, label: label, input_html: {placeholder: placeholder, autofocus: autofocus_field == :name}
13
+
14
+ - label = settings_scope.email_label(default: t('hancock.feedback_plugin.fields.email.label'), label: "Заголовок поля e-mail", cache_keys: cache_key)
15
+ - placeholder = settings_scope.email_placeholder(default: t('hancock.feedback_plugin.fields.email.placeholder'), label: "Placeholder поля e-mail", cache_keys: cache_key)
16
+ = f.input :email, label: label, input_html: {placeholder: placeholder, autofocus: autofocus_field == :email}
17
+
18
+ - label = settings_scope.phone_label(default: t('hancock.feedback_plugin.fields.phone.label'), label: "Заголовок поля телефон", cache_keys: cache_key)
19
+ - placeholder = settings_scope.phone_placeholder(default: t('hancock.feedback_plugin.fields.phone.placeholder'), label: "Placeholder поля телефон", cache_keys: cache_key)
20
+ = f.input :phone, label: label, input_html: {placeholder: placeholder, autofocus: autofocus_field == :phone}
21
+
22
+ - label = settings_scope.content_label(default: t('hancock.feedback_plugin.fields.content.label'), label: "Заголовок поля сообщение", cache_keys: cache_key)
23
+ - placeholder = settings_scope.content_placeholder(default: t('hancock.feedback_plugin.fields.content.placeholder'), label: "Placeholder поля сообщение", cache_keys: cache_key)
24
+ = f.input :content, as: :text, label: label, input_html: {placeholder: placeholder, autofocus: autofocus_field == :content}