Skip to content

Commit

Permalink
Sliding contact form. Fixes #319
Browse files Browse the repository at this point in the history
  • Loading branch information
jcoyne committed Feb 26, 2014
1 parent 38454a2 commit 4b0d8d0
Show file tree
Hide file tree
Showing 9 changed files with 67 additions and 3 deletions.
39 changes: 39 additions & 0 deletions app/assets/javascripts/spotlight/report_a_problem.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
(function( $ ){

$.fn.reportProblem = function( options ) {
// Create some defaults, extending them with any options that were provided
var settings = $.extend( { }, options);
var container, target, cancel;

function init() {
target_val = container.attr('data-target')
if (!target_val)
return

target = $("#" + target_val);
container.on('click', open);
target.find('[data-behavior="cancel-link"]').on('click', close);
}

function open(event) {
event.preventDefault();
target.slideToggle('slow');
}

function close(event) {
event.preventDefault();
target.slideUp('fast');
}

return this.each(function() {
container = $(this);
init();
});
}
})( jQuery );

Spotlight.onLoad(function() {
$('[data-behavior="contact-link"]').reportProblem();
});


4 changes: 4 additions & 0 deletions app/assets/stylesheets/spotlight/_report_a_problem.css.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#report-problem-form {
margin-bottom: 30px;
display: none;
}
1 change: 1 addition & 0 deletions app/assets/stylesheets/spotlight/spotlight.css.scss
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
@import "spotlight/blacklight_configuration";
@import "spotlight/typeahead";
@import "spotlight/bootstrap_overrides";
@import "spotlight/report_a_problem";


#main-container {
Expand Down
2 changes: 1 addition & 1 deletion app/views/_user_util_links.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@
<% else %>
<li><%= link_to t('spotlight.header_links.login'), new_user_session_path %></li>
<% end %>
<li><%= link_to t('spotlight.header_links.contact'), spotlight.new_exhibit_contact_form_path(current_exhibit) %></li>
<li><%= link_to t('spotlight.header_links.contact'), spotlight.new_exhibit_contact_form_path(current_exhibit), data: {behavior: 'contact-link', target: 'report-problem-form' } %></li>
</ul>
1 change: 1 addition & 0 deletions app/views/layouts/spotlight/spotlight.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
<body class="<%= render_body_class %>">
<%= render :partial => 'shared/header_navbar' %>


<div id="ajax-modal" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="modal menu" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
Expand Down
3 changes: 2 additions & 1 deletion app/views/shared/_header_navbar.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,6 @@
</div>
</div>

<%= render 'spotlight/shared/report_a_problem' %>
<%= render 'shared/exhibit_masthead' %>
<%= render 'shared/exhibit_navbar' %>
<%= render 'shared/exhibit_navbar' %>
15 changes: 15 additions & 0 deletions app/views/spotlight/shared/_report_a_problem.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<div id="report-problem-form" class='row'>
<% contact_form = Spotlight::ContactForm.new current_url: request.original_url %>
<%= bootstrap_form_for contact_form, url: spotlight.exhibit_contact_form_path(current_exhibit, contact_form), style: :horizontal, right: "col-sm-5" do |f| %>

<h2 class="col-md-offset-2"><%= t(:'.title') %></h2>
<%= f.text_field :name %>
<%= f.text_field :email %>
<%= f.text_area :message, rows: 7 %>
<%= f.hidden_field :current_url %>
<%= f.form_group do %>
<%= f.submit nil %>
<%= link_to t(:'helpers.action.cancel'), '#', class: 'btn btn-text', data: { 'behavior' => 'cancel-link' } %>
<% end %>
<% end %>
</div>
3 changes: 3 additions & 0 deletions config/locales/spotlight.en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,9 @@ en:
saved_search:
label: "Save this search"
title: "Saved search title"
shared:
report_a_problem:
title: Contact Us
shared:
exhibit_navbar:
more_exhibits: More Exhibits
Expand Down
2 changes: 1 addition & 1 deletion spec/features/report_a_problem_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
expect(page).to have_content "Report a problem"
end

it "should accept a problem report" do
it "should accept a problem report", js: true do
e = Spotlight::Exhibit.default
e.contact_emails = ["test@example.com", "test2@example.com"]
e.save
Expand Down

0 comments on commit 4b0d8d0

Please sign in to comment.