tb_inquiries 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (123) hide show
  1. checksums.yaml +7 -0
  2. data/MIT-LICENSE +20 -0
  3. data/README.markdown +76 -0
  4. data/Rakefile +28 -0
  5. data/app/assets/images/spud/admin/contacts_thumb.png +0 -0
  6. data/app/assets/javascripts/spud/admin/inquiries.js +8 -0
  7. data/app/assets/javascripts/spud/inquiries/sitemaps.js +2 -0
  8. data/app/assets/stylesheets/spud/admin/inquiries.css +4 -0
  9. data/app/assets/stylesheets/spud/inquiries/sitemaps.css +4 -0
  10. data/app/controllers/contacts_controller.rb +82 -0
  11. data/app/controllers/spud/admin/inquiries_controller.rb +38 -0
  12. data/app/controllers/spud/admin/inquiry_forms_controller.rb +58 -0
  13. data/app/controllers/spud/inquiries/sitemaps_controller.rb +7 -0
  14. data/app/helpers/contacts_helper.rb +3 -0
  15. data/app/mailers/spud/inquiry_mailer.rb +10 -0
  16. data/app/models/spud_inquiry.rb +46 -0
  17. data/app/models/spud_inquiry_field.rb +13 -0
  18. data/app/models/spud_inquiry_form.rb +27 -0
  19. data/app/models/spud_inquiry_form_field.rb +21 -0
  20. data/app/views/contacts/_show.html.erb +45 -0
  21. data/app/views/contacts/show.html.erb +4 -0
  22. data/app/views/contacts/show.js.erb +1 -0
  23. data/app/views/contacts/thankyou.html.erb +2 -0
  24. data/app/views/contacts/thankyou.js.erb +1 -0
  25. data/app/views/layouts/spud/inquiries/detail.html.erb +6 -0
  26. data/app/views/spud/admin/inquiries/index.html.erb +30 -0
  27. data/app/views/spud/admin/inquiries/show.html.erb +8 -0
  28. data/app/views/spud/admin/inquiry_forms/_form.html.erb +52 -0
  29. data/app/views/spud/admin/inquiry_forms/_spud_inquiry_form_field_fields.html.erb +56 -0
  30. data/app/views/spud/admin/inquiry_forms/edit.html.erb +6 -0
  31. data/app/views/spud/admin/inquiry_forms/index.html.erb +22 -0
  32. data/app/views/spud/admin/inquiry_forms/new.html.erb +9 -0
  33. data/app/views/spud/inquiries/sitemaps/show.xml.builder +16 -0
  34. data/app/views/spud/inquiry_mailer/inquiry_notification.html.erb +15 -0
  35. data/app/views/spud/inquiry_mailer/inquiry_notification.text.erb +7 -0
  36. data/config/routes.rb +16 -0
  37. data/db/migrate/20120117133405_create_spud_inquiries.rb +8 -0
  38. data/db/migrate/20120117133412_create_spud_inquiry_fields.rb +13 -0
  39. data/db/migrate/20120121194439_create_spud_inquiry_forms.rb +9 -0
  40. data/db/migrate/20120121194447_create_spud_inquiry_form_fields.rb +12 -0
  41. data/db/migrate/20120122173829_add_field_order_to_spud_inquiry_form_fields.rb +7 -0
  42. data/db/migrate/20120126132407_add_spud_inquiry_form_id_to_spud_inquiries.rb +11 -0
  43. data/db/migrate/20120126132522_add_recipients_to_spud_inquiry_forms.rb +6 -0
  44. data/db/migrate/20120127023335_add_url_name_to_spud_inquiry_forms.rb +6 -0
  45. data/db/migrate/20120413124900_change_inquiry_form_fields_column.rb +9 -0
  46. data/db/migrate/20121228145215_add_thank_you_content_to_spud_inquiry_form.rb +5 -0
  47. data/db/migrate/20130627121030_add_placeholder_to_spud_inquiry_form_fields.rb +5 -0
  48. data/db/migrate/20131111143656_add_submit_title_to_spud_inquiry_form.rb +5 -0
  49. data/db/migrate/20131111143945_add_field_name_to_spud_inquiry_form_fields.rb +5 -0
  50. data/db/migrate/20131111144731_add_class_name_to_spud_inquiry_form_fields.rb +5 -0
  51. data/db/migrate/20131204163221_add_field_name_to_spud_inquiry_fields.rb +5 -0
  52. data/lib/spud_inquiries/configuration.rb +16 -0
  53. data/lib/spud_inquiries/engine.rb +28 -0
  54. data/lib/spud_inquiries/liquid_form.rb +47 -0
  55. data/lib/spud_inquiries/version.rb +5 -0
  56. data/lib/tasks/spud_inquiries_tasks.rake +4 -0
  57. data/lib/tb_inquiries.rb +7 -0
  58. data/spec/controllers/contacts_controller_spec.rb +69 -0
  59. data/spec/controllers/spud/admin/inquiries_controller_spec.rb +55 -0
  60. data/spec/controllers/spud/admin/inquiry_forms_controller_spec.rb +98 -0
  61. data/spec/controllers/spud/inquiries/sitemaps_controller_spec.rb +24 -0
  62. data/spec/dummy/README.rdoc +261 -0
  63. data/spec/dummy/Rakefile +7 -0
  64. data/spec/dummy/app/assets/javascripts/application.js +15 -0
  65. data/spec/dummy/app/assets/stylesheets/application.css +13 -0
  66. data/spec/dummy/app/controllers/application_controller.rb +3 -0
  67. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  68. data/spec/dummy/app/views/layouts/application.html.erb +14 -0
  69. data/spec/dummy/config/application.rb +57 -0
  70. data/spec/dummy/config/boot.rb +10 -0
  71. data/spec/dummy/config/database.yml +9 -0
  72. data/spec/dummy/config/environment.rb +5 -0
  73. data/spec/dummy/config/environments/development.rb +37 -0
  74. data/spec/dummy/config/environments/production.rb +67 -0
  75. data/spec/dummy/config/environments/test.rb +44 -0
  76. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  77. data/spec/dummy/config/initializers/inflections.rb +15 -0
  78. data/spec/dummy/config/initializers/mime_types.rb +5 -0
  79. data/spec/dummy/config/initializers/secret_token.rb +8 -0
  80. data/spec/dummy/config/initializers/session_store.rb +8 -0
  81. data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
  82. data/spec/dummy/config/locales/en.yml +5 -0
  83. data/spec/dummy/config/routes.rb +3 -0
  84. data/spec/dummy/config.ru +4 -0
  85. data/spec/dummy/db/migrate/20120610131537_create_spud_admin_permissions.spud_core.rb +12 -0
  86. data/spec/dummy/db/migrate/20120610131538_create_spud_users.spud_core.rb +30 -0
  87. data/spec/dummy/db/migrate/20120610131539_add_time_zone_to_spud_user.spud_core.rb +7 -0
  88. data/spec/dummy/db/migrate/20120610131540_add_scope_to_spud_admin_permissions.spud_core.rb +7 -0
  89. data/spec/dummy/db/migrate/20120610131541_create_spud_user_settings.spud_core.rb +12 -0
  90. data/spec/dummy/db/migrate/20140109151036_create_spud_roles.tb_core.rb +11 -0
  91. data/spec/dummy/db/migrate/20140109151037_create_spud_permissions.tb_core.rb +11 -0
  92. data/spec/dummy/db/migrate/20140109151038_create_spud_role_permissions.tb_core.rb +12 -0
  93. data/spec/dummy/db/migrate/20140109151039_drop_spud_admin_permissions.tb_core.rb +16 -0
  94. data/spec/dummy/db/migrate/20140109151040_create_spud_inquiries.spud_inquiries.rb +9 -0
  95. data/spec/dummy/db/migrate/20140109151041_create_spud_inquiry_fields.spud_inquiries.rb +14 -0
  96. data/spec/dummy/db/migrate/20140109151042_create_spud_inquiry_forms.spud_inquiries.rb +10 -0
  97. data/spec/dummy/db/migrate/20140109151043_create_spud_inquiry_form_fields.spud_inquiries.rb +13 -0
  98. data/spec/dummy/db/migrate/20140109151044_add_field_order_to_spud_inquiry_form_fields.spud_inquiries.rb +8 -0
  99. data/spec/dummy/db/migrate/20140109151045_add_spud_inquiry_form_id_to_spud_inquiries.spud_inquiries.rb +12 -0
  100. data/spec/dummy/db/migrate/20140109151046_add_recipients_to_spud_inquiry_forms.spud_inquiries.rb +7 -0
  101. data/spec/dummy/db/migrate/20140109151047_add_url_name_to_spud_inquiry_forms.spud_inquiries.rb +7 -0
  102. data/spec/dummy/db/migrate/20140109151048_change_inquiry_form_fields_column.spud_inquiries.rb +10 -0
  103. data/spec/dummy/db/migrate/20140109151049_add_thank_you_content_to_spud_inquiry_form.spud_inquiries.rb +6 -0
  104. data/spec/dummy/db/migrate/20140109151050_add_placeholder_to_spud_inquiry_form_fields.spud_inquiries.rb +6 -0
  105. data/spec/dummy/db/migrate/20140109151051_add_submit_title_to_spud_inquiry_form.spud_inquiries.rb +6 -0
  106. data/spec/dummy/db/migrate/20140109151052_add_field_name_to_spud_inquiry_form_fields.spud_inquiries.rb +6 -0
  107. data/spec/dummy/db/migrate/20140109151053_add_class_name_to_spud_inquiry_form_fields.spud_inquiries.rb +6 -0
  108. data/spec/dummy/db/migrate/20140109151054_add_field_name_to_spud_inquiry_fields.spud_inquiries.rb +6 -0
  109. data/spec/dummy/db/migrate/20140110151647_create_tb_liquid_spud_liquid_tags.tb_liquid.rb +13 -0
  110. data/spec/dummy/db/schema.rb +143 -0
  111. data/spec/dummy/log/test.log +425 -0
  112. data/spec/dummy/public/404.html +26 -0
  113. data/spec/dummy/public/422.html +26 -0
  114. data/spec/dummy/public/500.html +25 -0
  115. data/spec/dummy/public/favicon.ico +0 -0
  116. data/spec/dummy/script/rails +6 -0
  117. data/spec/models/spud_inquiry_field_spec.rb +18 -0
  118. data/spec/models/spud_inquiry_form_field_spec.rb +36 -0
  119. data/spec/models/spud_inquiry_form_spec.rb +28 -0
  120. data/spec/models/spud_inquiry_spec.rb +22 -0
  121. data/spec/spec_helper.rb +49 -0
  122. data/spec/support/authlogic_helper.rb +2 -0
  123. metadata +384 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: b48608817ae6cafbbde4917e1f9ad1ce8afbbe1d
