Skip to content
This repository was archived by the owner on Jul 24, 2020. It is now read-only.

Commit 92c57bc

Browse files
author
Sydney Young
committed
fix frontend things
1 parent 4390761 commit 92c57bc

11 files changed

+105
-38
lines changed

app/controllers/app_configs_controller.rb

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# frozen_string_literal: true
12
class AppConfigsController < ApplicationController
23
authorize_resource class: false
34
skip_before_action :seen_app_configs, only: [:edit]
@@ -53,6 +54,7 @@ def app_config_params
5354
:checkout_persons_can_edit, :enable_renewals,
5455
:override_on_create, :override_at_checkout, :require_phone,
5556
:notify_admin_on_create, :disable_user_emails,
56-
:autodeactivate_on_archive, :requests_affect_availability)
57+
:autodeactivate_on_archive, :requests_affect_availability,
58+
:disable_requests)
5759
end
5860
end

app/controllers/reservations_controller.rb

+26-16
Original file line numberDiff line numberDiff line change
@@ -102,30 +102,24 @@ def view_all_dates
102102
def show
103103
end
104104

105-
def new # rubocop:disable MethodLength
105+
def new
106106
if cart.items.empty?
107107
flash[:error] = 'You need to add items to your cart before making a '\
108108
'reservation.'
109109
redirect_loc = (request.env['HTTP_REFERER'].present? ? :back : root_path)
110110
redirect_to redirect_loc
111-
else
112-
# error handling
113-
@errors = cart.validate_all
114-
unless @errors.empty?
115-
if can? :override, :reservation_errors
116-
flash[:error] = 'Are you sure you want to continue? Please review '\
117-
'the errors below.'
118-
else
119-
flash[:error] = 'Please review the errors below. If uncorrected, '\
120-
'any reservations with errors will be filed as a request, and '\
121-
'subject to administrator approval.'
122-
end
123-
end
111+
return
112+
end
124113

114+
# error handling
115+
@errors = cart.validate_all
116+
if @errors.empty?
125117
# this is used to initialize each reservation later
126118
@reservation = Reservation.new(start_date: cart.start_date,
127119
due_date: cart.due_date,
128120
reserver_id: cart.reserver_id)
121+
else
122+
handle_new_reservation_errors
129123
end
130124
end
131125

@@ -480,6 +474,22 @@ def archive # rubocop:disable all
480474

481475
private
482476

