Class: UU::OS::GVC::MenuModel::MenuItem

Inherits:
Object
  • Object
show all
Defined in:
uu_os_gvc-0.28.16/lib/uu/os/gvc/menu_model.rb

Overview

Represenatation of a single menu item.

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (MenuItem) initialize(data = nil)

Creates a new instance of MenuItem. Menu item with all fields set to nil is considered a separator.

Examples:

# init empty menu item (separator)
mi = UU::OS::GVC::MenuModel::MenuItem.new()
# init MenuItem as copy of another item
menu_item = ... # get existing MenuItem
mi_copy = UU::OS::GVC::MenuModel::MenuItem.new(menu_item)
# init MenuModel from Hash
hash_data = { :text => "Menu item 1", :actionUri => "ues:TER:ART:" }
mi = UU::OS::GVC::MenuModel::MenuItem.new(hash_data)
# init MenuModel from String containing data in JSON Format
str_data = '{"text":"Menu item 1", "actionUri": "ues:TER:ART:"}'
mi = UU::OS::GVC::MenuModel::MenuItem.new(str_data)

Parameters:

Raises:

  • (ArgumentError)

    If data is not one of JSON String, Hash or MenuItem.



313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
# File 'uu_os_gvc-0.28.16/lib/uu/os/gvc/menu_model.rb', line 313

def initialize(data=nil)
  @attributes = {}
  if data.kind_of? String
    js = JSON.parse(data, :symbolize_names => true)
    if (!js.kind_of? Hash)
      raise ArgumentError.new("JSON String has bad format. The root element must be Hash but was #{js.class}.")
    end
    init_hash(js)
  elsif data.kind_of? Hash
    init_hash(deep_copy(data))
  elsif data.kind_of? MenuItem
    init_hash(data.send(:to_h))
  elsif !data.nil?
    raise ArgumentError.new("MenuItem data must be JSON String, Hash or MenuItem, but was #{data.class}.")
  end
end

Instance Attribute Details

- (Object) action_uri

URI to use for the menu item navigation (UESURI, URL). Can be also UESURI with VUC event, such as "ues:$this-art?:myevent".



281
282
283
# File 'uu_os_gvc-0.28.16/lib/uu/os/gvc/menu_model.rb', line 281

def action_uri
  @action_uri
end

- (Object) disabled

Whether the item is disabled.



284
285
286
# File 'uu_os_gvc-0.28.16/lib/uu/os/gvc/menu_model.rb', line 284

def disabled
  @disabled
end

- (Object) target

Defines target window where the action URI will be opened - one of "CURRENT_WINDOW" (default), "NEW_WINDOW", "DIALOG_WINDOW". For backward compatibility it's also possible to use older equivalents "SELF", "NEW" and "MODAL".



277
278
279
# File 'uu_os_gvc-0.28.16/lib/uu/os/gvc/menu_model.rb', line 277

def target
  @target
end

- (Object) text

Item text.



272
273
274
# File 'uu_os_gvc-0.28.16/lib/uu/os/gvc/menu_model.rb', line 272

def text
  @text
end

Instance Method Details

- (String) to_json(options = {})

Returns data representation as JSON String.

Examples:

# get JSON String
data_str = mi.to_json

# output:
# {"text":"Menu item 1", "actionUri": "ues:TER:ART:"}

Returns:

  • (String)

    Data as JSON String.



340
341
342
# File 'uu_os_gvc-0.28.16/lib/uu/os/gvc/menu_model.rb', line 340

def to_json(options = {})
  @attributes.to_json(options)
end

- (String) to_s

Returns data representation as String.

Examples:

# get String
data_str = mi.to_s

# output:
# {"text":"Menu item 1", "actionUri": "ues:TER:ART:"}

Returns:

  • (String)

    Data as String.



354
355
356
# File 'uu_os_gvc-0.28.16/lib/uu/os/gvc/menu_model.rb', line 354

def to_s
  to_json
end