Skip to content

Commit

Permalink
add contact us form
Browse files Browse the repository at this point in the history
  • Loading branch information
tampakis committed Oct 5, 2017
1 parent c55000f commit 7955abd
Show file tree
Hide file tree
Showing 21 changed files with 526 additions and 4 deletions.
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,5 @@ gem 'sneakers'
gem 'chosen-rails' # jquery multiselect plugin for advanced search
gem 'rails-reverse-proxy'
gem 'pul_uv_rails', git: 'https://github.com/pulibrary/pul_uv_rails', branch: 'master'
gem 'mail_form'
gem 'simple_form'
10 changes: 9 additions & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ GEM
railties (>= 3.0)
sass-rails (>= 3.2)
cliver (0.3.2)
coderay (1.1.1)
coderay (1.1.2)
coffee-rails (4.2.2)
coffee-script (>= 2.2.0)
railties (>= 4.0.0)
Expand Down Expand Up @@ -205,6 +205,9 @@ GEM
nokogiri (>= 1.5.9)
mail (2.6.6)
mime-types (>= 1.16, < 4)
mail_form (1.7.0)
actionmailer (>= 3.2, < 5.2)
activemodel (>= 3.2, < 5.2)
method_source (0.8.2)
mime-types (3.1)
mime-types-data (~> 3.2015)
Expand Down Expand Up @@ -339,6 +342,9 @@ GEM
serverengine (1.5.11)
sigdump (~> 0.2.2)
sigdump (0.2.4)
simple_form (3.5.0)
actionpack (> 4, < 5.2)
activemodel (> 4, < 5.2)
simplecov (0.14.1)
docile (~> 1.1.0)
json (>= 1.8, < 3)
Expand Down Expand Up @@ -428,6 +434,7 @@ DEPENDENCIES
geoblacklight (~> 1.6.0)
jbuilder (~> 2.5)
jquery-rails
mail_form
modernizr-rails
neat (~> 1.8)
omniauth-cas
Expand All @@ -443,6 +450,7 @@ DEPENDENCIES
rubocop (~> 0.42.0)
rubocop-rspec (~> 1.6.0)
sass-rails (~> 5.0)
simple_form
sneakers
solr_wrapper
spring
Expand Down
41 changes: 41 additions & 0 deletions app/assets/stylesheets/components/forms.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
@import "utils/variables";

// reset form styling cross-browser
.form-control,
.form-control:focus {
-webkit-box-shadow: 0 5px 15px rgba(0, 0, 0, 0);
-moz-box-shadow: 0 5px 15px rgba(0, 0, 0, 0);
-o-box-shadow: 0 5px 15px rgba(0, 0, 0, 0);
box-shadow: 0 5px 15px rgba(0, 0, 0, 0);
}

form table th:first-child {
width: 30px;
}

.blacklight-feedback h1 {
margin-bottom: 0.25em;
display: block;
}
.blacklight-feedback small {
margin-bottom: 2em;
display: block;
}

// overwrite bootstrap glyphicon for errors in input fields
.form-control-feedback {
right: 15px;
}

.feedback-button {
margin-bottom: 15px;
}

.has-error .error {
font-weight: bold;
color: $brand-danger;
}

.blacklight-feedback-hidden {
display: none;
}
1 change: 1 addition & 0 deletions app/assets/stylesheets/pulmap.scss
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
@import 'components/universal-viewer';
@import 'components/advanced';
@import 'components/buttons';
@import 'components/forms';

@import 'shame-geo';
@import 'bootstrap-toggle';
Expand Down
3 changes: 2 additions & 1 deletion app/assets/stylesheets/utils/variables.scss
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@ $light-gray: #f5f4f1;
$dark-orange: #89440a;
$orange: #e87511;
$blue: #337ab7;
$brand-danger: #a94442;

//typography
$font-serif: 'Droid Serif', Georgia, Times, serif !default;
$font-sans: 'DejaVu Sans', 'Arial Unicode MS', Helvetica, sans-serif !default;
$font-mono: 'Lucida Console', Monaco, monospace !default;
$text-color: #000 !default;
$placeholder-text-color: rgb(204, 204, 204);
$placeholder-text-color: rgb(204, 204, 204);
39 changes: 39 additions & 0 deletions app/controllers/feedback_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
class FeedbackController < ApplicationController
before_action :current_user_email
before_action :build_feedback_form, only: [:create]

def new
@feedback_form = FeedbackForm.new if @feedback_form.nil?
@feedback_form.current_url = request.referer || root_url
end

def create
respond_to do |format|
if @feedback_form.valid?
@feedback_form.deliver
format.js { flash.now[:notice] = I18n.t('blacklight.feedback.success') }
else
format.js { flash.now[:error] = @feedback_form.error_message }
end
end
end

protected

def build_feedback_form
@feedback_form = FeedbackForm.new(feedback_form_params)
@feedback_form.request = request
@feedback_form
end

def feedback_form_params
params.require(:feedback_form).permit(:name, :email, :message, :current_url, :feedback_desc)
end

def current_user_email
return if current_user.nil?
return if current_user.provider != 'cas'
@user_email = "#{current_user.uid}@princeton.edu"
@user_email
end
end
23 changes: 23 additions & 0 deletions app/models/feedback_form.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
require 'mail_form'

