bcms_feedback_form 1.0.1 → 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.markdown +3 -2
- data/app/controllers/cms/feedback_forms_controller.rb +39 -1
- data/app/controllers/feedback_forms_controller.rb +15 -7
- data/app/models/feedback_form.rb +2 -0
- data/app/models/feedback_submission.rb +8 -0
- data/app/views/cms/feedback_forms/render.html.erb +3 -0
- data/db/migrate/20100315174506_create_feedback_submissions.rb +18 -0
- data/lib/bcms_feedback_form/routes.rb +1 -0
- data/rails/init.rb +1 -0
- metadata +4 -2
data/README.markdown
CHANGED
@@ -5,8 +5,9 @@ Provides a feedback form content block protected by Recaptcha. It also:
|
|
5
5
|
* Allows you to specific the thank you message,
|
6
6
|
* Gives you the ability to create a custom form,
|
7
7
|
* Requires that you register at recaptcha.net and create an API key,
|
8
|
-
* Uses prototype to dynamically swap out the form in-place with a thank you message, allowing this to work fine in a statically cached environment
|
9
|
-
* Includes the recaptcha plugin
|
8
|
+
* Uses prototype to dynamically swap out the form in-place with a thank you message, allowing this to work fine in a statically cached environment,
|
9
|
+
* Includes the recaptcha plugin,
|
10
|
+
* Gives you a CSV download for form submissions (as of 1.0.2).
|
10
11
|
|
11
12
|
## Installation
|
12
13
|
|
@@ -1,2 +1,40 @@
|
|
1
1
|
class Cms::FeedbackFormsController < Cms::ContentBlockController
|
2
|
-
|
2
|
+
|
3
|
+
def download
|
4
|
+
@feedback_form = FeedbackForm.find(params[:id])
|
5
|
+
render_csv(@feedback_form.feedback_submissions)
|
6
|
+
end
|
7
|
+
|
8
|
+
def render_csv(objects)
|
9
|
+
columns = {}
|
10
|
+
rows = []
|
11
|
+
|
12
|
+
# Iterate through to find all the possible columns, just in case multiple versions of a form have been submitted.
|
13
|
+
objects.each do |obj|
|
14
|
+
row = YAML.load(obj.feedback_content)
|
15
|
+
rows << row
|
16
|
+
row['user_agent'] = obj.user_agent
|
17
|
+
row['ip_address'] = obj.ip_address
|
18
|
+
row.keys.each do |column|
|
19
|
+
columns[column] = 1
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
csv_output = ''
|
24
|
+
sorted_columns = columns.keys.sort
|
25
|
+
CSV::Writer.generate(csv_output) do |csv|
|
26
|
+
csv << sorted_columns
|
27
|
+
rows.each do |row|
|
28
|
+
row_array = []
|
29
|
+
sorted_columns.each do |col|
|
30
|
+
row_array << row[col] || ''
|
31
|
+
end
|
32
|
+
csv << row_array
|
33
|
+
end
|
34
|
+
end
|
35
|
+
send_data(csv_output,
|
36
|
+
:type => 'application/octet-stream',
|
37
|
+
:filename => "feedback-submissions-#{Time.now.to_s(:number)}.csv")
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
@@ -1,21 +1,29 @@
|
|
1
1
|
class FeedbackFormsController < ApplicationController
|
2
2
|
def submit
|
3
3
|
feedback_form = FeedbackForm.find(params[:id])
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
4
|
+
|
5
|
+
if (feedback_form.use_recaptcha == false) || verify_recaptcha
|
6
|
+
begin
|
7
|
+
FeedbackSubmission.create(
|
8
|
+
:feedback_form => feedback_form,
|
9
|
+
:feedback_content => params[:feedback_form].to_yaml,
|
10
|
+
:user_agent => request.user_agent,
|
11
|
+
:ip_address => request.remote_ip
|
12
|
+
)
|
13
|
+
rescue Exception => e
|
14
|
+
#Failed, but it's not a huge deal.
|
9
15
|
end
|
10
|
-
else
|
11
16
|
Feedback.deliver_feedback(feedback_form, params)
|
17
|
+
else
|
18
|
+
raise
|
12
19
|
end
|
20
|
+
|
13
21
|
if request.xhr?
|
14
22
|
render :text => ((feedback_form.thank_you.blank?) ? 'Thanks!' : feedback_form.thank_you), :layout => false and return
|
15
23
|
else
|
16
24
|
redirect_to((params[:_redirect_to].blank?) ? '/' : params[:_redirect_to]) and return
|
17
25
|
end
|
18
|
-
rescue
|
26
|
+
rescue Exception => e
|
19
27
|
if request.xhr?
|
20
28
|
render :text => 'There seems to have been an error. Please try again', :layout => false and return
|
21
29
|
else
|
data/app/models/feedback_form.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
class FeedbackForm < ActiveRecord::Base
|
2
2
|
acts_as_content_block
|
3
|
+
has_many :feedback_submissions
|
4
|
+
|
3
5
|
validates_length_of :send_to, :maximum => 500
|
4
6
|
validates_length_of :subject, :maximum => 200, :allow_blank => true
|
5
7
|
validates_length_of :from, :maximum => 100, :allow_blank => true
|
@@ -0,0 +1,8 @@
|
|
1
|
+
class FeedbackSubmission < ActiveRecord::Base
|
2
|
+
belongs_to :feedback_form
|
3
|
+
|
4
|
+
validates_length_of :feedback_content, :maximum => 256.kilobytes, :allow_blank => true
|
5
|
+
validates_length_of :user_agent, :maximum => 1000, :allow_blank => true
|
6
|
+
validates_length_of :ip_address, :maximum => 20, :allow_blank => true
|
7
|
+
|
8
|
+
end
|
@@ -1,4 +1,7 @@
|
|
1
1
|
<div class="feedback-form">
|
2
|
+
<% if @mode == 'edit' %>
|
3
|
+
<div class="download-submissions"><%= @content_block.feedback_submissions.length %> submitted. <%= link_to('download as CSV', :controller => '/cms/feedback_forms', :action => :download, :id => @content_block ) %></div>
|
4
|
+
<% end %>
|
2
5
|
<%= @content_block.description %>
|
3
6
|
<div id="feedback-form-<%= @content_block.id %>">
|
4
7
|
<% form_remote_tag(:url => url_for(:controller => '/feedback_forms', :action => :submit, :id => @content_block.id), :update => "feedback-form-#{@content_block.id}" ) do -%>
|
@@ -0,0 +1,18 @@
|
|
1
|
+
class CreateFeedbackSubmissions < ActiveRecord::Migration
|
2
|
+
def self.up
|
3
|
+
create_table :feedback_submissions do |t|
|
4
|
+
t.references :feedback_form
|
5
|
+
t.string :feedback_content, :limit => 256.kilobytes
|
6
|
+
t.string :user_agent, :limit => 1000
|
7
|
+
t.string :ip_address, :limit => 20
|
8
|
+
t.timestamps
|
9
|
+
end
|
10
|
+
add_index :feedback_submissions, :feedback_form_id
|
11
|
+
add_index :feedback_submissions, :user_agent
|
12
|
+
add_index :feedback_submissions, :ip_address
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.down
|
16
|
+
drop_table :feedback_submissions
|
17
|
+
end
|
18
|
+
end
|
@@ -2,6 +2,7 @@ module Cms::Routes
|
|
2
2
|
def routes_for_bcms_feedback_form
|
3
3
|
self.connect 'feedback_forms/:action/:id.:format', :controller => 'feedback_forms'
|
4
4
|
namespace(:cms) do |cms|
|
5
|
+
cms.connect 'feedback_forms/download/:id',:controller => 'feedback_forms', :action => :download, :conditions => {:method => :get}
|
5
6
|
cms.content_blocks :feedback_forms
|
6
7
|
end
|
7
8
|
end
|
data/rails/init.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bcms_feedback_form
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daniel Collis-Puro
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2010-03-
|
12
|
+
date: 2010-03-15 00:00:00 -04:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|
@@ -34,7 +34,9 @@ files:
|
|
34
34
|
- app/controllers/cms/feedback_forms_controller.rb
|
35
35
|
- app/models/feedback.rb
|
36
36
|
- app/models/feedback_form.rb
|
37
|
+
- app/models/feedback_submission.rb
|
37
38
|
- db/migrate/20100312161745_create_feedback_forms.rb
|
39
|
+
- db/migrate/20100315174506_create_feedback_submissions.rb
|
38
40
|
- lib/bcms_feedback_form.rb
|
39
41
|
- lib/bcms_feedback_form/routes.rb
|
40
42
|
- rails/init.rb
|