Class: CamaleonCms::Admin::Appearances::NavMenusController
- Inherits:
-
CamaleonCms::AdminController
- Object
- CamaleonCms::AdminController
- CamaleonCms::Admin::Appearances::NavMenusController
- Defined in:
- app/controllers/camaleon_cms/admin/appearances/nav_menus_controller.rb
Overview
Camaleon CMS is a content management system
Copyright (C) 2015 by Owen Peredo Diaz
Email: [email protected]
This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU Affero General Public License (GPLv3) for more details.
Instance Method Summary collapse
-
#add_items ⇒ Object
add items to specific nav-menu.
- #create ⇒ Object
- #custom_settings ⇒ Object
- #delete_menu_item ⇒ Object
- #destroy ⇒ Object
- #edit ⇒ Object
-
#edit_menu_item ⇒ Object
render edit external menu item.
- #index ⇒ Object
- #new ⇒ Object
-
#reorder_items(items = nil, parent_id = nil, is_root = true) ⇒ Object
update the reorder of items.
- #save_custom_settings ⇒ Object
- #update ⇒ Object
-
#update_menu_item ⇒ Object
update an external menu item.
Instance Method Details
#add_items ⇒ Object
add items to specific nav-menu
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
# File 'app/controllers/camaleon_cms/admin/appearances/nav_menus_controller.rb', line 101 def add_items items = [] @nav_menu = current_site..find(params[:nav_menu_id]) if params[:external].present? item = @nav_menu.({label: params[:external][:external_label], link: params[:external][:external_url], type: "external"}) item.(params[:external][:options]) if params[:external][:options].present? items << item end if params[:custom_items].present? # custom menu items params[:custom_items].each do |index, item| item = @nav_menu.({label: item['label'], link: item['url'], type: 'external'}) items << item end end if params[:items].present? params[:items].each do |index, item| item = @nav_menu.({label: 'auto', link: item['id'], type: item['kind']}) items << item end end render partial: 'menu_items', locals: {items: items, nav_menu: @nav_menu} end |
#create ⇒ Object
31 32 33 34 35 36 |
# File 'app/controllers/camaleon_cms/admin/appearances/nav_menus_controller.rb', line 31 def create = current_site..new(params[:nav_menu]) .save flash[:notice] = t('.created_menu', default: 'Created Menu') redirect_to action: :index, id: .id end |
#custom_settings ⇒ Object
56 57 58 59 60 |
# File 'app/controllers/camaleon_cms/admin/appearances/nav_menus_controller.rb', line 56 def custom_settings @nav_menu = current_site..find(params[:nav_menu_id]) @nav_menu_item = current_site..find(params[:id]) render "_custom_fields", layout: "camaleon_cms/admin/_ajax" end |
#delete_menu_item ⇒ Object
82 83 84 85 86 |
# File 'app/controllers/camaleon_cms/admin/appearances/nav_menus_controller.rb', line 82 def # @nav_menu = current_site.nav_menus.find(params[:nav_menu_id]) current_site..find(params[:id]).destroy render nothing: true end |
#destroy ⇒ Object
50 51 52 53 54 |
# File 'app/controllers/camaleon_cms/admin/appearances/nav_menus_controller.rb', line 50 def destroy current_site..find(params[:id]).destroy flash[:notice] = t('.deleted_menu', default: 'Menu destroyed') redirect_to action: :index end |
#edit ⇒ Object
45 46 47 48 |
# File 'app/controllers/camaleon_cms/admin/appearances/nav_menus_controller.rb', line 45 def edit @nav_menu = current_site..find(params[:id]) render partial: 'form' end |
#edit_menu_item ⇒ Object
render edit external menu item
69 70 71 |
# File 'app/controllers/camaleon_cms/admin/appearances/nav_menus_controller.rb', line 69 def render "_external_menu", layout: false, locals: {nav_menu: current_site..find(params[:nav_menu_id]), menu_item: current_site..find(params[:id])} end |
#index ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'app/controllers/camaleon_cms/admin/appearances/nav_menus_controller.rb', line 13 def index if params[:id].present? @nav_menu = current_site..find_by_id(params[:id]) elsif params[:slug].present? @nav_menu = current_site..find_by_slug(params[:slug]) else @nav_menu = current_site..first end @post_types = current_site.post_types add_asset_library("nav_menu") render "index" end |
#new ⇒ Object
26 27 28 29 |
# File 'app/controllers/camaleon_cms/admin/appearances/nav_menus_controller.rb', line 26 def new @nav_menu = current_site..new render partial: 'form' end |
#reorder_items(items = nil, parent_id = nil, is_root = true) ⇒ Object
update the reorder of items
89 90 91 92 93 94 95 96 97 98 |
# File 'app/controllers/camaleon_cms/admin/appearances/nav_menus_controller.rb', line 89 def reorder_items(items = nil, parent_id = nil, is_root = true) items = params[:items] if items.nil? parent_id = params[:nav_menu_id] if parent_id.nil? items.each do |index, _item| item = current_site..find(_item['id']) item.update_columns parent_id: parent_id, term_order: index reorder_items(_item['children'], _item['id'], false) if _item['children'].present? end render(inline: '') if is_root end |
#save_custom_settings ⇒ Object
62 63 64 65 66 |
# File 'app/controllers/camaleon_cms/admin/appearances/nav_menus_controller.rb', line 62 def save_custom_settings @nav_menu_item = current_site..find(params[:id]) @nav_menu_item.set_field_values(params[:field_options]) render nothing: true end |
#update ⇒ Object
38 39 40 41 42 43 |
# File 'app/controllers/camaleon_cms/admin/appearances/nav_menus_controller.rb', line 38 def update = current_site..find(params[:id]) .update(params[:nav_menu]) flash[:notice] = t('.updated_menu', default: 'Menu updated') redirect_to action: :index, id: .id end |
#update_menu_item ⇒ Object
update an external menu item
74 75 76 77 78 79 80 |
# File 'app/controllers/camaleon_cms/admin/appearances/nav_menus_controller.rb', line 74 def @nav_menu = current_site..find(params[:nav_menu_id]) item = current_site..find(params[:id]) item.({label: params[:external_label], link: params[:external_url]}) item.(params[:options]) if params[:options].present? render partial: 'menu_items', locals: {items: [item], nav_menu: @nav_menu} end |