477+
def handle_new_reservation_errors
478+
if can? :override, :reservation_errors
479+
flash[:error] = 'Are you sure you want to continue? Please review '\
480+
'the errors below.'
481+
render :new
482+
elsif AppConfig.check(:disable_requests)
483+
flash[:error] = 'Please review the errors below.'
484+
render :requests_disabled
485+
else
486+
flash[:error] = 'Please review the errors below. If uncorrected, '\
487+
'any reservations with errors will be filed as a request, and '\
488+
'subject to administrator approval.'
489+
render :new_request
490+
end
491+
end
492+
483493
def handle_create_errors(errors)
484494
case errors
485495
when 'needs notes'
@@ -491,10 +501,10 @@ def handle_create_errors(errors)
491501
else
492502
AppConfig.get(:request_text)
493503
end
494-
render(:new)
504+
render :new_request
495505
when 'requests disabled'
496506
flash[:error] = 'Unable to create reservation'
497-
render(:new)
507+
render :requests_disabled
498508
else
499509
redirect_to catalog_path,
500510
flash: { error: 'Oops, something went wrong with making '\

app/views/app_configs/_form.erb

+1
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
<fieldset>
5050
<legend>Reservation Settings</legend><br />
5151
<%= f.input :requests_affect_availability, label: 'Allow requests to affect equipment availability?', hint: 'When enabled, reservation requests will affect equipment item availability before the request is approved.' %>
52+
<%= f.input :disable_requests, label: 'Disable reservation requests?', hint: 'When enabled, users will not be able to create special reservation requests.' %>
5253
<%= f.input :notify_admin_on_create, label: 'Notify admin on creation?',hint: 'When enabled, admins will get an e-mail whenever a reservation is created.' %>
5354
<%= f.input :request_text, label: 'Reservation request text', input_html: {rows: 10},
5455
hint: 'This message will be displayed to users who are about to file a reservation request for invalid reservations. You can use markdown in this field' %>

app/views/cart_js/reservation_form.js.erb

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
resume_cart();
22

33
<% if @errors.empty? or (can? :override, :reservation_errors) %>
4-
$('#confirm-res-form').html('<%= escape_javascript(render :partial => '/reservations/new_reservation') %>');
4+
$('#confirm-res-form').html('<%= escape_javascript(render partial: '/reservations/new_reservation') %>');
55
$('.page-header').html('<h1>Confirm Reservation</h1>');
6+
<% elsif AppConfig.check(:disable_requests) %>
7+
$('#confirm-res-form').html('<%= escape_javascript(render partial: '/reservations/requests_disabled') %>');
8+
$('.page-header').html('<h1>Reservation Denied</h1>');
69
<% else %>
7-
$('#confirm-res-form').html('<%= escape_javascript(render :partial => '/reservations/new_request' ) %>');
10+
$('#confirm-res-form').html('<%= escape_javascript(render partial: '/reservations/new_request' ) %>');
811
$('.page-header').html('<h1>Confirm Reservation Request</h1>');
912
<% end %>
1013

app/views/reservations/_new_request.html.erb

+4-4
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<div id="content" class="col-md-9">
33
<% unless @errors.empty? %>
44
<p>
5-
<h3><i class="fa fa-exclamation-triangle warning-icon"></i> Would you like to resolve the following error(s)?</h3>
5+
<h3><i class="fa fa-exclamation-triangle warning-icon"></i> Would you like to resolve the following error(s)?</h3>
66
</p>
77
<div class ="form-errors">
88
<% @errors.each do |msg| %>
@@ -13,13 +13,13 @@
1313
</div>
1414
<% end %>
1515
<p>
16-
<h4>Equipment requested for
16+
<h4>Equipment requested for
1717
<%= link_to User.find(cart.reserver_id).name, User.find(cart.reserver_id),
18-
target: '_blank' %>
18+
target: '_blank' %>
1919
from
2020
<%= cart.start_date.to_s(:long) %> to
2121
<%= cart.due_date.to_s(:long) %>:
22-
</h4>
22+
</h4>
2323
</p>
2424
<%= render partial: 'reservations/edit_reservation_form' %>
2525
<div class="well">

app/views/reservations/_new_reservation.html.erb

+7-7
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
<div id="content" class="col-md-9">
44
<% unless @errors.empty? %>
55
<p>
6-
<h3>
7-
<i class="fa fa-exclamation-triangle warning-icon"></i>
8-
Please be aware of the following errors:
9-
</h3>
6+
<h3>
7+
<i class="fa fa-exclamation-triangle warning-icon"></i>
8+
Please be aware of the following errors:
9+
</h3>
1010
</p>
1111
<div class ="form-errors">
1212
<% @errors.each do |msg| %>
@@ -17,13 +17,13 @@
1717
</div>
1818
<% end %>
1919
<p>
20-
<h4>Equipment Reserved for
20+
<h4>Equipment Reserved for
2121
<%= link_to User.find(cart.reserver_id).name, User.find(cart.reserver_id),
22-
target: '_blank' %>
22+
target: '_blank' %>
2323
from
2424
<%= cart.start_date.to_s(:long) %> to
2525
<%= cart.due_date.to_s(:long) %>:
26-
</h4>
26+
</h4>
2727
</p>
2828
<%= render partial: 'reservations/edit_reservation_form' %>
2929
</div>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<% title "Reservation Denied" %>
2+
<div id="content" class="col-md-9">
3+
<% unless @errors.empty? %>
4+
<p>
5+
<h3><i class="fa fa-exclamation-triangle warning-icon"></i> Would you like to resolve the following error(s)?</h3>
6+
</p>
7+
<div class ="form-errors">
8+
<% @errors.each do |msg| %>
9+
<ul>
10+
<li><%= msg %></li>
11+
</ul>
12+
<% end %>
13+
</div>
14+
<% end %>
15+
<p>
16+
<h4>Equipment requested for
17+
<%= link_to User.find(cart.reserver_id).name, User.find(cart.reserver_id),
18+
target: '_blank' %>
19+
from
20+
<%= cart.start_date.to_s(:long) %> to
21+
<%= cart.due_date.to_s(:long) %>:
22+
</h4>
23+
</p>
24+
<%= render partial: 'reservations/edit_reservation_form' %>
25+
<%= simple_form_for @reservation do |f| %>
26+
<div class="form-group">
27+
<%= f.button :submit, "Submit", id: 'finalize_reservation_btn' %>
28+
</div>
29+
<% end %>
30+
</div>
31+
<div id="sidebar" class="col-md-3">
32+
<div id="sidebarbottom">
33+
<div id="cart" class="well">
34+
<div id="cartSpinner"></div>
35+
<header class="cart-header">
36+
<% if cannot? :manage, Reservation %>
37+
<h2>My Cart</h2>
38+
<% else %>
39+
<h2>Cart</h2>
40+
<% end %>
41+
</header>
42+
<%= form_tag url_for(action: 'change_reservation_dates', controller: "catalog"), remote: true, class: 'form-vertical', id: 'dates_form', method: :put do %>
43+
<%# allow user to set start/end dates %>
44+
<%= render partial: 'reservations/cart_dates' %>
45+
<% end %>
46+
<br>
47+
</div>
48+
</div>
49+
</div>

app/views/reservations/new.html.erb

+2-6
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
11
<div id='confirm-res-form'>
2-
<% if @errors.empty? or (can? :override, :reservation_errors) %>
3-
<%= render :partial => "new_reservation" %>
4-
<% else %>
5-
<%= render :partial => "new_request" %>
6-
<% end %>
7-
</div>
2+
<%= render partial: 'new_reservation' %>
3+
</div>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<div id='confirm-res-form'>
2+
<%= render partial: 'new_request' %>
3+
</div>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<div id='confirm-res-form'>
2+
<%= render partial: 'requests_disabled' %>
3+
</div>

spec/controllers/reservations_controller_spec.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@
321321
post :create, reservation: { id: 1 }
322322
end
323323
it { is_expected.to set_flash[:error] }
324-
it { is_expected.to render_template(:new) }
324+
it { is_expected.to render_template(:new_request) }
325325
end
326326
context 'requests disabled' do
327327
before do
@@ -333,7 +333,7 @@
333333
post :create, reservation: { id: 1 }
334334
end
335335
it { is_expected.to set_flash[:error] }
336-
it { is_expected.to render_template(:new) }
336+
it { is_expected.to render_template(:requests_disabled) }
337337
end
338338
context 'other error' do
339339
before do

0 commit comments

Comments
 (0)