4
+ data.tar.gz: 285c8b320f48e9b799ee2b41478eac1bb7414716
5
+ SHA512:
6
+ metadata.gz: 771744fead4f548d81cccb56775d88656342efa6fa7c437df27f4b6f716d950833295490427835c5328690c19810f15eabe41bc8b0e14c0e3424d68d5e7d9e17
7
+ data.tar.gz: 2f7fc8f425ccc1c4c3cb38a64e7be3bc6d52e9a4896480d7b55ae20e031c075b31381764b2694177cf63c3702e1252d5af994494b2036c83feded6b4ea505077
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2012 YOURNAME
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.markdown ADDED
@@ -0,0 +1,76 @@
1
+ IMPORTANT NOTE
2
+ ==============
3
+
4
+ This engine is under review and will likley be replaced at some point in the future. Because of this, I have no plans to release tb_inquiries to Rubygems.org. In the meantime you may continue to reference this gem in your gemfile via git.
5
+
6
+ Spud Inquiries
7
+ ==============
8
+ Spud Inquiries is a Spud Engine designed to make it easier to generate contact forms and send email notifications when these inquiries occur. This engine works great with the spud_cms engine but it is fully capable of running standalone with spud_core.
9
+
10
+ Installation/Usage
11
+ ------------------
12
+
13
+ 1. In your Gemfile add the following
14
+
15
+ gem 'tb_core'
16
+ gem 'tb_inquiries', :git => "git@bitbucket.org:westlakedesign/tb_inquiries.git"
17
+
18
+ 2. Run bundle install
19
+ 3. Copy in database migrations to your new rails project
20
+
21
+ bundle exec rake railties:install:migrations
22
+ rake db:migrate
23
+
24
+ 4. run a rails server instance and point your browser to /spud/admin
25
+
26
+ Creating a Contact Form
27
+ -----------------------
28
+ Creating a contact form is still fairly new and improvements will be made as time goes on. To create a new form, go to the Inquiries app inside of your spud admin panel. Click the forms button to manage various forms. Here you can set the form name, any content (html safe) you wish to render before the form renders, and add the form fields to the form (Email address is currently at the top of all forms and not adjustable).
29
+
30
+ Routing to the Inquiries Engine
31
+ -------------------------------
32
+ By default the inquiries gem routes the "/contact" url to the form named "contact". However this and other configuration options can be changed as shown below.
33
+
34
+
35
+ Spud::Inquiries.configure do |config|
36
+ config.enable_routes = true
37
+ config.default_contact_form = "contact"
38
+ config.base_layout = "application"
39
+ config.from_address = "no-reply@example.org"
40
+ end
41
+
42
+
43
+
44
+ Where "contact" is the name of the form you wish to use (downcased,parameterized,hyphenated)
45
+
46
+ Inquiry will default render to the 'application' layout of your application. You can change this by adjusting the configuration option called "base_layout". More configuration options can be found in the Wiki "Configuration" page.
47
+
48
+ Injecting Forms into Spud CMS Pages
49
+ -----------------------------------
50
+ Spud Supports the use of liquid tags to inject dynamic content into pages. In order to inject a contact form into a spud page simply use the following liquid tag in your content:
51
+
52
+ ```html
53
+ {% inquiry Contact %}
54
+ ```
55
+ The above example will inject a form named "Contact" into your content.
56
+
57
+
58
+ Testing
59
+ -----------------
60
+
61
+ Spud uses RSpec for testing. Get the tests running with a few short commands:
62
+
63
+ 1. Create and migrate the databases:
64
+
65
+ rake db:create
66
+ rake db:migrate
67
+
68
+ 2. Load the schema in to the test database:
69
+
70
+ rake app:db:test:prepare
71
+
72
+ 3. Run the tests with RSpec
73
+
74
+ rspec spec
75
+
76
+ After the tests have completed the current code coverage stats is available by opening ```/coverage/index.html``` in a browser.
data/Rakefile ADDED
@@ -0,0 +1,28 @@
1
+ #!/usr/bin/env rake
2
+ begin
3
+ require 'bundler/setup'
4
+ rescue LoadError
5
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
6
+ end
7
+ begin
8
+ require 'rdoc/task'
9
+ rescue LoadError
10
+ require 'rdoc/rdoc'
11
+ require 'rake/rdoctask'
12
+ RDoc::Task = Rake::RDocTask
13
+ end
14
+
15
+ RDoc::Task.new(:rdoc) do |rdoc|
16
+ rdoc.rdoc_dir = 'rdoc'
17
+ rdoc.title = 'SpudInquiries'
18
+ rdoc.options << '--line-numbers'
19
+ rdoc.rdoc_files.include('README.rdoc')
20
+ rdoc.rdoc_files.include('lib/**/*.rb')
21
+ end
22
+
23
+ APP_RAKEFILE = File.expand_path("../spec/dummy/Rakefile", __FILE__)
24
+ load 'rails/tasks/engine.rake'
25
+
26
+ Bundler::GemHelper.install_tasks
27
+
28
+ require 'rake'
@@ -0,0 +1,8 @@
1
+ $(function() {
2
+ var initWysiwym = function() {
3
+ $('textarea.wysiwym').wymeditor({
4
+ basePath:'/assets/wymeditor/'
5
+ });
6
+ }
7
+ initWysiwym();
8
+ });
@@ -0,0 +1,2 @@
1
+ // Place all the behaviors and hooks related to the matching controller here.
2
+ // All this logic will automatically be available in application.js.
@@ -0,0 +1,4 @@
1
+ /*
2
+ Place all the styles related to the matching controller here.
3
+ They will automatically be included in application.css.
4
+ */
@@ -0,0 +1,4 @@
1
+ /*
2
+ Place all the styles related to the matching controller here.
3
+ They will automatically be included in application.css.
4
+ */
@@ -0,0 +1,82 @@
1
+ class ContactsController < ApplicationController
2
+ skip_before_filter :verify_authenticity_token
3
+ layout Spud::Inquiries.base_layout
4
+ respond_to :html,:js
5
+ def show
6
+ url_name = !params[:id].blank? ? params[:id] : Spud::Inquiries.default_contact_form
7
+ @inquiry_form = SpudInquiryForm.where(:url_name => url_name).includes(:spud_inquiry_form_fields).first
8
+
9
+ if @inquiry_form.blank?
10
+ flash[:error] = "Contact Inquiry Form not found!"
11
+ redirect_to "/" and return
12
+ end
13
+ @spud_inquiry = SpudInquiry.new(:spud_inquiry_form_id => @inquiry_form.id)
14
+ @spud_inquiry.build_inquiry_form_fields()
15
+ end
16
+
17
+ def inquire
18
+ if !params[:other_email].blank?
19
+ flash[:error] = "You must be a robot! No robots allowed here!"
20
+ redirect_to request.referer || "/" and return
21
+ end
22
+ unless params[:spud_inquiry]
23
+ flash[:error] = "Inquiry Not Found!"
24
+ redirect_to request.referer || "/" and return
25
+ end
26
+ @inquiry_form = SpudInquiryForm.where(:id => params[:spud_inquiry][:spud_inquiry_form_id]).first
27
+ if @inquiry_form.blank?
28
+ flash[:error] = "Form Not Found!"
29
+ redirect_to request.referer || "/" and return
30
+ end
31
+ @spud_inquiry = SpudInquiry.new(:spud_inquiry_form_id => params[:spud_inquiry][:spud_inquiry_form_id])
32
+
33
+ @spud_inquiry.recipients = @inquiry_form.recipients
34
+ @spud_inquiry.subject = @inquiry_form.subject
35
+
36
+ @inquiry_form.spud_inquiry_form_fields.order(:field_order).each do |field|
37
+ val = params[:spud_inquiry][field.field_name]
38
+ if field.required && val.blank?
39
+ flash[:error] = "Not all required fields were entered"
40
+ @spud_inquiry.errors.add field.field_name,"is a required field"
41
+ end
42
+ @spud_inquiry.spud_inquiry_fields.new(:name => field.name, :field_name => field.field_name, :value => val)
43
+ end
44
+
45
+ if !@spud_inquiry.errors.empty?
46
+ respond_to do |format|
47
+ format.html {render :action => "show", :status => 422}
48
+ format.js { render "show.js.erb", :status => 422}
49
+ end
50
+ return
51
+ end
52
+ if @spud_inquiry.save
53
+ flash[:notice] = "Your inquiry was received!"
54
+ if !@spud_inquiry.recipients.blank?
55
+ Spud::InquiryMailer.inquiry_notification(@spud_inquiry).deliver
56
+ end
57
+ else
58
+ flash[:error] = "Whoops! Something went wrong. Please try again!"
59
+ respond_to do |format|
60
+ format.html {render :action => "show"}
61
+ format.js { render "show.js.erb"}
62
+ end
63
+ return
64
+ end
65
+ respond_to do |format|
66
+ format.html { redirect_to contact_thankyou_url }
67
+ format.js { render "thankyou.js.erb"}
68
+ end
69
+
70
+ end
71
+
72
+ def thankyou
73
+ render
74
+ end
75
+
76
+ private
77
+
78
+ def inquiry_params
79
+ parms.require(:spud_inquiry).permit(:spud_inquiry_form_id, :spud_inquiry_fields)
80
+ end
81
+
82
+ end
@@ -0,0 +1,38 @@
1
+ class Spud::Admin::InquiriesController < Admin::ApplicationController
2
+ belongs_to_spud_app :inquiries
3
+ add_breadcrumb "Inquiries", :spud_admin_inquiries_path
4
+ before_filter :load_inquiries, :only => [:edit,:update,:show,:destroy]
5
+
6
+ def index
7
+ @inquiries = SpudInquiry.order("created_at DESC").includes(:spud_inquiry_form, :spud_inquiry_fields).paginate :page => params[:page]
8
+ respond_with @inquiries
9
+ end
10
+
11
+ def show
12
+ add_breadcrumb "#{@inquiry.email || "Unknown"}", ''
13
+ respond_with @inquiry
14
+ end
15
+
16
+ def destroy
17
+ status = 500
18
+ if @inquiry.destroy
19
+ status = 200
20
+ end
21
+ respond_with @inquiry do |format|
22
+ format.js { render :status => status,:text => nil}
23
+ format.html {
24
+ flash[:error] = "Error removing inquiry!" if status == 500
25
+ flash[:notice] = "Inquiry removed!" if status == 200
26
+ redirect_to spud_admin_inquiries_path and return
27
+ }
28
+ end
29
+ end
30
+ private
31
+ def load_inquiries
32
+ @inquiry = SpudInquiry.where(:id => params[:id]).first
33
+ if @inquiry.blank?
34
+ flash[:error] = "Inquiry not found!"
35
+ redirect_to spud_admin_inquiries_path and return
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,58 @@
1
+ class Spud::Admin::InquiryFormsController < Admin::ApplicationController
2
+ belongs_to_spud_app :inquiries, :title => "Inquiry Forms"
3
+ add_breadcrumb "Inquiries", :spud_admin_inquiries_path
4
+ add_breadcrumb "Forms", :spud_admin_inquiry_forms_path
5
+ add_breadcrumb "New", '',:only => [:new, :create]
6
+ add_breadcrumb "Edit", '',:only => [:edit, :update]
7
+ before_filter :load_form,:only => [:edit,:update,:show,:destroy]
8
+ def index
9
+
10
+ @inquiry_forms = SpudInquiryForm.order(:name).paginate :page => params[:page]
11
+ respond_with @inquiry_forms
12
+ end
13
+
14
+ def new
15
+ @inquiry_form = SpudInquiryForm.new
16
+ respond_with @inquiry_form
17
+ end
18
+
19
+ def create
20
+ @inquiry_form = SpudInquiryForm.new(form_params)
21
+ flash[:notice] = "Form saved successfully!" if @inquiry_form.save
22
+
23
+ respond_with @inquiry_form,:location => spud_admin_inquiry_forms_url
24
+ end
25
+
26
+ def edit
27
+ respond_with @inquiry_form
28
+ end
29
+
30
+ def update
31
+ flash[:notice] = "Form saved successfully!" if @inquiry_form.update_attributes(form_params)
32
+ if Spud::Inquiries.enable_action_caching
33
+ #noop
34
+ end
35
+ respond_with @inquiry_form, :location => spud_admin_inquiry_forms_url
36
+ end
37
+
38
+ def destroy
39
+ flash[:notice] = "Inquiry form removed!" if @inquiry_form.destroy
40
+ if Spud::Inquiries.enable_action_caching
41
+ #noop
42
+ end
43
+ respond_with @inquiry_form,:location => spud_admin_inquiry_forms_url
44
+ end
45
+ private
46
+ def load_form
47
+ @inquiry_form = SpudInquiryForm.where(:id => params[:id]).first
48
+ if @inquiry_form.blank?
49
+ flash[:error] = "Inquiry Form not found!"
50
+ redirect_to spud_admin_inquiry_forms_url() and return
51
+ end
52
+ end
53
+
54
+ def form_params
55
+ params.require(:spud_inquiry_form).permit(:name, :url_name, :recipients, :content, :subject, :thank_you_content, :submit_title, :spud_inquiry_form_fields_attributes => [:id, :name, :options, :default_value, :field_type, :spud_inquiry_form_id, :field_order, :required, :placeholder, :class_name, :_destroy])
56
+ end
57
+
58
+ end
@@ -0,0 +1,7 @@
1
+ class Spud::Inquiries::SitemapsController < Spud::ApplicationController
2
+ respond_to :xml
3
+ def show
4
+ @forms = SpudInquiryForm.all
5
+ respond_with @forms
6
+ end
7
+ end
@@ -0,0 +1,3 @@
1
+ module ContactsHelper
2
+
3
+ end
@@ -0,0 +1,10 @@
1
+ class Spud::InquiryMailer < ActionMailer::Base
2
+
3
+
4
+ def inquiry_notification(inquiry)
5
+ @inquiry = inquiry
6
+ @url = spud_admin_inquiry_url(:id => @inquiry.id)
7
+ # @url = "/spud/admin/inquiries/#{@inquiry.id}"
8
+ mail(:from =>Spud::Inquiries.from_address,:to => @inquiry.recipients.split(","), :subject => @inquiry.subject.blank? ? "No Subject" : @inquiry.subject)
9
+ end
10
+ end
@@ -0,0 +1,46 @@
1
+ class SpudInquiry < ActiveRecord::Base
2
+
3
+ has_many :spud_inquiry_fields, :dependent => :destroy
4
+ belongs_to :spud_inquiry_form
5
+ accepts_nested_attributes_for :spud_inquiry_fields, :reject_if => lambda { |a| a[:name].blank? }
6
+
7
+ def email
8
+ email_field_names = ['email', 'email_address', 'email address', 'emailaddress', 'e-mail']
9
+ email_field = self.spud_inquiry_fields.load.find do |field|
10
+ email_field_names.include?(field.name.downcase)
11
+ end
12
+ if !email_field.blank?
13
+ return email_field.value
14
+ end
15
+ return "Unknown Sender"
16
+ end
17
+
18
+ def build_inquiry_form_fields()
19
+ if self.spud_inquiry_form
20
+ self.spud_inquiry_form.spud_inquiry_form_fields.order(:field_order).each do |field|
21
+ self.spud_inquiry_fields.new(:name => field.name, :field_name => field.field_name)
22
+ end
23
+ end
24
+ end
25
+
26
+ # If a property is not defined here we want to check the dynamic fields list
27
+ def method_missing(sym, *args)
28
+ inquiry_field = self.spud_inquiry_fields.select{ |field| field.field_name == sym.to_s}
29
+ if inquiry_field.any?
30
+ return inquiry_field[0].value
31
+ end
32
+ super
33
+ end
34
+
35
+ def respond_to?(sym, include_all=false)
36
+ default_responds = super
37
+ if !default_responds
38
+ inquiry_field = self.spud_inquiry_fields.select{ |field| field.field_name == sym.to_s}
39
+ if inquiry_field.any?
40
+ return true
41
+ end
42
+ end
43
+ return default_responds
44
+ end
45
+
46
+ end
@@ -0,0 +1,13 @@
1
+ class SpudInquiryField < ActiveRecord::Base
2
+ belongs_to :spud_inquiry
3
+ before_save :serialize_value
4
+
5
+ private
6
+
7
+ def serialize_value
8
+ if self.value.is_a? Array
9
+ self.value = self.value.reject(&:blank?).join(', ')
10
+ end
11
+ end
12
+
13
+ end
@@ -0,0 +1,27 @@
1
+ class SpudInquiryForm < ActiveRecord::Base
2
+ has_many :spud_inquiries, :dependent => :nullify
3
+ has_many :spud_inquiry_form_fields, ->{ order('field_order asc') }, :dependent => :destroy
4
+
5
+ accepts_nested_attributes_for :spud_inquiry_form_fields, :reject_if => lambda { |a| a[:name].blank? }, :allow_destroy => true
6
+
7
+ validates :name,:presence => true,:uniqueness => true
8
+ validates :url_name,:presence => true, :uniqueness => true
9
+ before_validation :generate_url_name
10
+
11
+ acts_as_spud_liquid_tag :inquiry, :name
12
+
13
+ def generate_url_name
14
+ if !self.name.blank?
15
+ self.url_name = self.name.gsub(/[^a-zA-Z0-9\ ]/," ").gsub(/\ \ +/," ").gsub(/\ /,"-").downcase
16
+ end
17
+ end
18
+
19
+ def submit_title_text
20
+ if self.submit_title.blank?
21
+ 'Submit'
22
+ else
23
+ self.submit_title
24
+ end
25
+ end
26
+
27
+ end
@@ -0,0 +1,21 @@
1
+ class SpudInquiryFormField < ActiveRecord::Base
2
+ belongs_to :spud_inquiry_form
3
+ validates :name,:presence => true
4
+ validates :field_type,:presence => true
5
+ # validates :spud_inquiry_form_id, :presence => true
6
+
7
+ before_save :update_field_name
8
+
9
+ def options_list
10
+ return [] if self.options.blank?
11
+ self.options.split(/\,*?(".*?")\,*?/).map{|x| x=~/^".*"$/ ? x.gsub(/\"/,"") : x.split(',')}.flatten.select{|p| !p.strip.blank?}
12
+ end
13
+
14
+ def update_field_name
15
+ if self.name.blank?
16
+ return
17
+ end
18
+ self.field_name = self.name.parameterize.underscore
19
+ end
20
+
21
+ end
@@ -0,0 +1,45 @@
1
+ <%= form_for spud_inquiry, :url => contact_inquire_path, :html => {:class => "form-horizontal", :id => "inquiry_form_#{spud_inquiry_form.id}"}, :remote => true do |f| %>
2
+
3
+ <% if defined?(error_messages_for) %>
4
+ <%= error_messages_for(spud_inquiry)%>
5
+ <% end %>
6
+
7
+ <fieldset>
8
+ <%=f.hidden_field :spud_inquiry_form_id,:value => spud_inquiry_form.id%>
9
+
10
+ <% spud_inquiry_form.spud_inquiry_form_fields.each do |field| %>
11
+ <div class="control-group type_<%=field.field_type%> <%=field.class_name ? field.class_name : ''%>">
12
+ <%=f.label field.field_name, field.name,:class => "control-label"%>
13
+ <div class="controls">
14
+ <%
15
+ case field.field_type
16
+ when '0'
17
+ concat f.text_field field.field_name, :placeholder => field.placeholder
18
+ when '1'
19
+ if field.options_list.count > 0
20
+ concat f.collection_check_boxes field.field_name, field.options_list, :to_s, :to_s
21
+ else
22
+ concat f.check_box field.field_name
23
+ end
24
+ when '2'
25
+ concat f.text_area field.field_name, :rows => 5, :cols => 70, :placeholder => field.placeholder
26
+ when '3'
27
+ concat f.select field.field_name, options_for_select(field.options_list, spud_inquiry.send(field.field_name)), {:include_blank => true}
28
+ when '4'
29
+ concat f.collection_radio_buttons field.field_name, field.options_list, :to_s, :to_s
30
+ end
31
+ %>
32
+ </div>
33
+ </div>
34
+ <%end%>
35
+ <div class="spud_inquiry_hide">
36
+ <label id='other_email_label' for='other_email'>Please leave blank:</label>
37
+ <input type='text' name='other_email' id='other_email'>
38
+ </div>
39
+ <div class="form-actions">
40
+ <%=f.submit spud_inquiry_form.submit_title_text, :class => "btn btn-primary"%>
41
+ </div>
42
+
43
+ </fieldset>
44
+
45
+ <% end %>
@@ -0,0 +1,4 @@
1
+ <h2><%=@inquiry_form.name%></h2>
2
+ <%= @inquiry_form.content.html_safe if !@inquiry_form.content.blank? %>
3
+
4
+ <%= render :partial => 'show', :locals => {:spud_inquiry_form => @inquiry_form, :spud_inquiry => @spud_inquiry} %>
@@ -0,0 +1 @@
1
+ $('#inquiry_form_<%=@inquiry_form.id%>').replaceWith("<%=escape_javascript(render :partial=>"show",:locals => {:spud_inquiry_form => @inquiry_form, :spud_inquiry => @spud_inquiry})%>");
@@ -0,0 +1,2 @@
1
+ <h2>Thank you</h2>
2
+ <p>Thank you for your inquiry. A representitive will get back to you as soon as possible</p>
@@ -0,0 +1 @@
1
+ $('#inquiry_form_<%=@inquiry_form.id%>').replaceWith("<%=escape_javascript(@inquiry_form.thank_you_content ? @inquiry_form.thank_you_content.html_safe : 'Thank You')%>");
@@ -0,0 +1,6 @@
1
+ <%=content_for :head do%>
2
+ <%= javascript_include_tag "wymeditor/jquery.wymeditor.pack" %>
3
+ <%= stylesheet_link_tag "spud/admin/inquiries" %>
4
+ <%= javascript_include_tag "spud/admin/inquiries" %>
5
+ <%end%>
6
+ <%= render :template => 'layouts/spud/admin/detail' %>
@@ -0,0 +1,30 @@
1
+ <% content_for :data_controls do %>
2
+ <%= link_to "Forms" ,spud_admin_inquiry_forms_path, :class => "btn btn-primary", :title => "Forms" %>
3
+ <% end %>
4
+
5
+ <% content_for :detail do %>
6
+ <table class="table table-striped">
7
+ <thead>
8
+ <tr>
9
+ <th>Form</th>
10
+ <th>Email Address</th>
11
+ <th>Date Sent</th>
12
+ <th></th>
13
+ </tr>
14
+ </thead>
15
+ <tbody>
16
+ <% @inquiries.each do |inquiry| %>
17
+ <tr>
18
+ <td><%= inquiry.spud_inquiry_form.blank? ? "No Form" : inquiry.spud_inquiry_form.name %></td>
19
+ <td><%= inquiry.email %></td>
20
+ <td><%= timestamp(inquiry.created_at) %></td>
21
+ <td>
22
+ <%= link_to 'Details', spud_admin_inquiry_path(inquiry), :class => 'btn btn-mini' %>
23
+ <%= link_to "Remove", spud_admin_inquiry_path(inquiry), :method => :delete, :class => 'btn btn-mini btn-danger', :data => {:confirm => "Are you sure you want to remove this inquiry?"} %>
24
+ </td>
25
+ </tr>
26
+ <% end %>
27
+ </tbody>
28
+ </table>
29
+ <%= will_paginate @inquiries %>
30
+ <% end %>
@@ -0,0 +1,8 @@
1
+ <% content_for :detail do %>
2
+ <h3>Form: <%=@inquiry.spud_inquiry_form.blank? ? "No Form" : @inquiry.spud_inquiry_form.name %></h3>
3
+ <ul>
4
+ <% @inquiry.spud_inquiry_fields.each do |field| %>
5
+ <li><strong><%= field.name %>:</strong> <%= field.value %></li>
6
+ <% end %>
7
+ </ul>
8
+ <% end %>
@@ -0,0 +1,52 @@
1
+ <%=error_messages_for(f.object)%>
2
+ <fieldset>
3
+ <legend>Form Info</legend>
4
+
5
+ <div class="control-group">
6
+
7
+ <%=f.label :name, :required=>true, :class=>"control-label"%>
8
+ <div class="controls">
9
+ <%=f.text_field :name%>
10
+ </div>
11
+ </div>
12
+ <div class="control-group">
13
+ <%=f.label :recipients, :required=>true, :class=>"control-label"%>
14
+ <div class="controls">
15
+ <%=f.text_field :recipients%>
16
+ </div>
17
+ </div>
18
+ <div class="control-group">
19
+ <%=f.label :subject, :required=>true, :class=>"control-label"%>
20
+ <div class="controls">
21
+ <%=f.text_field :subject%>
22
+ </div>
23
+ </div>
24
+ <div class="control-group">
25
+ <%=f.label :content, :required=>true, :class=>"control-label"%>
26
+ <div class="controls">
27
+ <%=f.text_area :content,:cols => 75,:rows => 5,:class => "wysiwym tinymce"%>
28
+ </div>
29
+ </div>
30
+ <div class="control-group">
31
+ <%=f.label :thank_you_content,"Thank You Text", :required=>true, :class=>"control-label"%>
32
+ <div class="controls">
33
+ <%=f.text_area :thank_you_content,:cols => 75,:rows => 5,:class => "wysiwym tinymce"%>
34
+ </div>
35
+ </div>
36
+ <div class="control-group">
37
+ <%=f.label :submit_title, "Submit Button Title", :required=>true, :class=>"control-label"%>
38
+ <div class="controls">
39
+ <%=f.text_field :submit_title%>
40
+ </div>
41
+ </div>
42
+
43
+ </fieldset>
44
+ <fieldset>
45
+ <legend>Fields</legend>
46
+
47
+ <%=f.fields_for :spud_inquiry_form_fields do |builder|%>
48
+ <%=render "spud_inquiry_form_field_fields",:f => builder%>
49
+ <%end%>
50
+ <p><%= link_to_add_fields "Add Field", f, :spud_inquiry_form_fields %></p>
51
+ </fieldset>
52
+