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.
73 lines
1.5 KiB
73 lines
1.5 KiB
2 years ago
|
class Form::Lettings::Questions::StockOwner < ::Form::Question
|
||
2 years ago
|
attr_accessor :current_user, :log
|
||
|
|
||
|
def initialize(id, hsh, page)
|
||
|
super
|
||
|
@id = "owning_organisation_id"
|
||
2 years ago
|
@check_answer_label = "Stock owner"
|
||
2 years ago
|
@header = "Which organisation owns this property?"
|
||
|
@type = "select"
|
||
|
end
|
||
|
|
||
|
def answer_options
|
||
|
answer_opts = { "" => "Select an option" }
|
||
|
return answer_opts unless ActiveRecord::Base.connected?
|
||
|
return answer_opts unless current_user
|
||
|
|
||
|
if !current_user.support? && current_user.organisation.holds_own_stock?
|
||
|
answer_opts[current_user.organisation.id] = "#{current_user.organisation.name} (Your organisation)"
|
||
|
end
|
||
|
|
||
2 years ago
|
answer_opts.merge(stock_owners_answer_options)
|
||
2 years ago
|
end
|
||
|
|
||
|
def displayed_answer_options(log, user = nil)
|
||
|
@current_user = user
|
||
|
@log = log
|
||
|
|
||
|
answer_options
|
||
|
end
|
||
|
|
||
|
def label_from_value(value)
|
||
|
return unless value
|
||
|
|
||
|
answer_options[value]
|
||
|
end
|
||
|
|
||
|
def derived?
|
||
|
true
|
||
|
end
|
||
|
|
||
|
def hidden_in_check_answers?(_log, user = nil)
|
||
|
@current_user = user
|
||
|
|
||
2 years ago
|
return false if current_user.support?
|
||
2 years ago
|
|
||
2 years ago
|
stock_owners = current_user.organisation.stock_owners
|
||
2 years ago
|
|
||
|
if current_user.organisation.holds_own_stock?
|
||
2 years ago
|
stock_owners.count.zero?
|
||
2 years ago
|
else
|
||
2 years ago
|
stock_owners.count <= 1
|
||
2 years ago
|
end
|
||
2 years ago
|
end
|
||
|
|
||
|
def enabled
|
||
|
true
|
||
|
end
|
||
|
|
||
|
private
|
||
|
|
||
|
def selected_answer_option_is_derived?(_log)
|
||
|
true
|
||
|
end
|
||
|
|
||
2 years ago
|
def stock_owners_answer_options
|
||
2 years ago
|
if current_user.support?
|
||
|
Organisation
|
||
|
else
|
||
2 years ago
|
current_user.organisation.stock_owners
|
||
2 years ago
|
end.pluck(:id, :name).to_h
|
||
2 years ago
|
end
|
||
|
end
|