Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wth right panel reconfig #258

Merged
merged 4 commits into from
Jan 19, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 0 additions & 1 deletion app/assets/javascripts/application.js
Expand Up @@ -42,6 +42,5 @@
//= require form_manager
//= require assert
//= require ajax_handler
//= require ask_a_question
//= require review
//= require steps
72 changes: 0 additions & 72 deletions app/assets/javascripts/ask_a_question.js.coffee

This file was deleted.

3 changes: 0 additions & 3 deletions app/assets/javascripts/feedback.js.coffee
Expand Up @@ -63,6 +63,3 @@ $(document).ready ->
error: (event) ->
$('#errors').show()
$('#error-text').html(I18n["feedback"]["message_error"])



13 changes: 12 additions & 1 deletion app/assets/stylesheets/application.css
Expand Up @@ -18,6 +18,7 @@
/* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR*/
/* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.*/


html, body {
height: 100%;
}
Expand Down Expand Up @@ -889,7 +890,7 @@ span#infotip img {
vertical-align: bottom;
}

.continue div.nav-backward img,
.continue div.nav-backward img,
.review-bottom-navigation div.return-to-step-3 img {
vertical-align: middle;
padding-right: 5px;
Expand Down Expand Up @@ -2906,6 +2907,16 @@ input.devise_submit_button {
margin: 0px -50px 0px 30px !important;
}

.contact-form-fields {
height: 1.3rem;
width: 100%;
}

.contact-form-textarea {
width: 100%;
min-height: 75px;
}

.new-project-button {
background: #4fd934;
background-image: -webkit-linear-gradient(top, #4fd934, #358f35);
Expand Down
27 changes: 27 additions & 0 deletions app/controllers/contact_forms_controller.rb
@@ -0,0 +1,27 @@
class ContactFormsController < ApplicationController

def new
@contact_form = ContactForm.new
respond_to do |format|
format.js
end
end

def create
@contact_form = ContactForm.new(contact_form_params)
respond_to do |format|
if @contact_form.valid?
ContactMailer.contact_us_email(@contact_form).deliver_now
format.html { head :ok, content_type: 'text/html' }
else
format.js { render :new }
end
end
end

private

def contact_form_params
params.require(:contact_form).permit!
end
end
4 changes: 4 additions & 0 deletions app/mailers/application_mailer.rb
@@ -0,0 +1,4 @@
class ApplicationMailer < ActionMailer::Base
default from: "from@example.com"
layout 'mailer'
end
7 changes: 7 additions & 0 deletions app/mailers/contact_mailer.rb
@@ -0,0 +1,7 @@
class ContactMailer < ApplicationMailer

def contact_us_email(contact_form)
@contact_form = contact_form
mail(to: 'success@musc.edu', cc: 'sparcrequest@gmail.com', from: "#{contact_form.email}", subject: "#{contact_form.subject}")
end
end
6 changes: 6 additions & 0 deletions app/models/contact_form.rb
@@ -0,0 +1,6 @@
class ContactForm < ActiveRecord::Base
validates :email,
:message,
presence: true
validates_format_of :email, with: /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\z/i
end
15 changes: 15 additions & 0 deletions app/views/contact_forms/_form.html.haml
@@ -0,0 +1,15 @@
= form_for @contact_form, remote: true do |f|
.field
= f.label :subject, 'Subject'
= f.text_field :subject, class: 'contact-form-fields'
.field
= f.label :email, 'Email'
- if current_user.present?
= f.email_field :email, class: 'contact-form-fields', value: current_user.email
- else
= f.email_field :email, class: 'contact-form-fields'
.field
= f.label :message
= f.text_area :message, class: 'contact-form-textarea'
%br/
= f.submit 'Send Message', class: 'dark-blue-button'
10 changes: 10 additions & 0 deletions app/views/contact_forms/new.js.coffee
@@ -0,0 +1,10 @@
formDialog = $('.contact-form-dialog').html("<%= escape_javascript render 'form' %>").dialog(
height: 400
width: 500
modal: true
title: 'Contact Us'
)

$('.new_contact_form').on 'ajax:success', ->
formDialog.dialog('close')
$('.flash').html('<div id="flash_notice">Message sent</div>')
6 changes: 6 additions & 0 deletions app/views/contact_mailer/contact_us_email.html.haml
@@ -0,0 +1,6 @@
%h3
From SPARCRequest Webpage:
%p
= "We have received a message from #{@contact_form.email}"
%p
= @contact_form.message
5 changes: 5 additions & 0 deletions app/views/layouts/mailer.html.erb
@@ -0,0 +1,5 @@
<html>
<body>
<%= yield %>
</body>
</html>
1 change: 1 addition & 0 deletions app/views/layouts/mailer.text.erb
@@ -0,0 +1 @@
<%= yield %>
31 changes: 5 additions & 26 deletions app/views/service_requests/_right_navigation.html.haml
Expand Up @@ -17,36 +17,15 @@
-# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
-# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
-# TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

.ask-a-question-button.blue-button.btn.btn-primary.btn-lg.btn-block= t(:right_navigation)[:ask_a_question]
= link_to t(:right_navigation)[:dashboard], USER_PORTAL_LINK, :class => "dashboard-button blue-button btn btn-primary btn-lg btn-block"
- if USE_FAQ_LINK
= link_to t(:right_navigation)[:faq], FAQ_URL, :class => "faq-button blue-button btn btn-primary btn-lg btn-block", :target => "blank"
- else
.faq-button.blue-button.btn.btn-primary.btn-lg.btn-block= t(:right_navigation)[:faq]
.feedback-button.blue-button.btn.btn-primary.btn-lg.btn-block= t(:right_navigation)[:feedback]

#feedback-form{:style => 'display: none', :title => 'Give Us Your Feedback!'}
= form_tag feedback_service_requests_path, :method => :post, :remote => true do
#errors
#error-text
%br
%p
= text_field_tag "feedback[email]", nil, {:placeholder => t(:notifications)[:email], :size => 35, :tabindex => 1}
%br
%br
%p
= text_area_tag "feedback[message]", nil, {:placeholder => t(:notifications)[:feedback], :cols => 65, :rows => 15, :tabindex => 2}

#ask-a-question-form{:style => 'display: none', :title => 'Ask a Question'}
= form_tag ask_a_question_service_requests_path, :method => :post, :remote => true do
%p
= text_field_tag "quick_question[email]", nil, {:placeholder => t(:notifications)[:ask_a_question_email], :size => 35, :tabindex => 3}
%span.quick_question_email_error= t(:notifications)[:ask_a_question_email_error]
%br
%br
%p
= text_area_tag "quick_question[body]", nil, {:placeholder => t(:notifications)[:ask_a_question], :cols => 65, :rows => 15, :tabindex => 4}
.feedback-button.blue-button.btn.btn-primary.btn-lg.btn-block
= link_to t(:right_navigation)[:feedback], 'https://redcap.musc.edu/surveys/?s=A37TNJWJPL', target: '_blank'
.feedback-button.blue-button.btn.btn-primary.btn-lg.btn-block
= link_to 'Contact Us', new_contact_form_path, remote: true
.contact-form-dialog

- unless USE_FAQ_LINK
#cart-help{:style => 'display: none', :title => 'Help/FAQs'}
Expand Down
4 changes: 3 additions & 1 deletion config/routes.rb
Expand Up @@ -49,6 +49,8 @@
end
end

resources :contact_forms, only: [:new, :create]

resources :service_requests, only: [:show] do
resources :projects, except: [:index, :show, :destroy]
resources :studies, except: [:index, :show, :destroy]
Expand Down Expand Up @@ -344,7 +346,7 @@
match 'identities/search' => 'identities#search', :via => :get
resources :identities, only: [:index, :show, :create, :update]
end

mount API::Base => '/'

root to: 'service_requests#catalog'
Expand Down
11 changes: 11 additions & 0 deletions db/migrate/20160114154000_create_contact_forms.rb
@@ -0,0 +1,11 @@
class CreateContactForms < ActiveRecord::Migration
def change
create_table :contact_forms do |t|
t.string :subject
t.string :email
t.text :message

t.timestamps null: false
end
end
end
23 changes: 22 additions & 1 deletion db/schema.rb
Expand Up @@ -11,7 +11,20 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 20160106161249) do
ActiveRecord::Schema.define(version: 20160114151800) do

create_table "additional_details", force: :cascade do |t|
t.string "name", limit: 255
t.string "description", limit: 255
t.text "form_definition_json", limit: 65535
t.date "effective_date"
t.boolean "enabled"
t.integer "service_id", limit: 4
t.datetime "created_at"
t.datetime "updated_at"
end

add_index "additional_details", ["service_id"], name: "index_additional_details_on_service_id", using: :btree

create_table "admin_rates", force: :cascade do |t|
t.integer "line_item_id", limit: 4
Expand Down Expand Up @@ -200,6 +213,14 @@
add_index "clinical_providers", ["identity_id"], name: "index_clinical_providers_on_identity_id", using: :btree
add_index "clinical_providers", ["organization_id"], name: "index_clinical_providers_on_organization_id", using: :btree

create_table "contact_forms", force: :cascade do |t|
t.string "subject", limit: 255
t.string "email", limit: 255
t.text "message", limit: 65535
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end

create_table "cover_letters", force: :cascade do |t|
t.text "content", limit: 65535
t.integer "sub_service_request_id", limit: 4
Expand Down
38 changes: 38 additions & 0 deletions spec/controllers/contact_forms_controller_spec.rb
@@ -0,0 +1,38 @@
require 'rails_helper'

RSpec.describe ContactFormsController, type: :controller do
let!(:contact_form) do
FactoryGirl.create(:contact_form)
end

describe 'GET #new' do
it 'returns http success' do
xhr :get, :new
expect(response).to have_http_status(:success)
end

it 'assigns a new instance to correct model' do
xhr :get, :new
expect(assigns(:contact_form).class).to eq ContactForm
end
end

describe 'GET #create' do
it 'returns http success' do
xhr :post, :create, :contact_form => {
subject: 'subject',
email: 'email@email.com',
message: 'sample message'
}
expect(response).to have_http_status(:success)
end

it 'should send an email' do
expect { xhr :post, :create, :contact_form => {
subject: 'subject',
email: 'email@email.com',
message: 'sample message'
}}.to change(ActionMailer::Base.deliveries, :count).by(1)
end
end
end
7 changes: 7 additions & 0 deletions spec/factories/contact_form.rb
@@ -0,0 +1,7 @@
FactoryGirl.define do
factory :contact_form, class: ContactForm do
subject 'SPARC-Request'
email 'example@example.com'
message 'this is a sample message'
end
end