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.
49 lines
1.0 KiB
49 lines
1.0 KiB
2 years ago
|
class Form::Common::Questions::CreatedById < ::Form::Question
|
||
2 years ago
|
def initialize(id, hsh, page)
|
||
|
super
|
||
|
@id = "created_by_id"
|
||
|
@check_answer_label = "User"
|
||
|
@header = "Which user are you creating this log for?"
|
||
|
@hint_text = ""
|
||
|
@type = "select"
|
||
|
@page = page
|
||
|
end
|
||
|
|
||
2 years ago
|
def answer_options
|
||
2 years ago
|
answer_opts = { "" => "Select an option" }
|
||
|
return answer_opts unless ActiveRecord::Base.connected?
|
||
|
|
||
2 years ago
|
User.select(:id, :name).each_with_object(answer_opts) do |user, hsh|
|
||
|
hsh[user.id] = user.name
|
||
2 years ago
|
hsh
|
||
|
end
|
||
|
end
|
||
|
|
||
2 years ago
|
def displayed_answer_options(log)
|
||
|
return answer_options unless log.owning_organisation
|
||
2 years ago
|
|
||
2 years ago
|
user_ids = log.owning_organisation.users.pluck(:id) + [""]
|
||
2 years ago
|
answer_options.select { |k, _v| user_ids.include?(k) }
|
||
|
end
|
||
|
|
||
|
def label_from_value(value)
|
||
|
return unless value
|
||
|
|
||
|
answer_options[value]
|
||
|
end
|
||
|
|
||
2 years ago
|
def hidden_in_check_answers?(_log, current_user)
|
||
2 years ago
|
!current_user.support?
|
||
|
end
|
||
|
|
||
|
def derived?
|
||
|
true
|
||
2 years ago
|
end
|
||
2 years ago
|
|
||
|
private
|
||
|
|
||
2 years ago
|
def selected_answer_option_is_derived?(_log)
|
||
2 years ago
|
false
|
||
|
end
|
||
2 years ago
|
end
|