Browse Source

wip

CLDC-1348-basic-validation-for-scheme-and-location-refactor
JG 2 years ago
parent
commit
0e21e5ce63
  1. 22
      app/controllers/schemes_controller.rb
  2. 7
      app/views/schemes/new.html.erb

22
app/controllers/schemes_controller.rb

@ -25,9 +25,9 @@ class SchemesController < ApplicationController
end end
def create def create
@scheme = Scheme.new(scheme_params) @scheme = Scheme.new(scheme_params.except(:support_services_provider_before_type_cast))
validation_errors scheme_params validation_errors scheme_params.except(:support_services_provider_before_type_cast)
if @scheme.errors.empty? && @scheme.save if @scheme.errors.empty? && @scheme.save
if scheme_params[:support_services_provider].zero? if scheme_params[:support_services_provider].zero?
@ -46,9 +46,9 @@ class SchemesController < ApplicationController
check_answers = params[:scheme][:check_answers] check_answers = params[:scheme][:check_answers]
page = params[:scheme][:page] page = params[:scheme][:page]
validation_errors scheme_params validation_errors scheme_params.except(:support_services_provider_before_type_cast)
if @scheme.errors.empty? && @scheme.update(scheme_params) if @scheme.errors.empty? && @scheme.update(scheme_params.except(:support_services_provider_before_type_cast))
if check_answers if check_answers
if confirm_secondary_page? page if confirm_secondary_page? page
redirect_to scheme_secondary_client_group_path(@scheme, check_answers: "true") redirect_to scheme_secondary_client_group_path(@scheme, check_answers: "true")
@ -162,18 +162,24 @@ private
:secondary_client_group, :secondary_client_group,
:support_type, :support_type,
:support_services_provider, :support_services_provider,
:support_services_provider_before_type_cast,
:intended_stay) :intended_stay)
same_org_providing_support = required_params[:support_services_provider] == "0" same_org_providing_support = required_params[:support_services_provider_before_type_cast] == "0"
full_params = same_org_providing_support && required_params[:owning_organisation_id].present? ? required_params.merge(managing_organisation_id: required_params[:owning_organisation_id]) : required_params full_params = same_org_providing_support && required_params[:owning_organisation_id].present? ? required_params.merge(managing_organisation_id: required_params[:owning_organisation_id]) : required_params
full_params[:sensitive] = full_params[:sensitive].to_i if full_params[:sensitive] full_params[:sensitive] = full_params[:sensitive].to_i if full_params[:sensitive]
full_params[:support_services_provider] = full_params[:support_services_provider].to_i if full_params[:support_services_provider]
if full_params[:support_services_provider_before_type_cast]
translated_params = full_params.merge(support_services_provider: full_params[:support_services_provider_before_type_cast].to_i)
else
translated_params = full_params
end
if current_user.data_coordinator? if current_user.data_coordinator?
full_params[:owning_organisation_id] = current_user.organisation_id translated_params[:owning_organisation_id] = current_user.organisation_id
end end
full_params translated_params
end end
def search_term def search_term

7
app/views/schemes/new.html.erb

@ -69,15 +69,16 @@
<% OpenStruct.new(id: value, name: key.to_s.humanize) %> <% OpenStruct.new(id: value, name: key.to_s.humanize) %>
<% end %> <% end %>
<%= f.govuk_collection_radio_buttons :support_services_provider, <%= f.govuk_collection_radio_buttons :support_services_provider_before_type_cast,
support_services_provider_selection, support_services_provider_selection,
:id, :id,
->(option) do ->(option) do
if option.id.zero? && !current_user.support? if option.id.zero? && !current_user.support?
"Your organisation" "Your organisation"
else else
option.name option.name
end end
end,
legend: { text: "Who provides the support services used by this scheme?", size: "m" } %> legend: { text: "Who provides the support services used by this scheme?", size: "m" } %>
<%= f.govuk_submit "Save and continue" %> <%= f.govuk_submit "Save and continue" %>

Loading…
Cancel
Save