c80_feedback_form 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (38) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +10 -0
  3. data/.travis.yml +3 -0
  4. data/CODE_OF_CONDUCT.md +13 -0
  5. data/Gemfile +4 -0
  6. data/LICENSE.txt +21 -0
  7. data/README.md +59 -0
  8. data/Rakefile +1 -0
  9. data/app/admin/c80_feedback_form/message_feedbacks.rb +21 -0
  10. data/app/assets/javascripts/c80_feedback_form.js.coffee +2 -0
  11. data/app/assets/javascripts/frontend/feedback-form-ajax.js +52 -0
  12. data/app/assets/javascripts/frontend/modal_forms.js +65 -0
  13. data/app/assets/stylesheets/active_admin_c80_feedback_form.scss +1 -0
  14. data/app/assets/stylesheets/backend/active_admin_custom/message_feedbacks.scss +8 -0
  15. data/app/assets/stylesheets/backend/active_admin_custom.scss +1 -0
  16. data/app/assets/stylesheets/c80_feedback_form.scss +8 -0
  17. data/app/assets/stylesheets/frontend/contacts.scss +43 -0
  18. data/app/controllers/c80_feedback_form/application_controller.rb +5 -0
  19. data/app/controllers/c80_feedback_form/mess_controller.rb +26 -0
  20. data/app/controllers/c80_feedback_form/site_controller.rb +6 -0
  21. data/app/helpers/c80_feedback_form/site_helper.rb +22 -0
  22. data/app/mailers/c80_feedback_form/message_feedback_mailer.rb +28 -0
  23. data/app/models/c80_feedback_form/message_feedback.rb +5 -0
  24. data/app/models/c80_feedback_form/message_feedback_validator.rb +50 -0
  25. data/app/views/c80_feedback_form/mess/handle_message_feedback.js.erb +4 -0
  26. data/app/views/c80_feedback_form/message_feedback_mailer/mail_mess.html.erb +1 -0
  27. data/app/views/c80_feedback_form/site/give_me_form.js.erb +10 -0
  28. data/app/views/c80_feedback_form/site/shared/_feedback_form.html.erb +77 -0
  29. data/app/views/c80_feedback_form/site/shared/_ok_message.html.erb +16 -0
  30. data/bin/console +14 -0
  31. data/bin/setup +7 -0
  32. data/c80_feedback_form.gemspec +25 -0
  33. data/config/routes.rb +6 -0
  34. data/db/migrate/20151207174001_create_c80_feedback_form_message_feedbacks.rb +12 -0
  35. data/lib/c80_feedback_form/engine.rb +23 -0
  36. data/lib/c80_feedback_form/version.rb +3 -0
  37. data/lib/c80_feedback_form.rb +9 -0
  38. metadata +129 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 9254cd62480954cac0fa1f8198f5719fa26cf227
