Class: UiObjects::ObjectReferenceDropDown

Inherits:
UiObject
  • Object
show all
Defined in:
lib/question_chain/models/ui_objects/object_reference_drop_down.rb

Instance Attribute Summary

Attributes inherited from UiObject

#value

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from UiObject

#change_value!, #enabled?, #initialize, #per_page, #visible?

Constructor Details

This class inherits a constructor from UiObject

Class Method Details

.attributes_for_apiObject



33
34
35
# File 'lib/question_chain/models/ui_objects/object_reference_drop_down.rb', line 33

def self.attributes_for_api
  %w(id name _type label description rules default_value ui_attributes options prompt max_options object_name drop_down_target_id  extra_info css_classes)
end

Instance Method Details

#get_target_drop_down_options(object_ids = []) ⇒ Object

 object_reference drop down can only target its formula units basically only 1 object in this instance



39
40
41
42
43
44
45
46
47
48
49
# File 'lib/question_chain/models/ui_objects/object_reference_drop_down.rb', line 39

def get_target_drop_down_options(object_ids = [])
  if object_id = object_ids.first
    formula_inputs = QuestionChain.calculated_session.formula_inputs_for_generic_object(object_id.to_s)
    if respond_to?(:drop_down_target_options_filters) && !drop_down_target_options_filters.empty?
      selected_formula_inputs = formula_inputs.select{|f| drop_down_target_options_filters.map(&:downcase).include?(f.name.downcase)}
      selected_formula_inputs.inject({}){|var, fi| var.merge!({fi.name => fi.label_input_units}); var}
    else
      formula_inputs.inject({}){|var, fi| var.merge!({fi.name => fi.label_input_units}); var}
    end
  end
end

#optionsObject



28
29
30
31
# File 'lib/question_chain/models/ui_objects/object_reference_drop_down.rb', line 28

def options
  return [] if !populate
  @options ||= get_options(object_name, filters || [])
end