You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
50 lines
1.7 KiB
50 lines
1.7 KiB
2 years ago
|
class Form::Lettings::Questions::SchemeId < ::Form::Question
|
||
3 years ago
|
def initialize(_id, hsh, page)
|
||
|
super("scheme_id", hsh, page)
|
||
|
@check_answer_label = "Scheme name"
|
||
|
@header = "What scheme is this log for?"
|
||
|
@hint_text = "Enter scheme name or postcode"
|
||
|
@type = "select"
|
||
|
@answer_options = answer_options
|
||
2 years ago
|
@guidance_position = GuidancePosition::BOTTOM
|
||
|
@guidance_partial = "scheme_selection"
|
||
3 years ago
|
end
|
||
|
|
||
|
def answer_options
|
||
2 years ago
|
answer_opts = { "" => "Select an option" }
|
||
3 years ago
|
return answer_opts unless ActiveRecord::Base.connected?
|
||
|
|
||
2 years ago
|
Scheme.select(:id, :service_name, :primary_client_group, :secondary_client_group).each_with_object(answer_opts) do |scheme, hsh|
|
||
|
hsh[scheme.id.to_s] = scheme
|
||
3 years ago
|
hsh
|
||
|
end
|
||
|
end
|
||
|
|
||
2 years ago
|
def displayed_answer_options(lettings_log)
|
||
|
organisation = lettings_log.owning_organisation || lettings_log.created_by&.organisation
|
||
2 years ago
|
schemes = organisation ? Scheme.select(:id).where(owning_organisation_id: organisation.id, confirmed: true) : Scheme.select(:id).where(confirmed: true)
|
||
2 years ago
|
filtered_scheme_ids = schemes.joins(:locations).merge(Location.where("startdate <= ? or startdate IS NULL", Time.zone.today)).map(&:id)
|
||
3 years ago
|
answer_options.select do |k, _v|
|
||
2 years ago
|
filtered_scheme_ids.include?(k.to_i) || k.blank?
|
||
3 years ago
|
end
|
||
|
end
|
||
|
|
||
2 years ago
|
def hidden_in_check_answers?(lettings_log, _current_user = nil)
|
||
|
!supported_housing_selected?(lettings_log)
|
||
3 years ago
|
end
|
||
|
|
||
2 years ago
|
def answer_selected?(lettings_log, answer)
|
||
|
lettings_log[id] == answer.name || lettings_log[id] == answer.resource
|
||
2 years ago
|
end
|
||
|
|
||
3 years ago
|
private
|
||
|
|
||
2 years ago
|
def supported_housing_selected?(lettings_log)
|
||
|
lettings_log.needstype == 2
|
||
3 years ago
|
end
|
||
3 years ago
|
|
||
2 years ago
|
def selected_answer_option_is_derived?(_lettings_log)
|
||
3 years ago
|
false
|
||
|
end
|
||
3 years ago
|
end
|