class FeedbackForm < MailForm::Base
attribute :name, validate: true
attribute :email, validate: /\A([\w\.%\+\-]+)@([\w\-]+\.)+([\w]{2,})\z/i
attribute :message, validate: true
attribute :current_url
attribute :feedback_desc, captcha: true
append :remote_ip, :user_agent

def headers
{
subject: "#{I18n.t(:'blacklight.application_name')} Feedback Form",
to: ENV['MAP_FEEDBACK_TO'] || 'lsupport@princeton.edu',
from: %("#{name}" <#{email}>),
cc: ENV['MAP_FEEDBACK_CC']
}
end

def error_message
I18n.t(:'blacklight.feedback.error').to_s
end
end
54 changes: 54 additions & 0 deletions app/views/feedback/_form.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<%= simple_form_for(@feedback_form, url: '/contact-us', id: 'feedback_form', remote: true, class: "form-horizontal" ) do |f| %>
<fieldset class="form-group">
<label class="control-label col-sm-2" for="name">
Your name
</label>
<div class="col-sm-10">
<%= f.text_field :name, class: 'form-control', error: 'Please provide a name' %>
<% unless @feedback_form.errors[:name].empty? %>
<span class="glyphicon glyphicon-remove form-control-feedback" aria-hidden="true"></span>
<span id="inputError2Status" class="sr-only">(error)</span>
<span class="error">This field <%= @feedback_form.errors[:name].first %></span>
<% end %>
</div>
</fieldset>
<fieldset class="form-group">
<label class="control-label col-sm-2" for="email">
Your email
</label>
<div class="col-sm-10">
<%= f.email_field :email, class: 'form-control', error: 'Please provide a valid email address', value: @user_email %>
<% unless @feedback_form.errors[:email].empty? %>
<span class="glyphicon glyphicon-remove form-control-feedback" aria-hidden="true"></span>
<span id="inputError2Status" class="sr-only">(error)</span>
<span class="error">Email <%= @feedback_form.errors[:email].first %></span>
<% end %>
</div>
</fieldset>
<fieldset class="form-group">
<label class="control-label col-sm-2" for="message">
Questions or comments
</label>
<div class="col-sm-10">
<%= f.text_area :message, class: 'form-control', rows: '5', error: 'Please describe the problem you encountered or ask a question.' %>
<% unless @feedback_form.errors[:message].empty? %>
<span class="error">This field <%= @feedback_form.errors[:message].first %></span>
<% end %>
</div>
</fieldset>
<fieldset class="form-group blacklight-feedback-hidden">
<label class="control-label col-sm-2" for="feedback_desc">
If you are a human do not fill in this value
</label>
<div class="col-sm-10">
<%= f.text_field :feedback_desc, class: 'form-control', error: 'Please describe' %>
</div>
</fieldset>

<%= f.hidden_field :current_url %>
<div class="form-group">
<div class="col-sm-offset-2 col-md-10 feedback-button">
<%= f.submit t('blacklight.sms.form.submit'), class: 'btn btn-primary pull-right' %>
</div>
</div>
<% end %>
2 changes: 2 additions & 0 deletions app/views/feedback/_return.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<p><%= I18n.t('blacklight.feedback.confirmation') %></p>
<%= link_to t('blacklight.feedback.return').html_safe, @feedback_form.current_url, class: 'btn btn-default feedback-button' %>
16 changes: 16 additions & 0 deletions app/views/feedback/create.js.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
$(".flash_messages").html("<%= escape_javascript(render :partial=>'shared/flash_msg', layout: 'shared/flash_messages') %>");

setTimeout(function() {
$(".flash_messages .alert-info, .flash_messages .alert-success").fadeOut('slow', function(){
$(".flash_messages .alert-info, .flash_messages .alert-success").remove();
});
}, 3000);

<% if !@feedback_form.errors.full_messages.empty? %>
$("#new_feedback_form").replaceWith("<%= escape_javascript(render 'form') %>");
$(".error").each(function( index ) {
$(this).parent().addClass('has-error');
});
<% else %>
$("#new_feedback_form").replaceWith("<%= escape_javascript(render 'return') %>");
<% end %>
9 changes: 9 additions & 0 deletions app/views/feedback/new.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<%= render 'shared/start_over_row' %>
<div class="col-sm-12">
<h1 class="page-heading">Contact Us</h1>
<small>*All fields are required</small>
</div>

<div class="col-sm-12">
<%= render 'form' %>
</div>
2 changes: 1 addition & 1 deletion app/views/shared/_pul_branding.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

<div class="pull-right menu--level-1 col-xs-12 col-sm-3">
<ul>
<li><a href="http://library.princeton.edu/help/contact-us">Contact Us</a></li>
<li><a href="/contact-us">Contact Us</a></li>
<%= render :partial=>'/account' %>
</ul>
</div>
Expand Down
2 changes: 1 addition & 1 deletion app/views/shared/_this_is_beta.html.erb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<div class="col-xs-12 col-lg-12 alert alert-warning beta">
<p><strong>This is Beta Software</strong><br />
There may be features missing. <a title="Feedback on New Catalog" href="http://library.princeton.edu/help/contact-us">Please send us a note</a>
There may be features missing. <a title="Feedback on New Geo Search" href="/feedback">Please send us a note</a>
if you have feedback or think you have found an error.
</p>
</div>

0 comments on commit 7955abd

Please sign in to comment.