Module: CamaleonCms::Admin::MenusHelper

Includes:
BreadcrumbHelper
Included in:
ApplicationHelper
Defined in:
app/helpers/camaleon_cms/admin/menus_helper.rb

Instance Method Summary collapse

Instance Method Details

#admin_menu_add_menu(key, menu) ⇒ Object

add menu item to admin menu at the the end key: key for menu menu: is hash like this: “dashboard”, title: “My title”, url: my_path, items: [sub menus]

  • icon: font-awesome icon (it is already included “fa fa-”)

  • title: title for the menu

  • url: url for the menu

  • items: is an recursive array of the menus without a key

  • datas: html data text for this menu item


67
68
69
# File 'app/helpers/camaleon_cms/admin/menus_helper.rb', line 67

def admin_menu_add_menu(key, menu)
  @_admin_menus[key] = menu
end

#admin_menu_append_menu_item(key, menu) ⇒ Object

append sub menu to menu with key = key menu: is hash like this: “dashboard”, title: “My title”, url: my_path, items: [sub menus]


73
74
75
76
77
# File 'app/helpers/camaleon_cms/admin/menus_helper.rb', line 73

def admin_menu_append_menu_item(key, menu)
  return unless @_admin_menus[key].present?
  @_admin_menus[key][:items] = [] unless @_admin_menus[key].has_key?(:items)
  @_admin_menus[key][:items] << menu
end

#admin_menu_drawObject

draw admin menu as html


112
113
114
115
116
117
118
119
120
121
122
123
# File 'app/helpers/camaleon_cms/admin/menus_helper.rb', line 112

def admin_menu_draw
  res= []
  @_tmp_menu_parents = []
  menus = _get_url_current
  menus.each do |menu|
    res << "<li data-key='#{menu[:key]}' class='#{"treeview" if menu.has_key?(:items)} #{'active' if is_active_menu(menu[:key])}' #{menu[:datas]}>
      <a href='#{menu[:url]}'><i class='fa fa-#{menu[:icon]}'></i> <span class=''>#{menu[:title]}</span> #{'<i class="fa fa-angle-left pull-right"></i>' if menu.has_key?(:items) }</a>
      #{_admin_menu_draw(menu[:items]) if menu.has_key?(:items)}
    </li>"
  end
  res.join
end

#admin_menu_insert_menu_after(key_target, key_menu, menu) ⇒ Object

add menu after menu with key = key_target key_menu: key for menu menu: is hash like this: “dashboard”, title: “My title”, url: my_path, items: [sub menus]


102
103
104
105
106
107
108
109
# File 'app/helpers/camaleon_cms/admin/menus_helper.rb', line 102

def admin_menu_insert_menu_after(key_target, key_menu, menu)
  res = {}
  @_admin_menus.each do |key, val|
    res[key] = val
    res[key_menu] = menu if key == key_target
  end
  @_admin_menus = res
end

#admin_menu_insert_menu_before(key_target, key_menu, menu) ⇒ Object

add menu before menu with key = key_target key_menu: key for menu menu: is hash like this: “dashboard”, title: “My title”, url: my_path, items: [sub menus]


90
91
92
93
94
95
96
97
# File 'app/helpers/camaleon_cms/admin/menus_helper.rb', line 90

def admin_menu_insert_menu_before(key_target, key_menu, menu)
  res = {}
  @_admin_menus.each do |key, val|
    res[key_menu] = menu if key == key_target
    res[key] = val
  end
  @_admin_menus = res
end

#admin_menu_prepend_menu_item(key, menu) ⇒ Object

prepend sub menu to menu with key = key menu: is hash like this: “dashboard”, title: “My title”, url: my_path, items: [sub menus]


81
82
83
84
85
# File 'app/helpers/camaleon_cms/admin/menus_helper.rb', line 81

def admin_menu_prepend_menu_item(key, menu)
  return unless @_admin_menus[key].present?
  @_admin_menus[key][:items] = [] unless @_admin_menus[key].has_key?(:items)
  @_admin_menus[key][:items] = [menu] + @_admin_menus[key][:items]
end

#admin_menus_add_commonsObject


4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'app/helpers/camaleon_cms/admin/menus_helper.rb', line 4

