Class: Anoubis::Output::Menu

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

Overview

Output subclass that represents data for menu action

Instance Attribute Summary collapse

Attributes inherited from Basic

#messages, #result, #tab, #title

Instance Method Summary collapse

Methods inherited from Basic

#hash_to_json, #options_to_json

Constructor Details

#initializeMenu

Initializes menu output data. Generates default values.



20
21
22
23
24
25
# File 'app/controllers/anoubis/output/menu.rb', line 20

def initialize
  super
  self.items = []
  self.keys = {}
  self.user = {}
end

Instance Attribute Details

#itemsArray

Returns the array of menu elements Anoubis::Output::MenuItem.

Returns:



8
# File 'app/controllers/anoubis/output/menu.rb', line 8

class_attribute :items

#keysHash

Returns the hash of menu elements Anoubis::Output::MenuItem with ‘mode’ as a key.

Returns:



12
# File 'app/controllers/anoubis/output/menu.rb', line 12

class_attribute :keys

#userHash

Returns the hash of user information.

Returns:

  • (Hash)

    the hash of user information.



16
# File 'app/controllers/anoubis/output/menu.rb', line 16

class_attribute :user

Instance Method Details

#addElement(options) ⇒ Object

Adds new element into menu hash

Parameters:

  • options (Hash)

    the menu element options

Options Hash (options):

  • :title (String)

    The title of the menu element.

  • :page_title (String)

    The page title of the menu element.

  • :short_title (String)

    The short title of the menu element.

  • :mode (String)

    The mode of the menu element.

  • :action (String)

    The action type of the menu element (‘menu’, ‘data’).

  • :position (Number)

    The position of the menu element in current level.

  • :tab (Number)

    The level of the menu element.

  • :state (String)

    The show state of the menu element (‘visible’, ‘hidden’).

  • :access (String)

    The access to the menu element for current user (‘read’, ‘write’).



39
40
41
42
43
44
45
46
47
48
# File 'app/controllers/anoubis/output/menu.rb', line 39

def addElement(options)
  if options.has_key? :parent
    if !self.keys.has_key? options[:parent].to_s.to_sym
      options[:parent] = nil
    end
  end
  menu = MenuItem.new options
  self.items.push menu
  self.keys[menu.mode.to_s.to_sym] = self.items[self.items.count-1]
end

#key(mode) ⇒ MenuItem | nil

Returns menu element

Parameters:

  • mode (String)

    the mode of returned menu element

Returns:

  • (MenuItem | nil)

    menu element or nil if element isn’t exists



80
81
82
83
84
85
86
87
# File 'app/controllers/anoubis/output/menu.rb', line 80

def key(mode)
  if self.keys.has_key? mode.to_s.to_sym

    return self.keys[mode.to_s.to_sym]
  else
    return nil
  end
end

#messageString

Generates output message based on self.result variable.

Returns:

  • (String)

    output message



67
68
69
70
71
72
73
74
# File 'app/controllers/anoubis/output/menu.rb', line 67

def message
  case self.result
  when 0
    return I18n.t('success')
  else
    return I18n.t('invalid_menu_output')
  end
end

#to_hHash

Generates hash representation of output class

Returns:

  • (Hash)

    hash representation of all data



53
54
55
56
57
58
59
60
61
62
# File 'app/controllers/anoubis/output/menu.rb', line 53

def to_h
  result = super.to_h
  return result if self.result != 0
  result[:menu] = []
  self.items.each { |item|
    result[:menu].push(item.to_h) if item
  }
  result[:user] = self.user
  result
end