4
+ data.tar.gz: cd7f63b514842ddde4f7e8c1275e1b653de51ac1
5
+ SHA512:
6
+ metadata.gz: a0ed4b83241cd71e5206869dce8d56d132d6d9d311c928a1ea62c6b37df6da2c5891c55395bf916a5ebe4b7d3f24ca029c7a798b4d365c6623ada703634dfa66
7
+ data.tar.gz: 99f50eac5c8cdcb410321309d1ab68a209e7631efc0a3a5377d7a4ea54a7e27e25dfb14742afc7d932ce8294a79d9c24134397cf44f2067302ce959958ccb7ec
data/.gitignore ADDED
@@ -0,0 +1,10 @@
1
+ /.idea/
2
+ /.bundle/
3
+ /.yardoc
4
+ /Gemfile.lock
5
+ /_yardoc/
6
+ /coverage/
7
+ /doc/
8
+ /pkg/
9
+ /spec/reports/
10
+ /tmp/
data/.travis.yml ADDED
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.1.4
@@ -0,0 +1,13 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4
+
5
+ We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, age, or religion.
6
+
7
+ Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
8
+
9
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
10
+
11
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
12
+
13
+ This Code of Conduct is adapted from the [Contributor Covenant](http:contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in c80_feedback_form.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 C80609A
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,59 @@
1
+ # C80FeedbackForm
2
+
3
+ Gem adds functionality to allow users to send feedback messages from site.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'c80_feedback_form'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install c80_feedback_form
20
+
21
+ ## Usage
22
+
23
+ You will need to add this line into your `application.js`:
24
+
25
+ //= require c80_feedback_form
26
+
27
+ And add this line into `application.scss`:
28
+
29
+ @import "c80_feedback_form";
30
+
31
+ Add this line into `active_admin.scss`:
32
+
33
+ @import "active_admin_c80_feedback_form";
34
+
35
+ Add this line into `routes.rb`:
36
+
37
+ mount C80FeedbackForm::Engine => '/'
38
+
39
+ Gem functionality applies to code snippets like this:
40
+
41
+ <body id="contacts"> <!-- js script performs at body#contacts page only -->
42
+ <...>
43
+ <div id="ff"></div> <!-- feedback form placeholder -->
44
+ <...>
45
+ </body>
46
+
47
+ ## Development
48
+
49
+ After checking out the repo, run `bin/setup` to install dependencies. Then, 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` to 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
+ 1. Fork it ( https://github.com/[my-github-username]/c80_feedback_form/fork )
56
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
57
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
58
+ 4. Push to the branch (`git push origin my-new-feature`)
59
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,21 @@
1
+ ActiveAdmin.register C80FeedbackForm::MessageFeedback, :as => 'MessageFeedback' do
2
+
3
+ before_filter :skip_sidebar!, :only => :index
4
+
5
+ menu :parent => "Сообщения", :label => 'Обратная связь'
6
+
7
+ index do
8
+ selectable_column
9
+ id_column
10
+ column :created_at
11
+ column :name
12
+ column :email_or_phone
13
+ column :comment do |msg|
14
+ msg.comment.html_safe if msg.comment.present?
15
+ end
16
+
17
+ actions
18
+ end
19
+
20
+
21
+ end
@@ -0,0 +1,2 @@
1
+ #= require bootstrap/modal
2
+ #= require_directory ./frontend
@@ -0,0 +1,52 @@
1
+
2
+ // =[ interface ]=====================================================================================================================
3
+
4
+ var $formHolder;
5
+ var markInvalidateInProgress = false;
6
+ var markWasPasted = false;
7
+ var fFeedbackFormInvalidate;
8
+ var fFeedbackFormOnScroll;
9
+
10
+ // =[ implementation ]=====================================================================================================================
11
+
12
+ $(function () {
13
+ if ($("body#contacts").length == 1) {
14
+
15
+ $formHolder = $("div#ff");
16
+
17
+ fFeedbackFormInvalidate = function () {
18
+ if (!markInvalidateInProgress) {
19
+ markInvalidateInProgress = true;
20
+
21
+ if (!markWasPasted) {
22
+
23
+ $('<div id="loading"></div>').appendTo($formHolder);
24
+
25
+ $.ajax({
26
+ url: '/give_me_form',
27
+ type: 'POST',
28
+ dataType: 'script'
29
+ }).done(function (data, result) {
30
+ if (result == "success") {
31
+ markWasPasted = true;
32
+ }
33
+ });
34
+ }
35
+ }
36
+ };
37
+
38
+ fFeedbackFormOnScroll = function(event) {
39
+ var closeToBottom = jQuery(window).scrollTop() >= 0;
40
+ if (closeToBottom) {
41
+ fFeedbackFormInvalidate();
42
+ }
43
+ };
44
+
45
+ // start
46
+ $(document).bind('scroll', fFeedbackFormOnScroll);
47
+ setTimeout(function () {
48
+ fFeedbackFormOnScroll();
49
+ },300);
50
+
51
+ }
52
+ });
@@ -0,0 +1,65 @@
1
+ /**
2
+ * Created by scout on 3/25/15.
3
+ * "методы" по работе с модальными окнами.
4
+ *
5
+ */
6
+
7
+ (function($) {
8
+
9
+ $.fn.modal_success = function(){
10
+ //console.log("modal_success>");
11
+
12
+ // close modal
13
+ this.modal('hide');
14
+
15
+ // clear form input elements
16
+ this.find('input[type="text"]').val('');
17
+ this.find('textarea').val('');
18
+
19
+ // clear error state
20
+ this.clear_previous_errors();
21
+ };
22
+
23
+ $.fn.render_form_errors = function(errors){
24
+
25
+ var $form = this;
26
+ this.clear_previous_errors();
27
+ var model = this.data('model');
28
+
29
+ // show error messages in input form-group help-block
30
+ $.each(errors, function(field, messages){
31
+ var $input = $('input[name="' + model + '[' + field + ']"]');
32
+ if ($input.length == 0) {
33
+ $input = $('textarea[name="' + model + '[' + field + ']"]');
34
+ }
35
+ $input.closest('.form-group').addClass('has-error').find('.help-block').html( messages.join(' ') );
36
+ });
37
+
38
+ };
39
+
40
+ $.fn.clear_previous_errors = function(){
41
+ $('.form-group.has-error', this).each(function(){
42
+ //console.log($('.help-block', $(this)));
43
+ $('.help-block', $(this)).html('');
44
+ $(this).removeClass('has-error');
45
+ });
46
+ $.rails.enableFormElements($(this));
47
+ };
48
+
49
+ $.fn.my_render_form_errors = function(errors) {
50
+
51
+ var model = this.data('model');
52
+
53
+ $.each(errors, function(field, messages) {
54
+
55
+ var $span = $('span#' + model + '_' + field);
56
+ //console.log($span);
57
+ $span.closest('.form-group').addClass('has-error');
58
+ $span.html( messages.join(' & ') );
59
+
60
+ });
61
+
62
+ };
63
+
64
+ }(jQuery));
65
+
@@ -0,0 +1 @@
1
+ @import "backend/active_admin_custom";
@@ -0,0 +1,8 @@
1
+ body.admin_message_feedbacks {
2
+ // прячем кнопку batch actions
3
+ .table_tools { display: none; }
4
+ // прячем кнопку "создать новую запись"
5
+ div.action_items { display: none; }
6
+ //прячем ссылку "редактировать"
7
+ a.edit_link { display: none; }
8
+ }
@@ -0,0 +1 @@
1
+ @import "active_admin_custom/message_feedbacks";
@@ -0,0 +1,8 @@
1
+ /*
2
+ *= require_self
3
+ */
4
+ @import "frontend/contacts";
5
+ @import "bootstrap-sprockets";
6
+ @import "bootstrap";
7
+
8
+ .kapcha { display: none; }
@@ -0,0 +1,43 @@
1
+
2
+ #ff {
3
+ margin: 0;
4
+ background-color: rgba(51, 122, 183, .03);
5
+ min-height: 300px;
6
+ position: relative;
7
+
8
+ #loading {
9
+ position: absolute;
10
+ top: 0;
11
+ left: 0;
12
+ bottom: 0;
13
+ right: 0;
14
+ text-align: center;
15
+ font-size: 20px;
16
+ background: rgba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IUi6ABBE3AkCA8a4RxnuJUCbYTEjaiJaXbE4lxMDFv0MYNCDoWJUBei8vli1iIDQY0xFRV9VEMO5uKDCnCv7ta0BP4siLBAEAIfkECQoAAAAsAAAAACMAIwAABv9AgHBILBqPyKQRwkkon8rQRSJRQK9Eg2V64WC/DypV9DUaHooDMSwWqYcJkcjxNBQgBQRjqBBfJkQTGxsfJHtJCQWKim8HIlwLQxwfg4ORSQqLik5CHFMSEUIKlZWhSguaBQZCDRcXbkIYpB8lUAypDUIErhBCCJSDHxhvTwwNixAEAI4XTgcjpBPEVwqoeUIgF2oTwBICZUMHD3ehBLkRgxgDWAcGBIdDxpysGAXEBwIQIQV0RAKLCxAIIDANST5ZFDIopBDizb9UihYk6GekwwaFGDNmwCBkAERkEKwUOXBRo0YPuj4uaPBA2ZEDBSSU1GgCxBADAxCsfOBgWsGXVULwdajwgcKHCqagOGhwKWgeoOEOFEzCwGPIZQjUPMCTAN4XBuMiioJAB+aib18cpOo3AAJaBXgiQlXiIK6iXMsUIRhibdHUkRAPqVUk2O41JQ8VuYWziCKCVHONJC6A19eieWYXRR75uMCDLJr2xjtWAK2Sdl4BENDU9ObmL3YWiQb3xNpi2k9W5/mLu4iCAS57C0cSBAA7AAAAAAAAAAAA) 50% 50% no-repeat;
17
+ z-index: 9999;
18
+ line-height: 3;
19
+ transition: visibility 1s, opacity 0.5s linear;
20
+
21
+ &.invis {
22
+ visibility: hidden;
23
+ opacity: 0;
24
+ }
25
+
26
+ }
27
+
28
+ #feedback_form {
29
+ .modal-dialog {
30
+ width: auto;
31
+ margin: 0 0 0 -15px;
32
+
33
+ .modal-content {
34
+ box-shadow: none;
35
+ border: none;
36
+ }
37
+
38
+ }
39
+ }
40
+
41
+ }
42
+
43
+
@@ -0,0 +1,5 @@
1
+ module C80FeedbackForm
2
+ class ApplicationController < ActionController::Base
3
+ protect_from_forgery with: :exception
4
+ end
5
+ end
@@ -0,0 +1,26 @@
1
+ module C80FeedbackForm
2
+ class MessController < ApplicationController
3
+
4
+ # skip_before_filter :verify_authenticity_token
5
+
6
+ def handle_message_feedback
7
+ puts "<MessController.handle_message_feedback>"
8
+ m = MessageFeedback.new(mess_params)
9
+ respond_to do |format|
10
+ if m.save
11
+
12
+ format.js
13
+ MessageFeedbackMailer.send_mess(m, "Сообщение с сайта").deliver
14
+ else
15
+ puts "<MessController.handle_message_feedback> errors: #{m.errors}"
16
+ format.js { render json: m.errors, status: :unprocessable_entity }
17
+ end
18
+ end
19
+ end
20
+
21
+ def mess_params
22
+ params.require(:mess).permit(:name, :email_or_phone, :comment, :kapcha)
23
+ end
24
+
25
+ end
26
+ end
@@ -0,0 +1,6 @@
1
+ module C80FeedbackForm
2
+ class SiteController < ApplicationController
3
+ def give_me_form
4
+ end
5
+ end
6
+ end
@@ -0,0 +1,22 @@
1
+ module C80FeedbackForm
2
+ module SiteHelper
3
+
4
+ def render_feedback_form
5
+
6
+ render :partial => "c80_feedback_form/site/shared/feedback_form",
7
+ :locals => {
8
+ :mess => "MessageFeedback.new"
9
+ }
10
+
11
+ end
12
+
13
+ def render_ok_message
14
+ render :partial => "c80_feedback_form/site/shared/ok_message",
15
+ :locals => {
16
+ ok_text: "Мы свяжемся с Вами в ближайшее время.",
17
+ wtitle: "Ваше сообщение отправлено"
18
+ }
19
+ end
20
+
21
+ end
22
+ end
@@ -0,0 +1,28 @@
1
+ module C80FeedbackForm
2
+ class MessageFeedbackMailer < ActionMailer::Base
3
+
4
+ default from: Proc.new { SiteProp.first.mail_from },
5
+ to: Proc.new { SiteProp.first.mail_to }
6
+
7
+ def send_mess(message, subject)
8
+ @message = format_message(message)
9
+
10
+ puts "<MessageFeedbackMailer.send_mess> Отправляем сообщение."
11
+ mail(subject: subject) do |format|
12
+ format.html { render "mail_mess" }
13
+ end
14
+
15
+ #puts "#{SiteProps.first.mail_to}"
16
+ end
17
+
18
+ private
19
+
20
+ def format_message(message)
21
+ result = "<br> • Имя: #{message.name}"
22
+ result += "<br> • Email или телефон: #{message.email_or_phone}"
23
+ result += "<br> • Сообщение: #{message.comment}"
24
+ result
25
+ end
26
+
27
+ end
28
+ end
@@ -0,0 +1,5 @@
1
+ module C80FeedbackForm
2
+ class MessageFeedback < ActiveRecord::Base
3
+ validates_with MessageFeedbackValidator
4
+ end
5
+ end
@@ -0,0 +1,50 @@
1
+ module C80FeedbackForm
2
+ class MessageFeedbackValidator < ActiveModel::Validator
3
+ def validate(record)
4
+ unless record.errors.present?
5
+ puts "<MessageFeedbackValidator.validate> record = #{record}"
6
+ mark_please_used = false
7
+
8
+ unless record.name.present?
9
+ record.errors[:name] = 'Укажите, пожалуйста, Ваше имя'
10
+ mark_please_used = true
11
+ end
12
+
13
+ if record.email_or_phone.present?
14
+ # указан email
15
+ if record.email_or_phone[/([a-z0-9_.-]+)@([a-z0-9-]+)\.[a-z.]+/].present?
16
+ else
17
+ # указан мобильный
18
+ if record.email_or_phone[/^((8|\+7)[\- ]?)?(\(?\d{3}\)?[\- ]?)?[\d\- ]{7,10}$/].present?
19
+ else
20
+ if mark_please_used
21
+ t2 = 'Номер телефона или email введены неверно'
22
+ else
23
+ t2 = 'Пожалуйста, укажите корректный номер телефона или email'
24
+ mark_please_used = true
25
+ end
26
+ record.errors[:email_or_phone] = t2
27
+ end
28
+ end
29
+ else
30
+ if mark_please_used
31
+ t1 = 'Укажите или номер телефона или email'
32
+ else
33
+ t1 = 'Укажите, пожалуйста, или номер телефона или email'
34
+ mark_please_used = true
35
+ end
36
+ record.errors[:email_or_phone] = t1
37
+ end
38
+
39
+ unless record.comment.present?
40
+ record.errors[:comment] = 'Сообщение не может быть пустым'
41
+ end
42
+
43
+ unless record.kapcha.blank?
44
+ record.errors[:kapcha] = 'fail'
45
+ end
46
+ end
47
+
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,4 @@
1
+ $('#feedback_form').modal_success();
2
+ setTimeout(function(){
3
+ $('#modal_ok').modal("show");
4
+ },400);
@@ -0,0 +1 @@
1
+ <%= @message.html_safe %>
@@ -0,0 +1,10 @@
1
+ var $cc = $("#ff");
2
+ var html_str = "<%= j render_feedback_form %>";
3
+
4
+ setTimeout(function () {
5
+ $('#loading').addClass('invis');
6
+ setTimeout(function () {
7
+ $cc.html(html_str);
8
+ },500);
9
+ },1000);
10
+
@@ -0,0 +1,77 @@
1
+ <%= render_ok_message %>
2
+ <div id="feedback_form" tabindex="-1" role="dialog" aria-labelledby="feedbackForm" aria-hidden="true">
3
+ <div class="modal-dialog">
4
+ <div class="modal-content">
5
+ <div class="modal-header">
6
+ <h4 class="modal-title medium" id="myModalLabel">Обратная связь</h4>
7
+ </div>
8
+ <div class="modal-body regular">
9
+
10
+ <%= form_for :mess,
11
+ :url => '/message_feedback',
12
+ :remote => true,
13
+ html: {
14
+ multipart: true,
15
+ :role => :form,
16
+ :id => "form_feedback",
17
+ :data => {
18
+ :model => "mess"
19
+ }
20
+ } do |f| %>
21
+
22
+ <div class="form-group clearfix">
23
+ <%= f.label :name, "Имя", class: 'control-label must' %>
24
+ <%= f.text_field :name, class: 'form-control' %>
25
+ <span class="help-block col-md-12"></span>
26
+ </div>
27
+
28
+ <div class="form-group clearfix">
29
+ <%= f.label :email_or_phone, "Email или телефон", class: 'control-label must' %>
30
+ <%= f.text_field :email_or_phone, class: 'form-control' %>
31
+ <span class="help-block col-md-12"></span>
32
+ </div>
33
+
34
+ <div class="form-group kapcha clearfix">
35
+ <%= f.label :kapcha, "Капча: сколько будет 2+2?", class: 'control-label' %>
36
+ <%= f.text_field :kapcha, class: 'form-control' %>
37
+ <span class="help-block col-md-12"></span>
38
+ </div>
39
+
40
+ <div class="form-group clearfix" style="margin-bottom: 0;">
41
+ <%= f.label :comment, "Сообщение", class: 'control-label' %>
42
+ <%= f.text_area :comment, class: 'form-control', :rows => "4" %>
43
+ <span class="help-block col-md-12"></span>
44
+ </div>
45
+
46
+ <div class="actions clearfix">
47
+ <%= f.label " ", class: 'control-label' %>
48
+ <%= f.submit "Отправить",
49
+ class: 'btn btn-primary',
50
+ data: {
51
+ disable_with: 'Отправляется...'
52
+ }
53
+ %>
54
+ </div>
55
+
56
+ <% end %>
57
+
58
+ </div>
59
+
60
+ </div>
61
+ </div>
62
+ </div>
63
+
64
+ <%# настраиваем форму %>
65
+ <script>
66
+ $(document).ready(function () {
67
+
68
+ var $form = $("form#form_feedback");
69
+
70
+ $form.bind("ajax:error", function (event, data, status, xhr) {
71
+ $form.render_form_errors($.parseJSON(data.responseText));
72
+ });
73
+
74
+ $form.modal_success();
75
+
76
+ });
77
+ </script>
@@ -0,0 +1,16 @@
1
+ <div class="modal fade" id="modal_ok" tabindex="1" role="dialog" aria-labelledby="modalOk" aria-hidden="true">
2
+ <div class="modal-dialog">
3
+ <div class="modal-content">
4
+ <div class="modal-header">
5
+ <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
6
+ <h4 class="modal-title" id="myModalLabel"><%= wtitle %></h4>
7
+ </div>
8
+ <div class="modal-body">
9
+ <p><%= ok_text %></p>
10
+ </div>
11
+ <div class="modal-footer">
12
+ <button type="button" class="btn btn-primary" data-dismiss="modal">Закрыть</button>
13
+ </div>
14
+ </div>
15
+ </div>
16
+ </div>
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "c80_feedback_form"
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,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,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'c80_feedback_form/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "c80_feedback_form"
8
+ spec.version = C80FeedbackForm::VERSION
9
+ spec.authors = ["C80609A"]
10
+ spec.email = ["c080609a@gmail.com"]
11
+
12
+ spec.summary = 'Enable the feedback feature'
13
+ spec.description = 'Gem adds functionality to allow users to send feedback messages from site.'
14
+ spec.homepage = "https://github.com/c080609a/c80_feedback_form"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = "exe"
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_development_dependency "bundler", "~> 1.9"
23
+ spec.add_development_dependency "rake", "~> 10.0"
24
+ spec.add_dependency 'rails', '~> 4.1', '>= 4.1.4'
25
+ end
data/config/routes.rb ADDED
@@ -0,0 +1,6 @@
1
+ C80FeedbackForm::Engine.routes.draw do
2
+ # scope :module => 'c80_feedback_form' do
3
+ match '/message_feedback', :to => 'mess#handle_message_feedback', :via => :post
4
+ match '/give_me_form', :to => 'site#give_me_form', :via => :post
5
+ # end
6
+ end
@@ -0,0 +1,12 @@
1
+ class CreateC80FeedbackFormMessageFeedbacks < ActiveRecord::Migration
2
+ def change
3
+ create_table :c80_feedback_form_message_feedbacks, :options => 'COLLATE=utf8_unicode_ci' do |t|
4
+ t.string :name
5
+ t.string :email_or_phone
6
+ t.string :comment
7
+ t.string :kapcha
8
+
9
+ t.timestamps
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,23 @@
1
+ module C80FeedbackForm
2
+ class Engine < ::Rails::Engine
3
+ isolate_namespace C80FeedbackForm
4
+
5
+ initializer :import_engine do
6
+ if defined?(ActiveAdmin)
7
+ ActiveAdmin.application.load_paths += Dir["#{config.root}/app/models/**/"]
8
+ #ActiveAdmin.application.load_paths += Dir["#{config.root}/app/models/concerns/**/"]
9
+ ActiveAdmin.application.load_paths += Dir["#{config.root}/app/admin/c80_feedback_form/**/"]
10
+ # ActiveAdmin.application.load_paths += Dir["#{config.root}/app/jobs/**/"]
11
+ end
12
+ end
13
+
14
+ initializer :append_migrations do |app|
15
+ unless app.root.to_s.match root.to_s
16
+ config.paths["db/migrate"].expanded.each do |expanded_path|
17
+ app.config.paths["db/migrate"] << expanded_path
18
+ end
19
+ end
20
+ end
21
+
22
+ end
23
+ end
@@ -0,0 +1,3 @@
1
+ module C80FeedbackForm
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,9 @@
1
+ require 'c80_feedback_form/version'
2
+ require 'c80_feedback_form/engine'
3
+
4
+ module C80FeedbackForm
5
+ def self.table_name_prefix
6
+ 'c80_feedback_form_'
7
+ end
8
+ end
9
+
metadata ADDED
@@ -0,0 +1,129 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: c80_feedback_form
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - C80609A
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-12-09 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.9'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.9'
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: rails
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '4.1'
48
+ - - ">="
49
+ - !ruby/object:Gem::Version
50
+ version: 4.1.4
51
+ type: :runtime
52
+ prerelease: false
53
+ version_requirements: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - "~>"
56
+ - !ruby/object:Gem::Version
57
+ version: '4.1'
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: 4.1.4
61
+ description: Gem adds functionality to allow users to send feedback messages from
62
+ site.
63
+ email:
64
+ - c080609a@gmail.com
65
+ executables: []
66
+ extensions: []
67
+ extra_rdoc_files: []
68
+ files:
69
+ - ".gitignore"
70
+ - ".travis.yml"
71
+ - CODE_OF_CONDUCT.md
72
+ - Gemfile
73
+ - LICENSE.txt
74
+ - README.md
75
+ - Rakefile
76
+ - app/admin/c80_feedback_form/message_feedbacks.rb
77
+ - app/assets/javascripts/c80_feedback_form.js.coffee
78
+ - app/assets/javascripts/frontend/feedback-form-ajax.js
79
+ - app/assets/javascripts/frontend/modal_forms.js
80
+ - app/assets/stylesheets/active_admin_c80_feedback_form.scss
81
+ - app/assets/stylesheets/backend/active_admin_custom.scss
82
+ - app/assets/stylesheets/backend/active_admin_custom/message_feedbacks.scss
83
+ - app/assets/stylesheets/c80_feedback_form.scss
84
+ - app/assets/stylesheets/frontend/contacts.scss
85
+ - app/controllers/c80_feedback_form/application_controller.rb
86
+ - app/controllers/c80_feedback_form/mess_controller.rb
87
+ - app/controllers/c80_feedback_form/site_controller.rb
88
+ - app/helpers/c80_feedback_form/site_helper.rb
89
+ - app/mailers/c80_feedback_form/message_feedback_mailer.rb
90
+ - app/models/c80_feedback_form/message_feedback.rb
91
+ - app/models/c80_feedback_form/message_feedback_validator.rb
92
+ - app/views/c80_feedback_form/mess/handle_message_feedback.js.erb
93
+ - app/views/c80_feedback_form/message_feedback_mailer/mail_mess.html.erb
94
+ - app/views/c80_feedback_form/site/give_me_form.js.erb
95
+ - app/views/c80_feedback_form/site/shared/_feedback_form.html.erb
96
+ - app/views/c80_feedback_form/site/shared/_ok_message.html.erb
97
+ - bin/console
98
+ - bin/setup
99
+ - c80_feedback_form.gemspec
100
+ - config/routes.rb
101
+ - db/migrate/20151207174001_create_c80_feedback_form_message_feedbacks.rb
102
+ - lib/c80_feedback_form.rb
103
+ - lib/c80_feedback_form/engine.rb
104
+ - lib/c80_feedback_form/version.rb
105
+ homepage: https://github.com/c080609a/c80_feedback_form
106
+ licenses:
107
+ - MIT
108
+ metadata: {}
109
+ post_install_message:
110
+ rdoc_options: []
111
+ require_paths:
112
+ - lib
113
+ required_ruby_version: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ required_rubygems_version: !ruby/object:Gem::Requirement
119
+ requirements:
120
+ - - ">="
121
+ - !ruby/object:Gem::Version
122
+ version: '0'
123
+ requirements: []
124
+ rubyforge_project:
125
+ rubygems_version: 2.4.7
126
+ signing_key:
127
+ specification_version: 4
128
+ summary: Enable the feedback feature
129
+ test_files: []