Browse Source

Fix controller and update deactivate confirm page

pull/981/head
Kat 4 years ago
parent
commit
e219f7ef1e
  1. 15
      app/controllers/locations_controller.rb
  2. 4
      app/views/locations/toggle_active_confirm.html.erb

15
app/controllers/locations_controller.rb

@ -21,7 +21,9 @@ class LocationsController < ApplicationController
def show; end def show; end
def deactivate def deactivate
if params[:location][:confirm].present? && params[:location][:deactivation_date].present? if params[:location].blank?
render "toggle_active", locals: { action: "deactivate" }
elsif params[:location][:confirm].present? && params[:location][:deactivation_date].present?
confirm_deactivation confirm_deactivation
else else
deactivation_date_errors deactivation_date_errors
@ -29,12 +31,7 @@ class LocationsController < ApplicationController
@location.deactivation_date_type = params[:location][:deactivation_date_type] @location.deactivation_date_type = params[:location][:deactivation_date_type]
render "toggle_active", locals: { action: "deactivate" }, status: :unprocessable_entity render "toggle_active", locals: { action: "deactivate" }, status: :unprocessable_entity
else else
deactivation_date_value = deactivation_date render "toggle_active_confirm", locals: { action: "deactivate", deactivation_date: deactivation_date }
if deactivation_date_value.blank?
render "toggle_active", locals: { action: "deactivate" }
else
render "toggle_active_confirm", locals: { action: "deactivate", deactivation_date: deactivation_date_value }
end
end end
end end
end end
@ -169,9 +166,9 @@ private
def confirm_deactivation def confirm_deactivation
if @location.update(deactivation_date: params[:location][:deactivation_date]) if @location.update(deactivation_date: params[:location][:deactivation_date])
@location.lettings_logs.filter_by_before_startdate( params[:location][:deactivation_date]).update(location: nil) @location.lettings_logs.filter_by_before_startdate( params[:location][:deactivation_date]).update(location: nil)
flash[:notice] = "#{@location.name} has been deactivated" flash[:notice] = "#{@location.name || @location.postcode} has been deactivated"
end end
redirect_to scheme_locations_path(@scheme) redirect_to scheme_location_path(@scheme, @location)
return return
end end

4
app/views/locations/toggle_active_confirm.html.erb

@ -3,14 +3,14 @@
<%= govuk_back_link(href: :back) %> <%= govuk_back_link(href: :back) %>
<% end %> <% end %>
<h1 class="govuk-heading-l"> <h1 class="govuk-heading-l">
<span class="govuk-caption-l"><%= @scheme.service_name %></span> <span class="govuk-caption-l"><%= @location.postcode %></span>
<%= "This change will affect #{@location.lettings_logs.count} logs" %> <%= "This change will affect #{@location.lettings_logs.count} logs" %>
</h1> </h1>
<%= govuk_warning_text text: I18n.t("warnings.location.deactivation.review_logs") %> <%= govuk_warning_text text: I18n.t("warnings.location.deactivation.review_logs") %>
<%= f.hidden_field :confirm, value: true %> <%= f.hidden_field :confirm, value: true %>
<%= f.hidden_field :deactivation_date, value: deactivation_date %> <%= f.hidden_field :deactivation_date, value: deactivation_date %>
<div class="govuk-button-group"> <div class="govuk-button-group">
<%= f.govuk_submit "Deactivate this scheme" %> <%= f.govuk_submit "Deactivate this location" %>
<%= govuk_button_link_to "Cancel", scheme_location_path(scheme_id: @scheme, id: @location.id), html: { method: :get }, secondary: true %> <%= govuk_button_link_to "Cancel", scheme_location_path(scheme_id: @scheme, id: @location.id), html: { method: :get }, secondary: true %>
</div> </div>
<% end %> <% end %>

Loading…
Cancel
Save