Class: Anoubis::Output::TabItem

Inherits:
Object
  • Object
show all
Defined in:
app/controllers/anoubis/output/frame.rb

Overview

Subclass of tab element.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ TabItem

Initializes tab element data. Generates default values.



100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
# File 'app/controllers/anoubis/output/frame.rb', line 100

def initialize(options = {})
  if options.has_key? :tab
    self.tab = options[:tab].to_s
  else
    self.tab = ''
  end

  if options.has_key? :title
    self.title = options[:title]
  else
    self.title = ''
  end

  if options.has_key? :hint
    self.hint = options[:hint]
  else
    self.hint = ''
  end

  if options.has_key? :filter
    self.filter = options[:filter]
  else
    self.filter = true
  end

  if options.has_key? :export
    self.export = options[:export]
  else
    self.export = true
  end

  self.button_items = []
  self.buttons = {}

  if options.has_key? :buttons
    options[:buttons].each do |key, button|
      button[:key] = key.to_s
      self.addButton(button)
    end
  end
end

Instance Attribute Details

#button_itemsArray



84
# File 'app/controllers/anoubis/output/frame.rb', line 84

class_attribute :button_items

#buttonsHash



88
# File 'app/controllers/anoubis/output/frame.rb', line 88

class_attribute :buttons

#exportBoolean



96
# File 'app/controllers/anoubis/output/frame.rb', line 96

class_attribute :export

#filterBoolean



92
# File 'app/controllers/anoubis/output/frame.rb', line 92

class_attribute :filter

#hintstring



80
# File 'app/controllers/anoubis/output/frame.rb', line 80

class_attribute :hint

#tabstring



72
# File 'app/controllers/anoubis/output/frame.rb', line 72

class_attribute :tab

#titlestring



76
# File 'app/controllers/anoubis/output/frame.rb', line 76

class_attribute :title

Instance Method Details

#addButton(options) ⇒ Object

Adds new button into frame buttons hash hash

Options Hash (options):

  • :key (String)

    The identifier of the button element.

  • :type (String)

    The type of the button (‘primary’, ‘danger’, ‘default’)

  • :mode (String)

    The button action object (‘single’, ‘multiple’)



148
149
150
151
152
# File 'app/controllers/anoubis/output/frame.rb', line 148

def addButton(options)
  button = FrameButtonItem.new options
  self.button_items.push button
  self.buttons[button.key.to_s.to_sym] = self.button_items[self.button_items.count-1]
end

#to_hHash

Generates hash representation of output class



157
158
159
160
161
162
163
164
165
166
167
168
169
170
# File 'app/controllers/anoubis/output/frame.rb', line 157

def to_h
  result = {
      tab: self.tab,
      title: self.title,
      buttons: [],
      filter: self.filter,
      export: self.export
  }
  result[:hint] = self.hint if self.hint != ''
  self.button_items.each { |item|
    result[:buttons].push(item.to_h) if item
  }
  result
end