|
|
|
@ -61,27 +61,33 @@ class LocationsController < ApplicationController
|
|
|
|
|
error_message = I18n.t("validations.location_admin_district") |
|
|
|
|
@location.errors.add :location_admin_district, error_message |
|
|
|
|
render :edit_local_authority, status: :unprocessable_entity |
|
|
|
|
elsif @location.update(location_params) |
|
|
|
|
case page |
|
|
|
|
when "edit" |
|
|
|
|
if @location.location_admin_district.nil? |
|
|
|
|
redirect_to(location_edit_local_authority_path(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_location_path(@location.scheme)) |
|
|
|
|
else |
|
|
|
|
redirect_to(scheme_check_answers_path(@scheme, anchor: "locations")) |
|
|
|
|
end |
|
|
|
|
when "edit-name" |
|
|
|
|
redirect_to(scheme_check_answers_path(@scheme, anchor: "locations")) |
|
|
|
|
when "edit-local-authority" |
|
|
|
|
if params[:add_another_location] == "Yes" |
|
|
|
|
redirect_to(new_location_path(@location.scheme)) |
|
|
|
|
else |
|
|
|
|
else |
|
|
|
|
if page == "edit-local-authority" |
|
|
|
|
la_list = FormHandler.instance.current_lettings_form.get_question("la", nil).answer_options |
|
|
|
|
params[:location][:location_code] = la_list.key(params[:location][:location_admin_district]) |
|
|
|
|
end |
|
|
|
|
if @location.update(location_params) |
|
|
|
|
case page |
|
|
|
|
when "edit" |
|
|
|
|
if @location.location_admin_district.nil? |
|
|
|
|
redirect_to(location_edit_local_authority_path(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_location_path(@location.scheme)) |
|
|
|
|
else |
|
|
|
|
redirect_to(scheme_check_answers_path(@scheme, anchor: "locations")) |
|
|
|
|
end |
|
|
|
|
when "edit-name" |
|
|
|
|
redirect_to(scheme_check_answers_path(@scheme, anchor: "locations")) |
|
|
|
|
when "edit-local-authority" |
|
|
|
|
if params[:add_another_location] == "Yes" |
|
|
|
|
redirect_to(new_location_path(@location.scheme)) |
|
|
|
|
else |
|
|
|
|
redirect_to(scheme_check_answers_path(@scheme, anchor: "locations")) |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
else |
|
|
|
|
render :edit, status: :unprocessable_entity |
|
|
|
|
end |
|
|
|
|
else |
|
|
|
|
render :edit, status: :unprocessable_entity |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
|
|
|
|
@ -123,7 +129,7 @@ private
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
def location_params |
|
|
|
|
required_params = params.require(:location).permit(:postcode, :name, :units, :type_of_unit, :add_another_location, :startdate, :mobility_type, :location_admin_district).merge(scheme_id: @scheme.id) |
|
|
|
|
required_params = params.require(:location).permit(:postcode, :name, :units, :type_of_unit, :add_another_location, :startdate, :mobility_type, :location_admin_district, :location_code).merge(scheme_id: @scheme.id) |
|
|
|
|
required_params[:postcode] = PostcodeService.clean(required_params[:postcode]) if required_params[:postcode] |
|
|
|
|
required_params |
|
|
|
|
end |
|
|
|
|