|
|
|
@ -15,13 +15,9 @@ class LocationsController < ApplicationController |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
def new |
|
|
|
def new |
|
|
|
@location = if params[:referrer] == "new_scheme" && @scheme.locations.present? |
|
|
|
@location = Location.new(scheme: @scheme) |
|
|
|
@scheme.locations.first |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
Location.new(scheme: @scheme) |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
@location.save! |
|
|
|
@location.save! |
|
|
|
redirect_to scheme_location_postcode_path(@scheme, @location, referrer: params[:referrer]) |
|
|
|
redirect_to scheme_location_postcode_path(@scheme, @location, route: params[:route]) |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
def postcode |
|
|
|
def postcode |
|
|
|
@ -32,11 +28,11 @@ class LocationsController < ApplicationController |
|
|
|
if @location.valid?(:postcode) |
|
|
|
if @location.valid?(:postcode) |
|
|
|
@location.save! |
|
|
|
@location.save! |
|
|
|
if @location.location_code.blank? || @location.location_admin_district.blank? |
|
|
|
if @location.location_code.blank? || @location.location_admin_district.blank? |
|
|
|
redirect_to scheme_location_local_authority_path(@scheme, @location, referrer: params[:referrer]) |
|
|
|
redirect_to scheme_location_local_authority_path(@scheme, @location, route: params[:route], referrer: params[:referrer]) |
|
|
|
elsif params[:referrer] == "check_answers" |
|
|
|
elsif params[:referrer] == "check_answers" |
|
|
|
redirect_to scheme_location_check_answers_path(@scheme, @location) |
|
|
|
redirect_to scheme_location_check_answers_path(@scheme, @location, route: params[:route]) |
|
|
|
else |
|
|
|
else |
|
|
|
redirect_to scheme_location_name_path(@scheme, @location, referrer: params[:referrer]) |
|
|
|
redirect_to scheme_location_name_path(@scheme, @location, route: params[:route]) |
|
|
|
end |
|
|
|
end |
|
|
|
else |
|
|
|
else |
|
|
|
render :postcode, status: :unprocessable_entity |
|
|
|
render :postcode, status: :unprocessable_entity |
|
|
|
@ -50,10 +46,10 @@ class LocationsController < ApplicationController |
|
|
|
@location.location_code = Location.local_authorities.key(params[:location][:location_admin_district]) |
|
|
|
@location.location_code = Location.local_authorities.key(params[:location][:location_admin_district]) |
|
|
|
if @location.valid?(:location_admin_district) |
|
|
|
if @location.valid?(:location_admin_district) |
|
|
|
@location.save! |
|
|
|
@location.save! |
|
|
|
if params[:referrer] == "check_answers" |
|
|
|
if params[:referrer] == "check_answers" || params[:referrer] == "check_local_authority" |
|
|
|
redirect_to scheme_location_check_answers_path(@scheme, @location) |
|
|
|
redirect_to scheme_location_check_answers_path(@scheme, @location, route: params[:route]) |
|
|
|
else |
|
|
|
else |
|
|
|
redirect_to scheme_location_name_path(@scheme, @location, referrer: params[:referrer]) |
|
|
|
redirect_to scheme_location_name_path(@scheme, @location, route: params[:route]) |
|
|
|
end |
|
|
|
end |
|
|
|
else |
|
|
|
else |
|
|
|
render :local_authority, status: :unprocessable_entity |
|
|
|
render :local_authority, status: :unprocessable_entity |
|
|
|
@ -68,11 +64,11 @@ class LocationsController < ApplicationController |
|
|
|
@location.save! |
|
|
|
@location.save! |
|
|
|
case params[:referrer] |
|
|
|
case params[:referrer] |
|
|
|
when "check_answers" |
|
|
|
when "check_answers" |
|
|
|
redirect_to scheme_location_check_answers_path(@scheme, @location) |
|
|
|
redirect_to scheme_location_check_answers_path(@scheme, @location, route: params[:route]) |
|
|
|
when "details" |
|
|
|
when "details" |
|
|
|
redirect_to scheme_location_path(@scheme, @location) |
|
|
|
redirect_to scheme_location_path(@scheme, @location) |
|
|
|
else |
|
|
|
else |
|
|
|
redirect_to scheme_location_units_path(@scheme, @location, referrer: params[:referrer]) |
|
|
|
redirect_to scheme_location_units_path(@scheme, @location, route: params[:route]) |
|
|
|
end |
|
|
|
end |
|
|
|
else |
|
|
|
else |
|
|
|
render :name, status: :unprocessable_entity |
|
|
|
render :name, status: :unprocessable_entity |
|
|
|
@ -86,9 +82,9 @@ class LocationsController < ApplicationController |
|
|
|
if @location.valid?(:units) |
|
|
|
if @location.valid?(:units) |
|
|
|
@location.save! |
|
|
|
@location.save! |
|
|
|
if params[:referrer] == "check_answers" |
|
|
|
if params[:referrer] == "check_answers" |
|
|
|
redirect_to scheme_location_check_answers_path(@scheme, @location) |
|
|
|
redirect_to scheme_location_check_answers_path(@scheme, @location, route: params[:route]) |
|
|
|
else |
|
|
|
else |
|
|
|
redirect_to scheme_location_type_of_unit_path(@scheme, @location, referrer: params[:referrer]) |
|
|
|
redirect_to scheme_location_type_of_unit_path(@scheme, @location, route: params[:route]) |
|
|
|
end |
|
|
|
end |
|
|
|
else |
|
|
|
else |
|
|
|
render :units, status: :unprocessable_entity |
|
|
|
render :units, status: :unprocessable_entity |
|
|
|
@ -102,9 +98,9 @@ class LocationsController < ApplicationController |
|
|
|
if @location.valid?(:type_of_unit) |
|
|
|
if @location.valid?(:type_of_unit) |
|
|
|
@location.save! |
|
|
|
@location.save! |
|
|
|
if params[:referrer] == "check_answers" |
|
|
|
if params[:referrer] == "check_answers" |
|
|
|
redirect_to scheme_location_check_answers_path(@scheme, @location) |
|
|
|
redirect_to scheme_location_check_answers_path(@scheme, @location, route: params[:route]) |
|
|
|
else |
|
|
|
else |
|
|
|
redirect_to scheme_location_mobility_standards_path(@scheme, @location, referrer: params[:referrer]) |
|
|
|
redirect_to scheme_location_mobility_standards_path(@scheme, @location, route: params[:route]) |
|
|
|
end |
|
|
|
end |
|
|
|
else |
|
|
|
else |
|
|
|
render :type_of_unit, status: :unprocessable_entity |
|
|
|
render :type_of_unit, status: :unprocessable_entity |
|
|
|
@ -118,9 +114,9 @@ class LocationsController < ApplicationController |
|
|
|
if @location.valid?(:mobility_type) |
|
|
|
if @location.valid?(:mobility_type) |
|
|
|
@location.save! |
|
|
|
@location.save! |
|
|
|
if params[:referrer] == "check_answers" |
|
|
|
if params[:referrer] == "check_answers" |
|
|
|
redirect_to scheme_location_check_answers_path(@scheme, @location) |
|
|
|
redirect_to scheme_location_check_answers_path(@scheme, @location, route: params[:route]) |
|
|
|
else |
|
|
|
else |
|
|
|
redirect_to scheme_location_availability_path(@scheme, @location, referrer: params[:referrer]) |
|
|
|
redirect_to scheme_location_availability_path(@scheme, @location, route: params[:route]) |
|
|
|
end |
|
|
|
end |
|
|
|
else |
|
|
|
else |
|
|
|
render :mobility_standards, status: :unprocessable_entity |
|
|
|
render :mobility_standards, status: :unprocessable_entity |
|
|
|
@ -138,7 +134,7 @@ class LocationsController < ApplicationController |
|
|
|
@location.startdate = Time.zone.local(year.to_i, month.to_i, day.to_i) |
|
|
|
@location.startdate = Time.zone.local(year.to_i, month.to_i, day.to_i) |
|
|
|
if @location.valid?(:startdate) |
|
|
|
if @location.valid?(:startdate) |
|
|
|
@location.save! |
|
|
|
@location.save! |
|
|
|
redirect_to scheme_location_check_answers_path(@scheme, @location, referrer: params[:referrer]) |
|
|
|
redirect_to scheme_location_check_answers_path(@scheme, @location, route: params[:route]) |
|
|
|
else |
|
|
|
else |
|
|
|
render :availability, status: :unprocessable_entity |
|
|
|
render :availability, status: :unprocessable_entity |
|
|
|
end |
|
|
|
end |
|
|
|
@ -157,6 +153,8 @@ class LocationsController < ApplicationController |
|
|
|
|
|
|
|
|
|
|
|
def check_answers |
|
|
|
def check_answers |
|
|
|
if params[:location].present? |
|
|
|
if params[:location].present? |
|
|
|
|
|
|
|
@location.confirmed = true |
|
|
|
|
|
|
|
@location.save! |
|
|
|
flash[:notice] = "#{@location.postcode} #{@location.startdate < Time.zone.now ? 'has been' : 'will be'} added to this scheme" |
|
|
|
flash[:notice] = "#{@location.postcode} #{@location.startdate < Time.zone.now ? 'has been' : 'will be'} added to this scheme" |
|
|
|
redirect_to scheme_locations_path(@scheme) |
|
|
|
redirect_to scheme_locations_path(@scheme) |
|
|
|
end |
|
|
|
end |
|
|
|
|