def admin_menus_add_commons
  admin_menu_add_menu("dashboard", {icon: "dashboard", title: t('camaleon_cms.admin.sidebar.dashboard'), url: cama_admin_dashboard_path})
  items = []

  current_site.post_types.eager_load(:metas).visible_menu.all.each do |pt|
    pt = pt.decorate
    items_i = []
    items_i << {icon: "list", title: "#{t('camaleon_cms.admin.post_type.all')}", url: cama_admin_post_type_posts_path(pt.id)} if can? :posts, pt
    items_i << {icon: "plus", title: "#{t('camaleon_cms.admin.post_type.add_new', type_title: pt.the_title)}", url: new_cama_admin_post_type_post_path(pt.id)} if can? :create_post, pt
    if pt.manage_categories?
      items_i << {icon: "folder-open", title: t('camaleon_cms.admin.post_type.categories'), url: cama_admin_post_type_categories_path(pt.id)} if can? :categories, pt
    end
    if pt.manage_tags?
      items_i << {icon: "tags", title: t('camaleon_cms.admin.post_type.tags'), url: (pt.id)} if can? :post_tags, pt
    end
    items << {icon: pt.get_option('icon', "copy"), title: pt.the_title, url: "", items: items_i } if items_i.present? #if can? :posts, pt
  end
  admin_menu_add_menu("content", {icon: "database", title: t('camaleon_cms.admin.sidebar.contents'), url: "", items: items, datas: "data-intro='#{t("camaleon_cms.admin.intro.content")}' data-position='right' data-wait='600'"}) if items.present?
  #end

  admin_menu_add_menu("media", {icon: "picture-o", title: t('camaleon_cms.admin.sidebar.media'), url: cama_admin_media_path, datas: "data-intro='#{t("camaleon_cms.admin.intro.media")}' data-position='right'"}) if can? :manage, :media
  admin_menu_add_menu("comments", {icon: "comments", title: t('camaleon_cms.admin.sidebar.comments'), url: cama_admin_comments_path, datas: "data-intro='#{t("camaleon_cms.admin.intro.comments")}' data-position='right'"}) if can? :manage, :comments

  items = []
  items << {icon: "desktop", title: t('camaleon_cms.admin.sidebar.themes'), url: cama_admin_appearances_themes_path, datas: "data-intro='#{t("camaleon_cms.admin.intro.themes")}' data-position='right'"} if can? :manage, :themes
  items << {icon: "archive", title: t('camaleon_cms.admin.sidebar.widgets'), url: cama_admin_appearances_widgets_main_index_path, datas: "data-intro='#{t("camaleon_cms.admin.intro.widgets")}' data-position='right'"} if can? :manage, :widgets
  items << {icon: "list", title: t('camaleon_cms.admin.sidebar.menus'), url: cama_admin_appearances_nav_menus_path, datas: "data-intro='#{t("camaleon_cms.admin.intro.menus", image: view_context.asset_path("camaleon_cms/admin/intro/menus.png"))}' data-position='right'"} if can? :manage, :nav_menu
  items << {icon: "code", title: t('camaleon_cms.admin.sidebar.shortcodes', default: "Shortcodes"), url: cama_admin_settings_shortcodes_path, datas: "data-intro='#{t("camaleon_cms.admin.intro.shortcodes")}' data-position='right'"} if can? :manage, :shortcodes
  admin_menu_add_menu("appearance", {icon: "paint-brush", title: t('camaleon_cms.admin.sidebar.appearance'), url: "", items: items, datas: "data-intro='#{t("camaleon_cms.admin.intro.appearance")}' data-position='right' data-wait='500'"}) if items.present?


  admin_menu_add_menu("plugins", {icon: "plug", title: "#{t('camaleon_cms.admin.sidebar.plugins')} <small class='label label-primary'>#{PluginRoutes.all_plugins.clone.delete_if{|plugin| plugin[:domain].present? && !plugin[:domain].split(",").include?(current_site.the_slug) }.size}</small>", url: cama_admin_plugins_path, datas: "data-intro='#{t("camaleon_cms.admin.intro.plugins")}' data-position='right'"}) if can? :manage, :plugins

  if can? :manage, :users
    items = []
    items << {icon: "list", title: t('camaleon_cms.admin.users.all_users'), url: cama_admin_users_path}
    items << {icon: "plus", title: t('camaleon_cms.admin.users.add_user'), url: new_cama_admin_user_path}
    items << {icon: "group", title: t('camaleon_cms.admin.users.user_roles'), url: cama_admin_user_roles_path}
    admin_menu_add_menu("users", {icon: "users", title: t('camaleon_cms.admin.sidebar.users'), url: "", items: items, datas: "data-intro='#{t("camaleon_cms.admin.intro.users")}' data-position='right' data-wait='500'"})
  end

  items = []
  if can? :manage, :settings
    items << {icon: "desktop", title: t('camaleon_cms.admin.sidebar.general_site'), url: cama_admin_settings_site_path, datas: "data-intro='#{t("camaleon_cms.admin.intro.gral_site")}' data-position='right'"}
    items << {icon: "cog", title: t('camaleon_cms.admin.sidebar.sites'), url: cama_admin_settings_sites_path, datas: "data-intro='#{t("camaleon_cms.admin.intro.sites")}' data-position='right'"} if current_site.manage_sites?
    items << {icon: "files-o", title: t('camaleon_cms.admin.sidebar.content_groups'), url: cama_admin_settings_post_types_path, datas: "data-intro='#{t("camaleon_cms.admin.intro.post_type")}' data-position='right'"}
    items << {icon: "cog", title: t('camaleon_cms.admin.sidebar.custom_fields'), url: cama_admin_settings_custom_fields_path, datas: "data-intro='#{t("camaleon_cms.admin.intro.custom_fields")}' data-position='right'"}
    items << {icon: "language", title: t('camaleon_cms.admin.sidebar.languages'), url: cama_admin_settings_languages_path, datas: "data-intro='#{t("camaleon_cms.admin.intro.languages")}' data-position='right'"}
  end

  items << {icon: "windows", title: t('camaleon_cms.admin.settings.theme_setting', default: 'Theme Settings'), url: cama_admin_settings_theme_path} if can? :manage, :theme_settings
  admin_menu_add_menu("settings", {icon: "cogs", title: t('camaleon_cms.admin.sidebar.settings'), url: "", items: items, datas: "data-intro='#{t("camaleon_cms.admin.intro.settings")}' data-position='right' data-wait='500'"}) if items.present?

end