|
|
|
@ -1,6 +1,4 @@ |
|
|
|
class Form::Lettings::Questions::StockOwner < ::Form::Question |
|
|
|
class Form::Lettings::Questions::StockOwner < ::Form::Question |
|
|
|
attr_accessor :current_user, :log |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def initialize(id, hsh, page) |
|
|
|
def initialize(id, hsh, page) |
|
|
|
super |
|
|
|
super |
|
|
|
@id = "owning_organisation_id" |
|
|
|
@id = "owning_organisation_id" |
|
|
|
@ -9,38 +7,38 @@ class Form::Lettings::Questions::StockOwner < ::Form::Question |
|
|
|
@type = "select" |
|
|
|
@type = "select" |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
def answer_options |
|
|
|
def answer_options(log = nil, user = nil) |
|
|
|
answer_opts = { "" => "Select an option" } |
|
|
|
answer_opts = { "" => "Select an option" } |
|
|
|
|
|
|
|
|
|
|
|
return answer_opts unless ActiveRecord::Base.connected? |
|
|
|
return answer_opts unless ActiveRecord::Base.connected? |
|
|
|
return answer_opts unless current_user |
|
|
|
return answer_opts unless user |
|
|
|
return answer_opts unless log |
|
|
|
return answer_opts unless log |
|
|
|
|
|
|
|
|
|
|
|
if log.owning_organisation_id.present? |
|
|
|
if log.owning_organisation_id.present? |
|
|
|
answer_opts = answer_opts.merge({ log.owning_organisation.id => log.owning_organisation.name }) |
|
|
|
answer_opts = answer_opts.merge({ log.owning_organisation.id => log.owning_organisation.name }) |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
if !current_user.support? && current_user.organisation.holds_own_stock? |
|
|
|
if !user.support? && user.organisation.holds_own_stock? |
|
|
|
answer_opts[current_user.organisation.id] = "#{current_user.organisation.name} (Your organisation)" |
|
|
|
answer_opts[user.organisation.id] = "#{user.organisation.name} (Your organisation)" |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
stock_owners_answer_options = if user.support? |
|
|
|
|
|
|
|
Organisation |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
user.organisation.stock_owners |
|
|
|
|
|
|
|
end.pluck(:id, :name).to_h |
|
|
|
|
|
|
|
|
|
|
|
answer_opts.merge(stock_owners_answer_options) |
|
|
|
answer_opts.merge(stock_owners_answer_options) |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
def displayed_answer_options(log, user = nil) |
|
|
|
def displayed_answer_options(log, user = nil) |
|
|
|
@current_user = user |
|
|
|
answer_options(log, user) |
|
|
|
@log = log |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
answer_options |
|
|
|
|
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
def label_from_value(value, log = nil, user = nil) |
|
|
|
def label_from_value(value, log = nil, user = nil) |
|
|
|
@log = log |
|
|
|
|
|
|
|
@current_user = user |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return unless value |
|
|
|
return unless value |
|
|
|
|
|
|
|
|
|
|
|
answer_options[value] |
|
|
|
answer_options(log, user)[value] |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
def derived? |
|
|
|
def derived? |
|
|
|
@ -48,13 +46,11 @@ class Form::Lettings::Questions::StockOwner < ::Form::Question |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
def hidden_in_check_answers?(_log, user = nil) |
|
|
|
def hidden_in_check_answers?(_log, user = nil) |
|
|
|
@current_user = user |
|
|
|
return false if user.support? |
|
|
|
|
|
|
|
|
|
|
|
return false if current_user.support? |
|
|
|
stock_owners = user.organisation.stock_owners |
|
|
|
|
|
|
|
|
|
|
|
stock_owners = current_user.organisation.stock_owners |
|
|
|
if user.organisation.holds_own_stock? |
|
|
|
|
|
|
|
|
|
|
|
if current_user.organisation.holds_own_stock? |
|
|
|
|
|
|
|
stock_owners.count.zero? |
|
|
|
stock_owners.count.zero? |
|
|
|
else |
|
|
|
else |
|
|
|
stock_owners.count <= 1 |
|
|
|
stock_owners.count <= 1 |
|
|
|
@ -70,12 +66,4 @@ private |
|
|
|
def selected_answer_option_is_derived?(_log) |
|
|
|
def selected_answer_option_is_derived?(_log) |
|
|
|
true |
|
|
|
true |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
def stock_owners_answer_options |
|
|
|
|
|
|
|
if current_user.support? |
|
|
|
|
|
|
|
Organisation |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
current_user.organisation.stock_owners |
|
|
|
|
|
|
|
end.pluck(:id, :name).to_h |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
end |
|
|
|
end |
|
|
|
|