class Savio::ButtonManager
Attributes
selected[R]
Public Class Methods
new(args = {})
click to toggle source
# File lib/savio/ButtonManager.rb, line 10 def initialize(args = {}) @@buttonManagers.push(self) @buttons = [] @selected = [] @type = args[:type] || 'radio' if @type != 'checkbox' && @type != 'radio' raise ArgumentError, 'ButtonManager type ' + @type.to_s + ' is invalid. Must be radio or checkbox' end end
Public Instance Methods
addButton(button)
click to toggle source
# File lib/savio/ButtonManager.rb, line 32 def addButton(button) if button.class.name != 'Savio::Button' raise ArgumentError, 'Given object ' + button.to_s + ' is not a Button. Must be of type Button' end button.deselect(false) @buttons.push(button) if button.buttonManager != self button.buttonManager = self end end
deselect(button)
click to toggle source
# File lib/savio/ButtonManager.rb, line 91 def deselect(button) if @buttons.include?(button) if @type == 'checkbox' @selected.delete(button) button.deselect(false) elsif @type == 'radio' @selected.delete(button) button.deselect(false) end else raise ArgumentError, ('Could not find button ' + button.to_s + ' in buttonManager') end end
removeButton(button, overwrite = true)
click to toggle source
# File lib/savio/ButtonManager.rb, line 43 def removeButton(button, overwrite = true) if @buttons.include?(button) @buttons.delete(button) if @selected.include?(button) @selected.delete(button) end if overwrite == true button.buttonManager = nil end else raise ArgumentError, ('Could not find button ' + button.to_s + ' in buttonManager') end end
select(button)
click to toggle source
# File lib/savio/ButtonManager.rb, line 73 def select(button) if @buttons.include?(button) if @type == 'checkbox' @selected.push(button) button.select(false) elsif @type == 'radio' @buttons.each do |i| i.deselect(false) end @selected.clear @selected.push(button) button.select(false) end else raise ArgumentError, ('Could not find button ' + button.to_s + ' in buttonManager') end end
toggle(button)
click to toggle source
# File lib/savio/ButtonManager.rb, line 57 def toggle(button) if @buttons.include?(button) if @type == 'checkbox' if button.selected deselect(button) else select(button) end elsif @type == 'radio' select(button) end else raise ArgumentError, ('Could not find button ' + button.to_s + ' in buttonManager') end end
type=(type)
click to toggle source
# File lib/savio/ButtonManager.rb, line 24 def type=(type) if type == 'radio' || type == "checkbox" @type = type else raise ArgumentError, 'ButtonManager type ' + type.to_s + ' is invalid. Must be radio or checkbox' end end