class Lebowski::Foundation::Views::SelectFieldView

Represents a proxy to a SproutCore select field view (SC.SelectFieldView)

Constants

EMPTY_VALUE

Public Instance Methods

has_empty_option?() click to toggle source

Use to check if this view has an empty item

# File lib/lebowski/foundation/views/select_field.rb, line 30
def has_empty_option?()
  empty = self['emptyName']
  return (not (empty.nil? or empty.empty?))
end
select(val) click to toggle source
# File lib/lebowski/foundation/views/select_field.rb, line 62
def select(val)
  return if val.nil?

  if val.kind_of? Integer
    select_with_index(val)
  elsif val == :empty
    select_empty
  else
    select_with_name(val.to_s)
  end
end
select_empty() click to toggle source

Used to select the empty item, if there is one

@see select

# File lib/lebowski/foundation/views/select_field.rb, line 113
def select_empty()
  option_locator = "value=#{EMPTY_VALUE}"
  @driver.sc_select(:view, option_locator, self.abs_path)
  stall :select
end
select_with_index(val) click to toggle source

Used to select an item via its index

@see select

# File lib/lebowski/foundation/views/select_field.rb, line 79
def select_with_index(val)
  option_locator = "index=#{val}"
  @driver.sc_select(:view, option_locator, self.abs_path)
  stall :select
end
select_with_name(val) click to toggle source

Used to select an item via its label

@see select

# File lib/lebowski/foundation/views/select_field.rb, line 90
def select_with_name(val)
  option_locator = "label=regexi:^#{val}$"
  @driver.sc_select(:view, option_locator, self.abs_path)
  stall :select
end
select_with_value(val) click to toggle source

Used to select an item via its value

@see select

# File lib/lebowski/foundation/views/select_field.rb, line 101
def select_with_value(val)
  guid = @driver.get_sc_guid(val)
  option_locator = "value=regexi:^#{guid}$"
  @driver.sc_select(:view, option_locator, self.abs_path)
  stall :select
end
selected?() click to toggle source
# File lib/lebowski/foundation/views/select_field.rb, line 20
def selected?()
  val = self['value']
  return false if val.nil?
  return false if (val.kind_of?(String) and (val.empty? or val == EMPTY_VALUE))
  return true
end
selected_with_index?(index) click to toggle source
# File lib/lebowski/foundation/views/select_field.rb, line 58
def selected_with_index?(index)
  # TODO
end
selected_with_name?(value) click to toggle source
# File lib/lebowski/foundation/views/select_field.rb, line 35
def selected_with_name?(value)
  objs = self['objects']
  val = self['value']
  objs.each do |obj|
    name = get_object_name(obj)
    return (val == get_object_value(obj)) if (not (name =~ /^#{value}$/i).nil?)
  end
  return false
end
selected_with_value?(value) click to toggle source
# File lib/lebowski/foundation/views/select_field.rb, line 45
def selected_with_value?(value)
  objs = self['objects']
  val = self['value']
  objs.each do |obj|
    if value.kind_of? String
      return true if (not (val =~ /^#{get_object_value(obj)}$/i).nil?)
    else
      return true if (value == val)
    end
  end
  return false
end

Private Instance Methods

get_object_name(obj) click to toggle source
# File lib/lebowski/foundation/views/select_field.rb, line 121
def get_object_name(obj)
  if obj.kind_of?(ProxyObject)
    @nameKey = self["nameKey"] if @nameKey.nil?
    return obj[@nameKey]
  end
    return obj
end
get_object_value(obj) click to toggle source
# File lib/lebowski/foundation/views/select_field.rb, line 129
def get_object_value(obj)
  if obj.kind_of?(ProxyObject)
    @valueKey = self["valueKey"] if @valueKey.nil?
    return obj[@valueKey]
  end
  return obj
end