Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

feedback popup implemented

  • Loading branch information...
commit f7fa9853296f9ceb75253af2c3247b6c2cdda4f1 1 parent 38cfad5
Levente Bagi bagilevi authored
Showing with 350 additions and 12 deletions.
  1. +1 −0  .gitignore
  2. +7 −0 Gemfile
  3. +21 −1 Gemfile.lock
  4. +1 −1  MIT-LICENSE
  5. +50 −0 README.md
  6. +0 −3  README.rdoc
  7. +70 −0 app/assets/javascripts/feedback_popup.coffee
  8. +44 −0 app/assets/stylesheets/feedback_popup.sass
  9. +26 −0 app/controllers/feedback_popup/messages_controller.rb
  10. +5 −0 app/helpers/feedback_popup/feedback_popup_helper.rb
  11. +12 −0 app/mailers/feedback_popup/mailer.rb
  12. +28 −0 app/models/feedback_popup/message.rb
  13. +10 −0 app/views/feedback_popup/_popup.html.erb
  14. +1 −0  app/views/feedback_popup/mailer/feedback.text.erb
  15. +1 −0  app/views/feedback_popup/messages/create.js.erb
  16. +8 −0 config/locales/feedback_popup.en.yml
  17. +7 −0 config/routes.rb
  18. +7 −7 feedback_popup.gemspec
  19. +22 −0 lib/feedback_popup.rb
  20. +1 −0  test/dummy/app/assets/javascripts/application.js
  21. +1 −0  test/dummy/app/assets/stylesheets/application.css
  22. +4 −0 test/dummy/app/controllers/main_controller.rb
  23. +1 −0  test/dummy/app/views/main/index.html.erb
  24. +12 −0 test/dummy/config/application.rb
  25. +7 −0 test/dummy/config/initializers/feedback_popup.rb
  26. +3 −0  test/dummy/config/routes.rb
