diff --git a/app/controllers/locations_controller.rb b/app/controllers/locations_controller.rb index 5e51670d5..233b3f383 100644 --- a/app/controllers/locations_controller.rb +++ b/app/controllers/locations_controller.rb @@ -24,6 +24,21 @@ class LocationsController < ApplicationController if params[:location].present? @location.postcode = params[:location][:postcode] @location.save! + if @location.location_code.blank? || @location.location_admin_district.blank? + redirect_to scheme_location_local_authority_path(@scheme, @location, referrer: params[:referrer]) + elsif params[:referrer] == "check_answers" + redirect_to scheme_location_check_answers_path(@scheme, @location) + else + redirect_to scheme_location_name_path(@scheme, @location) + end + end + end + + def local_authority + if params[:location].present? + @location.location_admin_district = params[:location][:location_admin_district] + @location.location_code = Location.local_authorities.key(params[:location][:location_admin_district]) + @location.save! if params[:referrer] == "check_answers" redirect_to scheme_location_check_answers_path(@scheme, @location) else @@ -158,7 +173,7 @@ class LocationsController < ApplicationController @location = Location.new(location_params) if @location.save if @location.location_admin_district.nil? - redirect_to(scheme_location_edit_local_authority_path(scheme_id: @scheme.id, location_id: @location.id, add_another_location: location_params[:add_another_location])) + redirect_to(scheme_location_local_authority_path(scheme_id: @scheme.id, location_id: @location.id, add_another_location: location_params[:add_another_location])) elsif location_params[:add_another_location] == "Yes" redirect_to new_scheme_location_path(@scheme) else @@ -184,10 +199,6 @@ class LocationsController < ApplicationController render_not_found and return unless @location && @scheme end - def edit_local_authority - render_not_found and return unless @location && @scheme - end - def update render_not_found and return unless @location && @scheme @@ -204,7 +215,7 @@ class LocationsController < ApplicationController case page when "edit" if @location.location_admin_district.nil? - redirect_to(scheme_location_edit_local_authority_path(scheme_id: @scheme.id, location_id: @location.id, add_another_location: location_params[:add_another_location])) + redirect_to(scheme_location_local_authority_path(scheme_id: @scheme.id, location_id: @location.id, add_another_location: location_params[:add_another_location])) elsif location_params[:add_another_location] == "Yes" redirect_to(new_scheme_location_path(@location.scheme)) else diff --git a/app/helpers/locations_helper.rb b/app/helpers/locations_helper.rb index dcc6c028b..14d10668f 100644 --- a/app/helpers/locations_helper.rb +++ b/app/helpers/locations_helper.rb @@ -60,7 +60,7 @@ module LocationsHelper when "name" scheme_location_name_path(location.scheme, location, referrer: "check_answers") when "location_admin_district" - scheme_location_edit_local_authority_path(location.scheme, location, referrer: "check_answers") + scheme_location_local_authority_path(location.scheme, location, referrer: "check_answers") when "units" scheme_location_units_path(location.scheme, location, referrer: "check_answers") when "type_of_unit" diff --git a/app/views/locations/local_authority.html.erb b/app/views/locations/local_authority.html.erb new file mode 100644 index 000000000..493c4f9cf --- /dev/null +++ b/app/views/locations/local_authority.html.erb @@ -0,0 +1,35 @@ +<% content_for :title, "Add a location to this scheme" %> + +<% content_for :before_content do %> + <%= govuk_back_link( + text: "Back", + href: params[:referrer] == "check_answers" ? scheme_location_check_answers_path(@scheme, @location) : scheme_location_postcode_path(@scheme), + ) %> +<% end %> + +<%= form_for(@location, method: :patch, url: scheme_location_local_authority_path(@scheme, @location, referrer: params[:referrer])) do |f| %> +