Class: Redmine::FieldFormat::UserFormat

Inherits:
RecordList show all
Defined in:
lib/redmine/field_format.rb

Instance Method Summary collapse

Methods inherited from RecordList

#cast_single_value, #group_statement, #join_for_order_statement, #order_statement, #possible_custom_value_options, #reset_target_class, #target_class

Methods inherited from List

#bulk_edit_tag, #edit_tag, #query_filter_options

Methods inherited from Base

#bulk_edit_tag, #cast_custom_value, #cast_single_value, #cast_value, #edit_tag, field_attributes, #formatted_custom_value, #formatted_value, #group_statement, #join_for_order_statement, #label, #name, #order_statement, #possible_custom_value_options, #query_filter_options, #target_class, #validate_custom_field, #validate_custom_value, #validate_single_value

Methods included from I18n

#current_language, #day_letter, #day_name, #find_language, #format_date, #format_time, included, #l, #l_hours, #l_or_humanize, #languages_options, #ll, #month_name, #set_language_if_valid, #valid_languages

Instance Method Details

#before_custom_field_save(custom_field) ⇒ Object


671
672
673
674
675
676
# File 'lib/redmine/field_format.rb', line 671

def before_custom_field_save(custom_field)
  super
  if custom_field.user_role.is_a?(Array)
    custom_field.user_role.map!(&:to_s).reject!(&:blank?)
  end
end

#possible_values_options(custom_field, object = nil) ⇒ Object


653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
# File 'lib/redmine/field_format.rb', line 653

def possible_values_options(custom_field, object=nil)
  if object.is_a?(Array)
    projects = object.map {|o| o.respond_to?(:project) ? o.project : nil}.compact.uniq
    projects.map {|project| possible_values_options(custom_field, project)}.reduce(:&) || []
  elsif object.respond_to?(:project) && object.project
    scope = object.project.users
    if custom_field.user_role.is_a?(Array)
      role_ids = custom_field.user_role.map(&:to_s).reject(&:blank?).map(&:to_i)
      if role_ids.any?
        scope = scope.where("#{Member.table_name}.id IN (SELECT DISTINCT member_id FROM #{MemberRole.table_name} WHERE role_id IN (?))", role_ids)
      end
    end
    scope.sorted.collect {|u| [u.to_s, u.id.to_s]}
  else
    []
  end
end