Manny Dinssa
6 days ago
11 changed files with 84 additions and 57 deletions
@ -0,0 +1,23 @@
|
||||
class Form::Lettings::Pages::AddressSearch < ::Form::Page |
||||
def initialize(id, hsh, subsection) |
||||
super |
||||
@id = "address_search" |
||||
@depends_on = [ |
||||
{ "uprn_known" => nil }, |
||||
{ "uprn_known" => 0 }, |
||||
{ "uprn_confirmed" => 0 }, |
||||
] |
||||
end |
||||
|
||||
def questions |
||||
@questions ||= [ |
||||
Form::Lettings::Questions::AddressSearch.new(nil, nil, self), |
||||
] |
||||
end |
||||
|
||||
def skip_href(log = nil) |
||||
return unless log |
||||
|
||||
"/#{log.model_name.param_key.dasherize}s/#{log.id}/property-unit-type" |
||||
end |
||||
end |
@ -0,0 +1,30 @@
|
||||
class Form::Lettings::Questions::AddressSearch < ::Form::Question |
||||
def initialize(id, hsh, page) |
||||
super |
||||
@id = "address_search" |
||||
@type = "address_autocomplete" |
||||
@plain_label = true |
||||
end |
||||
|
||||
def answer_options(log = nil, _user = nil) |
||||
return {} unless ActiveRecord::Base.connected? |
||||
return {} unless log&.address_options |
||||
|
||||
answer_opts = {} |
||||
|
||||
(0...[log.address_options.count, 10].min).each do |i| |
||||
answer_opts[log.address_options[i][:uprn]] = { "value" => log.address_options[i][:address] } |
||||
end |
||||
|
||||
answer_opts["divider"] = { "value" => true } |
||||
answer_opts |
||||
end |
||||
|
||||
def displayed_answer_options(log, user = nil) |
||||
answer_options(log, user).transform_values { |value| value["value"] } || {} |
||||
end |
||||
|
||||
def hidden_in_check_answers?(log, _current_user = nil) |
||||
(log.uprn_known == 1 || log.uprn_confirmed == 1) |
||||
end |
||||
end |
Loading…
Reference in new issue