1  .gitignore
View
@@ -5,3 +5,4 @@ test/dummy/db/*.sqlite3
test/dummy/log/*.log
test/dummy/tmp/
test/dummy/.sass-cache
+.sass-cache
7 Gemfile
View
@@ -15,3 +15,10 @@ gem "jquery-rails"
# To use debugger
# gem 'ruby-debug19', :require => 'ruby-debug'
+
+group :assets do
+ gem 'sass-rails'
+ gem 'coffee-rails'
+ gem 'uglifier'
+end
+
22 Gemfile.lock
View
@@ -2,7 +2,7 @@ PATH
remote: .
specs:
feedback_popup (0.0.1)
- rails (~> 3.2.3)
+ rails (~> 3.0)
GEM
remote: http://rubygems.org/
@@ -36,7 +36,16 @@ GEM
multi_json (~> 1.0)
arel (3.0.2)
builder (3.0.0)
+ coffee-rails (3.2.2)
+ coffee-script (>= 2.2.0)
+ railties (~> 3.2.0)
+ coffee-script (2.2.0)
+ coffee-script-source
+ execjs
+ coffee-script-source (1.3.1)
erubis (2.7.0)
+ execjs (1.3.0)
+ multi_json (~> 1.0)
hike (1.2.1)
i18n (0.6.0)
journey (1.0.3)
@@ -76,6 +85,11 @@ GEM
rake (0.9.2.2)
rdoc (3.12)
json (~> 1.4)
+ sass (3.1.15)
+ sass-rails (3.2.5)
+ railties (~> 3.2.0)
+ sass (>= 3.1.10)
+ tilt (~> 1.3)
sprockets (2.1.2)
hike (~> 1.2)
rack (~> 1.0)
@@ -87,11 +101,17 @@ GEM
polyglot
polyglot (>= 0.3.1)
tzinfo (0.3.33)
+ uglifier (1.2.4)
+ execjs (>= 0.3.0)
+ multi_json (>= 1.0.2)
PLATFORMS
ruby
DEPENDENCIES
+ coffee-rails
feedback_popup!
jquery-rails
+ sass-rails
sqlite3
+ uglifier
2  MIT-LICENSE
View
@@ -1,4 +1,4 @@
-Copyright 2012 YOURNAME
+Copyright 2012 Levente Bagi
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
50 README.md
View
@@ -0,0 +1,50 @@
+# feedback_popup
+
+Simple feedback popup for Rails 3 applications.
+
+## Installation
+
+Add to your `Gemfile`:
+
+```ruby
+gem 'feedback_popup'
+```
+
+Run `bundle install`
+
+`config/initializers/feedback_popup.rb`:
+
+```ruby
+FeedbackPopup.setup do |config|
+ config.mail_to = 'you@example.com'
+ config.mail_from = 'sender@example.com'
+end
+```
+
+Add to your `app/assets/stylesheets/application.css' or equivalent,
+normally just before the `require_tree` line:
+
+```
+ *= require feedback_popup
+```
+
+Add to your `app/assets/javascripts/application.js' or equivalent,
+normally just before the `require_tree` line:
+
+```
+//= require feedback_popup
+```
+
+Add to your layout:
+
+```
+<%= feedback_popup %>
+```
+
+Make sure you have ActionMailer configured.
+
+Restart your app.
+
+## Copyright
+
+See the MIT-LICENSE file.
3  README.rdoc
View
@@ -1,3 +0,0 @@
-= FeedbackPopup
-
-This project rocks and uses MIT-LICENSE.
70 app/assets/javascripts/feedback_popup.coffee
View
@@ -0,0 +1,70 @@
+$ ->
+ FeedbackForm =
+ $el: $("#feedback_popup")
+
+ open: ->
+ if ! @isOpen()
+ @$el.addClass("open")
+ @$el.find('textarea').focus()
+
+ close: ->
+ if @isOpen()
+ @$el.removeClass("open")
+
+ isOpen: ->
+ @$el.hasClass("open")
+
+ toggle: ->
+ if @isOpen()
+ @close()
+ else
+ @open()
+
+ updateWithResponse: (response) ->
+ if response.success
+ @replaceFormWithMessage(response.success)
+ @waitThen =>
+ @close()
+ @reset()
+ @clear()
+ else
+ @replaceFormWithMessage(response.error)
+ @waitThen =>
+ @reset()
+
+ replaceFormWithMessage: (message) ->
+ @$el.find('form').hide()
+ @$el.find('.message').text(message).show()
+ @$el.find('.title').hide()
+
+ waitThen: (callback) ->
+ setTimeout(callback, 2000)
+
+ reset: ->
+ @$el.find('.message').hide()
+ @$el.find('.title').show()
+ @$el.find('form').show()
+
+ clear: ->
+ @$el.find('form')[0].reset()
+
+ showSending: ->
+ @replaceFormWithMessage "Sending..."
+
+ hideSending: ->
+
+
+ $('#feedback_popup .title').click ->
+ FeedbackForm.toggle()
+ false
+
+ $('#feedback_popup form').bind 'ajax:beforeSend', ->
+ FeedbackForm.showSending()
+ $('#feedback_popup form').bind 'ajax:complete', ->
+ FeedbackForm.hideSending()
+
+ $('#feedback_popup form').bind 'ajax:error', ->
+ FeedbackForm.updateWithResponse
+ error: "Internal error. Try again later."
+
+ window.FeedbackForm = FeedbackForm
44 app/assets/stylesheets/feedback_popup.sass
View
@@ -0,0 +1,44 @@
+#feedback_popup
+ font-family: Verdana, sans-serif
+ font-size: 14px
+ position: fixed
+ bottom: 0
+ right: 2em
+ background: #F70
+ padding: 5px
+ border-radius: 0.5em 0.5em 0 0
+
+ h4
+ padding: 0 1em
+ margin: 0em 0
+ text-transform: uppercase
+ text-align: center
+ color: white
+ text-shadow: #000 1px 1px 2px
+ font-size: 23px
+ cursor: pointer
+
+ .content
+ display: none
+ margin: 0.5em
+ text-align: right
+ form
+ display: block
+ width: 100%
+ textarea
+ display: block
+ font-family: Verdana, sans-serif
+ font-size: 14px
+ width: 20em
+ height: 10em
+ input[type=submit]
+ font-size: 16px
+
+ .message
+ display: none
+ text-align: center
+ color: white
+
+ &.open
+ .content
+ display: block
26 app/controllers/feedback_popup/messages_controller.rb
View
@@ -0,0 +1,26 @@
+class FeedbackPopup::MessagesController < ApplicationController
+ def create
+ message = FeedbackPopup::Message.new(message_params)
+ if message.deliver
+ @success_message = t('feedback_popup.message_sent')
+ else
+ @error_message = message.errors.full_messages.join("; ")
+ end
+ respond_to do |format|
+ format.html {
+ flash[:notice] = @success_message if @success_message
+ flash[:alert] = @error_message if @error_message
+ redirect_to root_url
+ }
+ format.js {
+ render :layout => nil
+ }
+ end
+ end
+
+ private
+
+ def message_params
+ params[:feedback_popup_message].slice(:body)
+ end
+end
5 app/helpers/feedback_popup/feedback_popup_helper.rb
View
@@ -0,0 +1,5 @@
+module FeedbackPopup::FeedbackPopupHelper
+ def feedback_popup
+ render 'feedback_popup/popup'
+ end
+end
12 app/mailers/feedback_popup/mailer.rb
View
@@ -0,0 +1,12 @@
+class FeedbackPopup::Mailer < ActionMailer::Base
+ def feedback(message)
+ @message = message
+
+ mail(
+ :from => FeedbackPopup.mail_from,
+ :to => FeedbackPopup.mail_to,
+ :subject => t('feedback_popup.email.subject')
+ )
+ end
+end
+
28 app/models/feedback_popup/message.rb
View
@@ -0,0 +1,28 @@
+class FeedbackPopup::Message
+ include ActiveModel::Conversion
+ include ActiveModel::Validations
+
+ attr_accessor :body
+
+ validates :body, :presence => true
+
+ def initialize(attributes = {})
+ attributes.each do |key, value|
+ self.send("#{key}=", value)
+ end
+ end
+
+ def deliver
+ if self.valid?
+ FeedbackPopup::Mailer.feedback(self).deliver
+ return true
+ end
+ return false
+ end
+
+ def persisted?
+ false
+ end
+
+end
+
10 app/views/feedback_popup/_popup.html.erb
View
@@ -0,0 +1,10 @@
+<div id="feedback_popup">
+ <h4 class="title"><%= t('feedback_popup.title') %></h4>
+ <div class="content">
+ <%= form_for FeedbackPopup::Message.new, :remote => true do |f| %>
+ <%= f.text_area :body %>
+ <%= f.submit t('feedback_popup.send_button') %>
+ <% end %>
+ <div class="message"></div>
+ </div>
+</div>
1  app/views/feedback_popup/mailer/feedback.text.erb
View
@@ -0,0 +1 @@
+<%= @message.body %>
1  app/views/feedback_popup/messages/create.js.erb
View
@@ -0,0 +1 @@
+FeedbackForm.updateWithResponse({ success: <%=raw @success_message.to_json %>, error: <%=raw @error_message.to_json %> });
8 config/locales/feedback_popup.en.yml
View
@@ -0,0 +1,8 @@
+
+en:
+ feedback_popup:
+ title: "Feedback"
+ send_button: "Send"
+ message_sent: "Thanks!"
+ email:
+ subject: "Feedback received"
7 config/routes.rb
View
@@ -0,0 +1,7 @@
+Rails.application.routes.draw do
+ namespace :feedback_popup do
+ resources :messages, :only => :create
+ end
+ match 'feedback' => 'feedback_popup/messages#new'
+end
+
14 feedback_popup.gemspec
View
@@ -7,16 +7,16 @@ require "feedback_popup/version"
Gem::Specification.new do |s|
s.name = "feedback_popup"
s.version = FeedbackPopup::VERSION
- s.authors = ["TODO: Your name"]
- s.email = ["TODO: Your email"]
- s.homepage = "TODO"
- s.summary = "TODO: Summary of FeedbackPopup."
- s.description = "TODO: Description of FeedbackPopup."
+ s.authors = ["Levente Bagi"]
+ s.email = ["bagilevi@gmail.com"]
+ s.homepage = "https://github.com/peerpost/feedback_popup"
+ s.summary = "Simple feedback popup for Rails 3 applications."
+ s.description = "Simple feedback popup for Rails 3 applications."
- s.files = Dir["{app,config,db,lib}/**/*"] + ["MIT-LICENSE", "Rakefile", "README.rdoc"]
+ s.files = Dir["{app,config,db,lib}/**/*"] + ["MIT-LICENSE", "Rakefile", "README.md"]
s.test_files = Dir["test/**/*"]
- s.add_dependency "rails", "~> 3.2.3"
+ s.add_dependency "rails", "~> 3.0"
s.add_development_dependency "sqlite3"
end
22 lib/feedback_popup.rb
View
@@ -1,2 +1,24 @@
module FeedbackPopup
+ class Engine < Rails::Engine
+
+ initializer 'feedback_popup.action_controller' do |app|
+ ActiveSupport.on_load :action_controller do
+ helper FeedbackPopup::FeedbackPopupHelper
+ end
+ end
+
+ end
+
+ mattr_accessor :mail_from
+ mattr_accessor :mail_to
+
+ # Makes possible configuration with block:
+ #
+ # FeedbackPopup.setup do |config|
+ # config.mail_from = "dummy@example.com"
+ # config.mail_to = "dummy@example.com"
+ # end
+ def self.setup
+ yield self
+ end
end
1  test/dummy/app/assets/javascripts/application.js
View
@@ -12,4 +12,5 @@
//
//= require jquery
//= require jquery_ujs
+//= require feedback_popup
//= require_tree .
1  test/dummy/app/assets/stylesheets/application.css
View
@@ -9,5 +9,6 @@
* compiled file, but it's generally better to create a new file per style scope.
*
*= require_self
+ *= require feedback_popup
*= require_tree .
*/
4 test/dummy/app/controllers/main_controller.rb
View
@@ -0,0 +1,4 @@
+class MainController < ApplicationController
+ def index
+ end
+end
1  test/dummy/app/views/main/index.html.erb
View
@@ -0,0 +1 @@
+<%= feedback_popup %>
12 test/dummy/config/application.rb
View
@@ -51,6 +51,18 @@ class Application < Rails::Application
# Version of your assets, change this if you want to expire all your assets
config.assets.version = '1.0'
+
+ ActionMailer::Base.smtp_settings = {
+ :address => 'smtp.gmail.com',
+ :port => '587',
+ :domain => 'gmail.com',
+ :authentication => :plain,
+ :user_name => ENV['GMAIL_USERNAME'],
+ :password => ENV['GMAIL_PASSWORD'],
+ :enable_starttls_auto => true
+ }
+ ActionMailer::Base.delivery_method = :smtp
+ config.action_mailer.raise_delivery_errors = true
end
end
7 test/dummy/config/initializers/feedback_popup.rb
View
@@ -0,0 +1,7 @@
+FeedbackPopup.setup do |config|
+
+ config.mail_from = ENV['GMAIL_USERNAME']
+ config.mail_to = ENV['GMAIL_USERNAME']
+
+end
+
3  test/dummy/config/routes.rb
View
@@ -1,4 +1,7 @@
Dummy::Application.routes.draw do
+
+ root :to => "main#index"
+
# The priority is based upon order of creation:
# first created -> highest priority.
Please sign in to comment.
Something went wrong with that request. Please try again.