Class: DcMenu

Inherits:
Object
  • Object
show all
Includes:
Mongoid::Document, Mongoid::Timestamps
Defined in:
app/models/dc_menu.rb

Overview

Schema information

Collection name: dc_menu : Menus

_id                  BSON::ObjectId       _id
created_at           Time                 created_at
updated_at           Time                 updated_at
name                 String               Menu name
description          String               Short description of menu
div_name             String               Div id name around menu area
link_prepend         String               Link field usually holds direct link to document. Prepand field holds data, that has to be prepanded to the link.
css                  String               CSS for this menu
active               Mongoid::Boolean     Active
created_by           BSON::ObjectId       created_by
updated_by           BSON::ObjectId       updated_by
dc_menu_items        Embedded:DcMenuItem  Menu items

Default menu system for DRG CMS. Model recursively embeds DcMenuItem documents which (theoretically) results in infinite level of sub menus. In practice reasonable maximum level of 4 is advised.

Class Method Summary collapse

Class Method Details

.choices4_menu(site) ⇒ Object

Will return all top level menu items of specified menu. Used in DcPage document for selecting top level selected menu, when document displayed in browser.

Called from DcApplicationHelper :dc_choices4_menu: method.

Parameters:

Site

DcSite document. Site for which menu belongs to. If site is not specified

all current menus in dc_menus collection will be returned.

Returns: Array. Of choices prepared for select input field.



80
81
82
83
84
85
86
87
88
89
90
# File 'app/models/dc_menu.rb', line 80

def self.choices4_menu(site)
  rez = []
  menus = (site.menu_name.blank? ? all : where(name: site.menu_name)).to_a
  menus.each do |menu|
    rez << [menu.name, nil]
    menu.dc_menu_items.where(active: true).order_by(order: 1).each do |menu_item|
      rez << ['-- ' + menu_item.caption, menu_item._id]
    end
  end
  rez
end