Skip to content

Commit a464c1c

Browse files
committed
Wrap the edit form in a modal.
1 parent 999dffc commit a464c1c

File tree

5 files changed

+39
-16
lines changed

5 files changed

+39
-16
lines changed

app/components/aeon/request_actions_component.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
</form>
66
<% else %>
77
<% if helpers.can? :edit, request %>
8-
<%= link_to edit_aeon_request_path(request), class: 'btn btn-link su-underline p-0 me-sm-2' do %>
8+
<%= link_to edit_aeon_request_path(request), class: 'btn btn-link su-underline p-0 me-sm-2', data: { action: 'modal#open' } do %>
99
<i class="bi bi-pencil-fill me-1 align-middle"></i><span class="d-none d-sm-inline">Edit request</span>
1010
<% end %>
1111
<% end %>

app/controllers/aeon_requests_controller.rb

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,14 @@ def resubmit
3939

4040
def edit
4141
authorize! :update, @aeon_request
42+
43+
request.variant = :modal if params[:modal]
4244
end
4345

4446
def update # rubocop:disable Metrics/AbcSize,Metrics/MethodLength
4547
authorize! :update, @aeon_request
4648

47-
AeonClient.new.update_request(
49+
new_request = AeonClient.new.update_request(
4850
@aeon_request.transaction_number,
4951
AeonClient::RequestData.with_defaults.with(
5052
appointment_id: aeon_request_params[:appointment_id]&.to_i,
@@ -54,16 +56,21 @@ def update # rubocop:disable Metrics/AbcSize,Metrics/MethodLength
5456
)
5557
)
5658

57-
aeon_requests_path = @aeon_request.draft? ? drafts_aeon_requests_path : submitted_aeon_requests_path
58-
redirect_to aeon_requests_path, notice: 'Request was successfully updated.'
59+
respond_to do |format|
60+
format.turbo_stream { render turbo_stream: turbo_stream.replace(new_request, Aeon::RequestComponent.new(request: new_request)) }
61+
format.html do
62+
aeon_requests_path = new_request.draft? ? drafts_aeon_requests_path : submitted_aeon_requests_path
63+
redirect_to aeon_requests_path, notice: 'Request was successfully updated.'
64+
end
65+
end
5966
end
6067

6168
def destroy
6269
authorize! :destroy, @aeon_request
6370

6471
AeonClient.new.update_request_route(transaction_number: params[:id], status: 'Cancelled by User')
6572
respond_to do |format|
66-
format.turbo_stream { render turbo_stream: turbo_stream.remove("request-#{params[:id]}") }
73+
format.turbo_stream { render turbo_stream: turbo_stream.remove(@aeon_request) }
6774
end
6875
end
6976

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<%= form_with(model: @aeon_request, data: { turbo: true }) do |f| %>
2+
<div class="modal-body">
3+
<% if f.object.digital? %>
4+
<%= render Aeon::DigitizationFormItemComponent.new(title: f.object.volume, dom_id: 'edit_aeon_item_request', object: f.object, base_name: 'aeon_request', series: nil, subseries: nil, collapsed: false) %>
5+
<% else %>
6+
<ul id="reading" class="appointments-container list-unstyled">
7+
<%= render Aeon::AppointmentFormItemComponent.new(title: f.object.call_number, dom_id: 'edit_aeon_item_request', object: f.object, base_name: 'aeon_request', series: nil, subseries: nil, reading_room_id: f.object.reading_room.id, appointments: current_user.aeon.appointments_for(site: f.object.site)) %>
8+
</ul>
9+
<% end %>
10+
</div>
11+
12+
13+
<div class="modal-footer">
14+
<%= link_to 'Cancel', aeon_appointments_path, class: 'btn btn-outline-primary', data: { 'bs-dismiss': 'modal' } %>
15+
<%= f.submit class: 'btn btn-primary', data: { 'bs-dismiss': 'modal' } %>
16+
</div>
17+
<% end %>
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<turbo-frame id="modal-contents">
2+
<div class="modal-header">
3+
<h1 class="mb-0">Edit request</h1>
4+
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
5+
</div>
6+
<div class="modal-body">
7+
<%= render 'form' %>
8+
</div>
9+
</turbo-frame>
Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1 @@
1-
<%= form_with(model: @aeon_request) do |f| %>
2-
<% if f.object.digital? %>
3-
<%= render Aeon::DigitizationFormItemComponent.new(title: f.object.volume, dom_id: 'edit_aeon_item_request', object: f.object, base_name: 'aeon_request', series: nil, subseries: nil, collapsed: false) %>
4-
<% else %>
5-
<ul id="reading" class="appointments-container list-unstyled">
6-
<%= render Aeon::AppointmentFormItemComponent.new(title: f.object.call_number, dom_id: 'edit_aeon_item_request', object: f.object, base_name: 'aeon_request', series: nil, subseries: nil, reading_room_id: f.object.reading_room.id, appointments: current_user.aeon.appointments_for(site: f.object.site)) %>
7-
</ul>
8-
<% end %>
9-
10-
<%= f.submit class: 'btn btn-primary' %>
11-
<% end %>
1+
<%= render 'form' %>

0 commit comments

Comments
 (0)