Class: UnderOs::UI::Select

Inherits:
View
  • Object
show all
Defined in:
lib/under_os/ui/select.rb

Constant Summary

Constants included from Wrap

Wrap::INSTANCES_CACHE, Wrap::RAW_WRAPS_MAP, Wrap::WRAPS_TAGS_MAP

Instance Method Summary collapse

Methods inherited from View

#inspect

Methods included from Manipulation

#append, #clear, #insert, #insertTo, #prepend, #remove

Methods included from Traversing

#children, #empty?, #find, #first, #matches, #parent, #siblings

Methods included from Dimensions

#position, #position=, #size, #size=

Methods included from Animation

#animate, #fade_in, #fade_out, #highlight

Methods included from Commons

#data, #data=, #hidden, #id, #id=, #page, #tagName, #toggle, #visible

Methods included from Styles

#addClass, #className, #className=, #classNames, #classNames=, #hasClass, #radioClass, #removeClass, #repaint, #style, #style=, #toggleClass

Methods included from Events

#emit, #off, #on, #on=

Methods included from Wrap

included

Constructor Details

#initialize(options = {}) ⇒ Select

Returns a new instance of Select.



4
5
6
7
8
9
10
11
12
13
14
# File 'lib/under_os/ui/select.rb', line 4

def initialize(options={})
  super

  self.options = options.delete(:options) if options[:options]
  self.value   = options.delete(:value)   if options[:value]

  #@_.showsSelectionIndicator = true       if options[:lense]

  @_.delegate   = self
  @_.dataSource = self
end

Instance Method Details

#hideObject



71
72
73
74
75
# File 'lib/under_os/ui/select.rb', line 71

def hide
  animate bottom: -size.y, complete: -> {
    style.display = :none
  }
end

#numberOfComponentsInPickerView(picker) ⇒ Object

UIPickerView delegate



80
81
82
# File 'lib/under_os/ui/select.rb', line 80

def numberOfComponentsInPickerView(picker)
  optgroups.size
end

#optgroupsObject



16
17
18
# File 'lib/under_os/ui/select.rb', line 16

def optgroups
  @optgroups ||= [{}]
end

#optgroups=(list) ⇒ Object



20
21
22
23
24
25
26
27
28
# File 'lib/under_os/ui/select.rb', line 20

def optgroups=(list)
  @optgroups = list.map do |hash|
    {}.tap do |clean_hash|
      hash.each do |key, value|
        clean_hash[key.to_s] = value if key && value
      end
    end
  end
end

#optionsObject



30
31
32
# File 'lib/under_os/ui/select.rb', line 30

def options
  optgroups.size == 1 ? optgroups[0] : optgroups
end

#options=(value) ⇒ Object



34
35
36
37
# File 'lib/under_os/ui/select.rb', line 34

def options=(value)
  self.optgroups = value.is_a?(Array) ? value : [value]
  @_.reloadAllComponents
end

#pickerView(picker, didSelectRow: index, inComponent: group) ⇒ Object



84
85
86
# File 'lib/under_os/ui/select.rb', line 84

def pickerView(picker, numberOfRowsInComponent: group)
  optgroups[group].size
end

#showObject



61
62
63
64
65
66
67
68
69
# File 'lib/under_os/ui/select.rb', line 61

def show
  page.find('select').each do |select|
    select.hide if select.visible && select != self
  end

  self.style = {bottom: -size.y, display: :block}

  animate bottom: 0
end

#valueObject



39
40
41
42
# File 'lib/under_os/ui/select.rb', line 39

def value
  @value ||= []
  optgroups.size == 1 ? @value[0] : @value
end

#value=(value) ⇒ Object



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/under_os/ui/select.rb', line 44

def value=(value)
  prev_val = @value
  @value = Array(value).map(&:to_s)
  emit :change if @value != prev_val

  @value.each_with_index do |value, group|
    i = 0;
    optgroups[group].each do |v, label|
      if value == v
        @_.selectRow i, inComponent: group, animated: false
      else
        i += 1
      end
    end
  end
end