Class: UiObjects::RelatableCategoryDropDown

Inherits:
UiObject
  • Object
show all
Defined in:
lib/question_chain/models/ui_objects/relatable_category_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



52
53
54
# File 'lib/question_chain/models/ui_objects/relatable_category_drop_down.rb', line 52

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

Instance Method Details

#get_target_drop_down_options(relatable_category_ids = []) ⇒ Object



43
44
45
46
47
48
49
50
# File 'lib/question_chain/models/ui_objects/relatable_category_drop_down.rb', line 43

def get_target_drop_down_options(relatable_category_ids = [])
  if drop_down_target_is_relatable
    id = relatable_category_ids.shift
    QuestionChain.calculated_session.related_categories_from_relatable_category(id.to_s, drop_down_target.related_attribute, {:relatable_category_ids => relatable_category_ids, :per_page => per_page})
  else
    QuestionChain.calculated_session.related_objects_from_relatable_categories(self.object_name, relatable_category_ids, :per_page => per_page)
  end
end

#optionsObject



36
37
38
39
40
41
# File 'lib/question_chain/models/ui_objects/relatable_category_drop_down.rb', line 36

def options
  return [] if !populate
  @options ||= relatable_categories.select{|obj| (filters.empty? || (!filters.empty? && filters.include?(obj.id.to_s)))}.map do |obj|
    {:value => obj.id, :name => obj.name}
  end.sort_by{|option| option[:name]}
end